-
Notifications
You must be signed in to change notification settings - Fork 1
/
location.h
59 lines (48 loc) · 1.53 KB
/
location.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* File: location.h
* ----------------
* This file just contains features relative to the location structure
* used to record the lexical position of a token or symbol. This file
* establishes the cmoon definition for the yyltype structure, the global
* variable yylloc, and a utility function to join locations you might
* find handy at times.
*/
#ifndef YYLTYPE
/* Typedef: yyltype
* ----------------
* Defines the struct type that is used by the scanner to store
* position information about each lexeme scanned.
*/
typedef struct yyltype
{
int timestamp; // you can ignore this field
int first_line, first_column;
int last_line, last_column;
char *text; // you can also ignore this field
} yyltype;
#define YYLTYPE yyltype
/* Global variable: yylloc
* ------------------------
* The global variable holding the position information about the
* lexeme just scanned.
*/
extern struct yyltype yylloc;
/* Function: Join
* --------------
* Takes two locations and returns a new location which represents
* the span from first to last, inclusive.
*/
inline yyltype Join(yyltype first, yyltype last)
{
yyltype combined;
combined.first_column = first.first_column;
combined.first_line = first.first_line;
combined.last_column = last.last_column;
combined.last_line = last.last_line;
return combined;
}
/* Same as above, except operates on pointers as a convenience */
inline yyltype Join(yyltype *firstPtr, yyltype *lastPtr)
{
return Join(*firstPtr, *lastPtr);
}
#endif