-
Notifications
You must be signed in to change notification settings - Fork 7
/
PGLexer.cpp
254 lines (235 loc) · 19 KB
/
PGLexer.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#ifdef LRSTAR
/////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// PGLexer.
/* Generated by: DFASTAR 6.5.019
Grammar: PG.lgr
Skeleton: PGLexer.cpp.skl
Output: PGLexer.cpp
*/
#include "ComGlobal.h"
#include "PGLexer.h"
Token PGLexer::token; // Token.
int PGLexer::tab; // Tab setting for the input file.
int PGLexer::line_numb; // Line number of token.
int PGLexer::col_numb; // Column number of token.
int PGLexer::line_pos;
char* PGLexer::line_start; // Line start pointer.
int PGLexer::line_start_numb; // Line number associated with line_start.
/////////////////////////////////////////////////////////////////////////////////////////////////////
// //
void PGLexer::init_lexer (char* input_start)
{
tab = optn[PG_TAB];
line_pos = 0;
line_numb = 1;
token.end = input_start;
line_start = input_start;
line_ptr[1] = input_start;
line_start_numb = 1;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// Terminal Transition Matrix and Vectors.
// Terminal transition matrix.
uchar PGLexer::Tm [1951] =
{
89, 7, 7, 70, 7, 89, 4, 2, 59, 60, 24, 25, 61, 26, 27, 28, 6, 62, 63, 1,
29, 30, 64, 5, 65, 89, 66, 67, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 68, 69,
31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
81, 0, 0, 0, 8, 0, 0, 0, 0, 8, 8, 32, 8, 33, 8, 8, 8, 8, 0, 0,
0, 0, 0, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 11, 0, 0, 0, 0, 11, 11, 11, 11, 11, 11, 11, 11, 11, 0, 0, 0, 0,
4, 4, 74, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 12, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0,
5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 7, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0,
71, 0, 15, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0,
0, 0, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 10,
0, 10, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 10, 10,
72, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 16, 0, 0,
0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 73, 0, 0, 0, 0, 0, 0,
4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 4, 0, 4,
0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 13, 13, 0, 0, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 18, 18, 18, 0,
18, 18, 18, 18, 18, 18, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19,
0, 19, 19, 19, 19, 19, 19, 17, 19, 19, 19, 19, 88, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 18, 18,
18, 0, 18, 18, 18, 18, 18, 18, 20, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 21,
21, 21, 0, 21, 21, 21, 21, 21, 21, 48, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
22, 22, 22, 0, 22, 22, 22, 22, 22, 22, 20, 22, 22, 22, 22, 88, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 21, 21, 21, 0, 21, 21, 21, 21, 21, 21, 51, 21, 21, 21, 21, 21, 21, 21, 21,
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
21, 21, 23, 23, 23, 0, 23, 23, 23, 23, 23, 23, 52, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 0, 23, 23, 23, 23, 23, 23, 54, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 35, 0, 13, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0,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0, 0, 0, 15, 15, 15, 15, 15,
15, 44, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 0, 71, 0, 15, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15,
45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0,
0, 0, 56, 0, 15, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 71,
0, 15, 0, 0, 0, 0, 15, 15, 15, 15, 15, 46, 15, 15, 15, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 71, 0, 15, 0,
0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 47, 15, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 71, 0, 15, 0, 0, 0, 0,
15, 15, 15, 15, 15, 15, 49, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 71, 0, 15, 0, 0, 0, 0, 15, 15, 15,
15, 15, 50, 15, 15, 15, 0, 0, 0, 0, 19, 19, 19, 0, 19, 19, 19, 19, 19, 19,
48, 19, 19, 19, 19, 88, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 57, 0, 15, 0, 0, 0, 0, 15,
15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 15, 0, 0, 0, 0, 71, 0, 15, 0, 0, 0, 0, 15, 15, 15, 15,
15, 15, 53, 15, 15, 0, 0, 0, 0, 19, 19, 19, 0, 19, 19, 19, 19, 19, 19, 51,
19, 19, 19, 19, 88, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 22, 22, 22, 0, 22, 22, 22, 22, 22, 22,
52, 22, 22, 22, 22, 88, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 71, 0, 15, 0, 0, 0, 0, 15,
55, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 22, 22, 22, 0, 22, 22, 22, 22,
22, 22, 54, 22, 22, 22, 22, 88, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 58, 0, 15, 0, 0, 0,
0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
// T_matrix row.
ushort PGLexer::Tr [90] =
{
0, 41, 78, 119, 156, 197, 234, 274, 299, 336, 373, 414, 454, 495, 536, 299, 414, 577, 618, 659,
700, 741, 782, 820, 861, 883, 905, 932, 963, 1004, 1026, 1053, 1078, 1115, 1152, 1172, 1194, 1216, 1238, 1265,
1290, 1327, 1364, 1401, 1438, 1475, 1512, 1549, 1590, 1631, 1668, 1709, 1750, 1791, 1832, 1873, 1910, 1910, 1910, 1910,
1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910,
1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1910
};
// T_matrix column.
uchar PGLexer::Tc [256] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 4, 5, 6, 5, 5, 5, 5, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 18,
19, 20, 21, 22, 5, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 25, 26, 27, 28, 5, 23, 23, 23,
29, 30, 31, 23, 23, 23, 23, 32, 23, 23, 23, 33, 23, 23, 34, 23, 23, 23, 23, 35,
23, 36, 23, 37, 38, 39, 40, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
};
// Token numbers for each state.
char PGLexer::terminal [90] =
{
0, 0, 0, 26, 0, 1, 6, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 35, 30, 0, 0, 36, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 9, 8, 37,
38, 41, 13, 19, 34, 39, 40, 25, 18, 27, 7, 2, 4, 3, 5, 22, 21, 14, 31, 16,
17, 28, 24, 23, 20, 29, 33, 15, -1, 0
};
/////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// get_token
int PGLexer::get_token ()
{
int state, next; // State, next state.
do
{
state = 0;
token.start = token.end; // Set start of Token.
token.column = col_numb + 1; // Set column number.
token.line = line_numb; // Set line number of Token.
while (next = Tm [Tr [state] + Tc [*token.end]])
{
if (*token.end == '\n')
{
col_numb = 0;
line_pos = 0;
line_start = token.end + 1; // Set beginning of next line.
line_ptr [++line_numb] = line_start;
line_start_numb++;
}
else if (*token.end == '\t') // If tab character.
{
col_numb += tab - (col_numb % tab);
}
else
{
col_numb++; // Increment column.
}
token.end++; // Increment Token pointer.
state = next; // Set next state number.
}
}
while (terminal[state] < 0);
line_pos++;
return terminal[state];
}
///////////////////////////////////////////////////////////////////////////////
// //
int PGLexer::get_lookahead (int& linenumber)
{
char* TS = token.start;
char* TE = token.end;
int TSTI = token.sti;
int TL = token.line;
int TC = token.column;
int LN = line_numb;
int LC = col_numb;
int LP = line_pos;
int la = get_token(); // Get lookahead token number.
linenumber = token.line; // Set line number of lookahead.
token.start = TS; // Reset token start.
token.end = TE; // Reset token end.
token.sti = TSTI;
token.line = TL; // Reset token column.
token.column = TC; // Reset token column.
line_numb = LN; // Reset line number.
col_numb = LC; // Reset line column.
line_pos = LP; // Reset line position.
return (la);
}
// //
/////////////////////////////////////////////////////////////////////////////////////////////////////
#endif