1 mike 1.1.2.1 %option never-interactive
2 %{
3
|
4 mike 1.1.2.2 extern int WQLInput(char* buffer, int& numRead, int numRequested);
|
5 mike 1.1.2.3 extern int WQL_error(char*);
|
6 mike 1.1.2.2
7 /* ATTN: works with Flex only */
8 #define YY_INPUT(BUF, NREAD, NREQUESTED) WQLInput(BUF, NREAD, NREQUESTED)
9
|
10 mike 1.1.2.1 #include <cstring>
|
11 mike 1.1.2.7 #include <cassert>
12 #include "WQLYACC.h"
|
13 mike 1.1.2.1
|
14 mike 1.1.2.7 #if 0
|
15 mike 1.1.2.6 # define WQL_TRACE(X) printf X
16 #else
17 # define WQL_TRACE(X)
18 #endif
|
19 mike 1.1.2.3
|
20 mike 1.1.2.1 %}
21
22 POSITIVE_DECIMAL_DIGIT [1-9]
23 DECIMAL_DIGIT [0-9]
24 BLANK [ \t\n]
25 IDENT_CHAR [A-Za-z_]
26
27 %%
28
29 [Ss][Ee][Ll][Ee][Cc][Tt] {
30
|
31 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_SELECT]\n", yytext));
|
32 mike 1.1.2.1 return TOK_SELECT;
33 }
34
|
35 mike 1.1.2.3 [Ff][Rr][Oo][Mm] {
36
|
37 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_FROM]\n", yytext));
|
38 mike 1.1.2.3 return TOK_FROM;
39 }
40
41 [Ww][Hh][Ee][Rr][Ee] {
42
|
43 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_WHERE]\n", yytext));
|
44 mike 1.1.2.3 return TOK_WHERE;
45 }
46
47 [Tt][Rr][Uu][Ee] {
48
|
49 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_TRUE]\n", yytext));
|
50 mike 1.1.2.3 return TOK_TRUE;
51 }
52
53 [Ff][Aa][Ll][Ss][Ee] {
54
|
55 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_FALSE]\n", yytext));
|
56 mike 1.1.2.3 return TOK_FALSE;
57 }
58
|
59 mike 1.1.2.4 [Nn][Ul][Ul] {
60
|
61 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_NULL]\n", yytext));
|
62 mike 1.1.2.4 return TOK_NULL;
63 }
64
|
65 mike 1.1.2.3 [Nn][Oo][Tt] {
66
|
67 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_NOT]\n", yytext));
|
68 mike 1.1.2.3 return TOK_NOT;
69 }
70
71 [Aa][Nn][Dd] {
72
|
73 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_AND]\n", yytext));
|
74 mike 1.1.2.3 return TOK_AND;
75 }
76
77 [Oo][Rr] {
78
|
79 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_OR]\n", yytext));
|
80 mike 1.1.2.3 return TOK_OR;
81 }
82
|
83 mike 1.1.2.4 [Ii][Ss] {
|
84 mike 1.1.2.3
|
85 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_IS]\n", yytext));
|
86 mike 1.1.2.4 return TOK_IS;
|
87 mike 1.1.2.3 }
|
88 mike 1.1.2.1
89 [-+]?{POSITIVE_DECIMAL_DIGIT}{DECIMAL_DIGIT}* {
90
|
91 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_INTEGER]\n", yytext));
|
92 mike 1.1.2.1 WQL_lval.intValue = strtol(yytext, (char**)0, 10);
93 return TOK_INTEGER;
94 }
95
96 [+-]?0 {
97
|
98 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_INTEGER]\n", yytext));
|
99 mike 1.1.2.1 WQL_lval.intValue = 0;
100 return TOK_INTEGER;
101 }
102
103 [-+]?{DECIMAL_DIGIT}*\.{DECIMAL_DIGIT}+([eE][+-]?{DECIMAL_DIGIT}+)? {
104
|
105 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_DOUBLE]\n", yytext));
|
106 mike 1.1.2.1 WQL_lval.doubleValue = strtod((char*)yytext, (char**)0);
107 return TOK_DOUBLE;
108 }
109
|
110 mike 1.1.2.3 \"[^\"\n]*\" {
|
111 mike 1.1.2.1
|
112 mike 1.1.2.3 /* ATTN: Can long string literals overflow the buffer? */
|
113 mike 1.1.2.7 /* ATTN: Handle expansion of special characters */
|
114 mike 1.1.2.1
|
115 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_STRING]\n", yytext));
|
116 mike 1.1.2.7
117 /* Copy the string (but remove the surrounding quotes */
118
119 {
120 size_t n = strlen(yytext) - 2;
121 char* strValue = new char[n + 1];
122 memcpy(strValue, yytext + 1, n);
123 strValue[n - 1] = '\0';
124 WQL_lval.strValue = strValue;
125 }
126
|
127 mike 1.1.2.3 return TOK_STRING;
128 }
|
129 mike 1.1.2.1
|
130 mike 1.1.2.3 \"[^\"\n]*$ {
131
132 WQL_error("Unterminated string");
133 }
134
135 [\*(),] {
136
137 WQL_TRACE(("LEX: %c\n", yytext[0]));
138 return yytext[0];
139 }
140
141 "=" {
|
142 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_EQ]\n", yytext));
|
143 mike 1.1.2.3 return TOK_EQ;
144 }
145
146 "!=" {
147
|
148 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_NE]\n", yytext));
|
149 mike 1.1.2.3 return TOK_NE;
150 }
151
152 "<=" {
153
|
154 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_LE]\n", yytext));
|
155 mike 1.1.2.3 return TOK_LE;
156 }
157
158 "<" {
159
|
160 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_LT]\n", yytext));
|
161 mike 1.1.2.3 return TOK_LT;
162 }
163
164 ">=" {
165
|
166 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_GE]\n", yytext));
|
167 mike 1.1.2.3 return TOK_GE;
168 }
169
170 ">" {
171
|
172 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_GT]\n", yytext));
|
173 mike 1.1.2.3 return TOK_GT;
|
174 mike 1.1.2.1 }
175
176 {IDENT_CHAR}({IDENT_CHAR}|{DECIMAL_DIGIT})* {
177
|
178 mike 1.1.2.5 WQL_TRACE(("LEX: %s [TOK_IDENTIFIER]\n", yytext));
|
179 mike 1.1.2.7
180 {
181 size_t n = strlen(yytext);
182 char* strValue = new char[n + 1];
183 memcpy(strValue, yytext, n);
184 strValue[n] = '\0';
185 WQL_lval.strValue = strValue;
186 }
187
|
188 mike 1.1.2.1 return TOK_IDENTIFIER;
189 }
190
191 {BLANK}+ {
192
|
193 mike 1.1.2.3 /* Ignore blanks */
|
194 mike 1.1.2.1 }
195
196 . {
|
197 mike 1.1.2.7 WQL_lval.intValue = 0;
|
198 mike 1.1.2.3 return TOK_UNEXPECTED_CHAR;
|
199 mike 1.1.2.1 }
200
201 %%
202
203 extern "C" int WQL_wrap()
204 {
205 return 1;
206 }
|