-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathLGLexer.cpp
203 lines (181 loc) · 11.6 KB
/
LGLexer.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
#ifdef DFASTAR
#include "ComGlobal.h"
#include "LGLexer.h"
Token LGLexer::token;
int LGLexer::line_numb;
int LGLexer::col_numb;
int LGLexer::line_pos;
char* LGLexer::line_start;
int LGLexer::max_char_set;
int LGLexer::tab;
/////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// Terminal Transition Matrix and Vectors.
// Terminal transition matrix.
static unsigned char Tm [848] =
{
54, 8, 8, 43, 8, 54, 5, 24, 4, 35, 36, 37, 38, 25, 26, 28, 7, 39, 3, 27,
54, 40, 6, 1, 6, 2, 41, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 9, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0,
10, 0, 0, 0, 0, 29, 11, 11, 11, 29, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 11, 11, 0, 0, 0, 0, 30, 12, 30, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 6,
0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 8, 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, 0, 15, 0, 15, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 16, 0, 0, 0, 46, 0, 16, 0, 16, 0, 0, 0, 0, 0, 11,
11, 11, 47, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
11, 11, 0, 0, 0, 0, 0, 12, 48, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 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, 18, 18,
18, 0, 18, 18, 18, 18, 18, 18, 18, 17, 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, 19, 17, 19, 19,
19, 53, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 18, 18, 18, 0, 18, 18,
18, 18, 18, 18, 18, 20, 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, 21, 31, 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,
22, 20, 22, 22, 22, 53, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 21, 21,
21, 0, 21, 21, 21, 21, 21, 21, 21, 32, 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, 23, 33, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 0, 23, 23, 23, 23, 23,
23, 23, 34, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 0,
0, 0, 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 13,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 19, 19, 0, 19, 19,
19, 19, 19, 19, 19, 31, 19, 19, 19, 53, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 0, 19, 19, 19, 19, 19, 19, 19, 32, 19, 19, 19, 53, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 22, 22, 22, 0, 22, 22, 22, 22, 22, 22, 22, 33, 22,
22, 22, 53, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 0, 22, 22, 22, 22,
22, 22, 22, 34, 22, 22, 22, 53, 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, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
// T_matrix row.
static unsigned short Tr [55] =
{
0, 28, 51, 76, 101, 129, 157, 182, 209, 221, 249, 274, 302, 330, 358, 221, 249, 386, 414, 442,
470, 498, 526, 551, 579, 587, 608, 623, 644, 664, 686, 714, 739, 767, 792, 820, 820, 820, 820, 820,
820, 820, 820, 820, 820, 820, 820, 820, 820, 820, 820, 820, 820, 820, 820
};
// T_matrix column.
static unsigned char 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, 7, 5, 8,
9, 10, 11, 12, 5, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 5, 17,
18, 19, 20, 21, 5, 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, 22, 5, 23, 5, 5, 24, 5, 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, 22, 25, 26, 27, 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, 0
};
// token numbers for each state.
static char terminal [55] =
{
0, 0, 19, 0, 0, 0, 1, 7, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12, 14, 13, 21,
15, 17, 20, 8, 4, 3, 2, 5, 6, 22, 9, 16, 10, -1, 0
};
/*--- Defined Constants. ----------------------------------------------------*/
///////////////////////////////////////////////////////////////////////////////
// //
// init //
void LGLexer::init_lexer () // General purpose lexer.
{
int i;
line_numb = 1;
col_numb = 0;
line_pos = 0;
line_start = input_start;
token.end = line_start;
line_ptr[line_numb] = input_start;
tab = optn[LG_TAB];
if (max_char_set == 128)
{
for (i = 128; i < 256; i++)
{
Tc[i] = Tc[0]; // Make higher characters an error.
}
}
}
///////////////////////////////////////////////////////////////////////////////
// //
// term //
void LGLexer::term_lexer () // General purpose lexer.
{
/* Nothing */
}
/*--- DFA Lexer Engine. -----------------------------------------------------*/
int LGLexer::get_token () // DFA LGLexer Engine.
{
int state, next; // State, next state, terminal, keyword.
do
{
state = 0; // Start in state zero.
token.start = token.end; // Set start of token.
token.line = line_numb; // Set line number of token.
token.column = col_numb + 1; // Set column number.
while (next = Tm [Tr [state] + Tc [*token.end]])
{
if (*token.end == '\n') // If end-of-line character.
{
col_numb = 0;
line_pos = 0;
line_start = token.end + 1; // Set beginning of next line.
line_ptr [++line_numb] = line_start;
}
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] == -1); // If whitespace, continue.
line_pos++;
return terminal[state]; // Return terminal number.
}
///////////////////////////////////////////////////////////////////////////////
// //
int LGLexer::get_lookahead()
{
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 look ahead token.
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
// //
///////////////////////////////////////////////////////////////////////////////