Datei: NDODLL/NDOql/NDOql.ATG
Last Commit (28c8c45)
1 | using System.Collections.Generic; |
2 | using System.Text; |
3 | using System.Globalization; |
4 | using NDOql.Expressions; |
5 | |
6 | COMPILER NDOQL |
7 | |
8 | |
9 | OqlExpression rootExpression; |
10 | public OqlExpression RootExpression |
11 | { |
12 | ····get { return rootExpression; } |
13 | } |
14 | |
15 | |
16 | |
17 | /*------------------------------------------------------------------------* |
18 | *----- SCANNER DESCRIPTION ----------------------------------------------* |
19 | *------------------------------------------------------------------------*/ |
20 | |
21 | IGNORECASE |
22 | |
23 | CHARACTERS |
24 | |
25 | ····tab················= '\u0009'. /*··9 = tabulator */ |
26 | ····eol················= '\u000a'. /* 10 = line feed */ |
27 | ····cr················ = '\u000d'. /* 13 = carriage return */ |
28 | ····newLine············= cr + eol. /* Line separator character (U+2028) + Paragraph separator character (U+2029) */ |
29 | |
30 | ····/* see https://msdn.microsoft.com/de-de/library/aa664670(v=vs.71).aspx |
31 | ······ and implementation in http://www.ssw.uni-linz.ac.at/Coco/CS/CSharp3.atg */ |
32 | |
33 | ····startletter········= 'A' .. 'Z' + 'a' .. 'z' + '_' + '\u00aa' + '\u00b5' + '\u00ba' + '\u00c0' .. '\u00d6' + '\u00d8' .. '\u00f6' + '\u00f8' .. '\u00ff'. |
34 | ····partletter········ = '.' + '0' .. '9' + 'A' .. 'Z' + 'a' .. 'z' + '_' + '\u0080' + '\u00a0' .. '\u00b3' + '\u00b5' + '\u00ba' + '\u00c0' .. '\u00d6' + '\u00d8' .. '\u00f6' + '\u00f8' .. '\u00ff'. |
35 | |
36 | ····digit··············= "0123456789". |
37 | ····hexDigit·········· = digit + "ABCDEFabcdef". |
38 | ····notDigit·········· = ANY - digit. |
39 | |
40 | ····regularStringChar··= ANY - "'" - newLine. |
41 | ····notNewLine········ = ANY - newLine . |
42 | ····ws················ = " " + tab + '\u000b' + '\u000c'. /* Any character with Unicode class Zs */ |
43 | |
44 | |
45 | TOKENS |
46 | |
47 | ··/* This definition is not exact, as it allows '_.x' or 'x..y' as valid identifiers. But we couldn't get a mapping to that kind of wrong identifiers anyway. */ |
48 | ····ident = startletter { partletter }.···· |
49 | |
50 | ··/*--------------------------------------------------------------------------------*/ |
51 | ····realCon = |
52 | ····['-'] [digit {digit}] "." digit {digit} |
53 | ············[("e" | "E" ) ["+" | "-"] digit {digit} ] ···················· |
54 | ········. |
55 | |
56 | ··/*--------------------------------------------------------------------------------*/ |
57 | ····intCon = |
58 | ········['-'] (digit {digit} | digit {digit} ) |
59 | ········. |
60 | |
61 | ··/*--------------------------------------------------------------------------------*/ |
62 | ····stringCon = "'"····{ regularStringChar } "'". |
63 | |
64 | |
65 | ····/*----- keyword names needed in LL(1) resolvers -----*/ |
66 | ····AND······= "AND". |
67 | ····OR······ = "OR". |
68 | ····NOT······= "NOT". |
69 | ····LIKE···· = "LIKE". |
70 | ····ESCAPE·· = "ESCAPE". |
71 | ····BETWEEN··= "BETWEEN". |
72 | ····IS······ = "IS". |
73 | ····NULL···· = "NULL". |
74 | ····TRUE······= "TRUE". |
75 | ····MOD···· = "MOD". |
76 | ····IN···· = "IN". |
77 | |
78 | |
79 | ····parameter =··"{" digit "}". |
80 | |
81 | |
82 | |
83 | COMMENTS FROM "--" TO eol |
84 | |
85 | IGNORE eol + cr + tab |
86 | |
87 | PRODUCTIONS |
88 | |
89 | /*------------------------------------------------------------------------* |
90 | *--------------------------- Declarations -------------------------------* |
91 | *------------------------------------------------------------------------*/ |
92 | |
93 | NDOQL = RootExpr<out this.rootExpression> . |
94 | |
95 | /*------------------------------------------------------------------------*/ |
96 | |
97 | RootExpr<out OqlExpression expression> |
98 | ····(.··OqlExpression child; |
99 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
100 | ········bool negated = false; |
101 | ····.) |
102 | = ····[NOT (.negated = true; .)] OrExpr<out child> |
103 | (. |
104 | ····if (negated) result.UnaryOp = "NOT"; |
105 | ····result.Add(child); |
106 | ····expression = result.Simplify(); |
107 | .) |
108 | . |
109 | |
110 | /*------------------------------------------------------------------------*/ |
111 | OrExpr <out OqlExpression expression>·· |
112 | ····(. |
113 | ········OqlExpression child; |
114 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
115 | ····.) |
116 | |
117 | = AndExpr ············<out child> (. result.Add(child); .) |
118 | ··{ "OR" (. bool negated = false; .) [NOT (. negated = true; .)] |
119 | ··AndExpr<out child> (. if (negated) child.UnaryOp = "NOT"; result.Add(child, "OR"); .) |
120 | ··} |
121 | |
122 | (. expression = result.Simplify(); .) |
123 | . |
124 | |
125 | |
126 | /*------------------------------------------------------------------------*/ |
127 | AndExpr<out OqlExpression expression>·· |
128 | ····(. |
129 | ········OqlExpression child; |
130 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
131 | ····.) |
132 | = EqlExpr<out child> (. result.Add(child); .) { |
133 | ················································"AND" (. bool negated = false; .) [NOT (. negated = true; .)] |
134 | ················································EqlExpr<out child> (. if (negated) child.UnaryOp = "NOT"; result.Add(child, "AND"); .) |
135 | ··············································} |
136 | (. expression = result.Simplify(); .) |
137 | . |
138 | |
139 | |
140 | /*------------------------------------------------------------------------*/ |
141 | EqlExpr<out OqlExpression expression> |
142 | ····(. |
143 | ········OqlExpression child; |
144 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
145 | ········string newOp = null; |
146 | ········bool negated = false; |
147 | ····.) |
148 | ···· |
149 | = ( |
150 | ····IF(!(scanner.Peek().kind==_IN)) |
151 | ····RelExpr<out child> (. result.Add(child); .) |
152 | ····{ |
153 | ········( |
154 | ············"!=" (. newOp = "<>"; .) |
155 | ············| "<>" (. newOp = "<>"; .) |
156 | ············| "=" (. newOp = "="; .) [NOT (. negated = true; .)] |
157 | ············| "LIKE" (. newOp = "LIKE"; .) /*[ESCAPE stringCon]*/ |
158 | ········) |
159 | ········RelExpr<out child> (. if (negated) child.UnaryOp = "NOT"; result.Add(child, newOp); .) |
160 | ····} |
161 | ····| |
162 | ····Identifier <out child> (. result.Add(child); .) |
163 | ········IN "(" |
164 | ········( |
165 | ············NumList <out child> (. child.HasBrackets = true; result.Add(child, "IN"); .) |
166 | ············| StringList <out child> (. child.HasBrackets = true; result.Add(child, "IN"); .) |
167 | ········) |
168 | ········")" |
169 | ·· ) |
170 | (. expression = result.Simplify(); .) |
171 | . |
172 | |
173 | /*------------------------------------------------------------------------*/ |
174 | RelExpr <out OqlExpression expression> |
175 | ····(. |
176 | ········OqlExpression child; |
177 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
178 | ········string newOp = null; |
179 | ········bool negated = false; |
180 | ····.) |
181 | = BitOrExpr<out child> (. result.Add(child); .) |
182 | ··[ |
183 | ····( |
184 | ········"<" (. newOp = "<"; .) |
185 | ········| ">" (. newOp = ">"; .) |
186 | ········| "<=" (. newOp = "<="; .) |
187 | ········| ">=" (. newOp = ">="; .) |
188 | ········| "!<" (. newOp = ">="; .) |
189 | ········| "!>" (. newOp = "<="; .) |
190 | ····) BitOrExpr <out child> (. result.Add(child, newOp); .) |
191 | ····| IS [NOT (. negated = true; .)] NULL (. result.Add(new NamedConstantExpression("NULL", negated, t.line, t.col), "IS"); .) |
192 | ····| [NOT (. negated = true; .)] BETWEEN BitOrExpr <out child> (. result.Add(child, "BETWEEN"); .) |
193 | ································AND BitOrExpr <out child> (. result.Add(child, "BETWEEN"); .) |
194 | ··] |
195 | (. expression = result.Simplify(); .) |
196 | . |
197 | |
198 | /*------------------------------------------------------------------------*/ |
199 | BitOrExpr<out OqlExpression expression> |
200 | ····(. |
201 | ········OqlExpression child; |
202 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
203 | ····.) |
204 | = BitXorExpr <out child> (. result.Add(child); .) |
205 | ··{"|" BitXorExpr <out child> (. result.Add(child, "|"); .) } |
206 | (. expression = result.Simplify(); .) |
207 | . |
208 | |
209 | |
210 | /*------------------------------------------------------------------------*/ |
211 | BitXorExpr<out OqlExpression expression> |
212 | ····(. |
213 | ········OqlExpression child; |
214 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
215 | ····.) |
216 | = BitAndExpr <out child> (. result.Add(child); .) |
217 | ··{"^" BitAndExpr <out child> (. result.Add(child, "^"); .) } |
218 | (. expression = result.Simplify(); .) |
219 | . |
220 | |
221 | |
222 | /*------------------------------------------------------------------------*/ |
223 | BitAndExpr<out OqlExpression expression> |
224 | ····(. |
225 | ········OqlExpression child; |
226 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
227 | ····.) |
228 | = AddExpr <out child> (. result.Add(child); .) |
229 | ··{"&" AddExpr <out child> (. result.Add(child, "&"); .) } |
230 | (. expression = result.Simplify(); .) |
231 | . |
232 | |
233 | |
234 | /*------------------------------------------------------------------------*/ |
235 | AddExpr<out OqlExpression expression> |
236 | ····(. |
237 | ········OqlExpression child; |
238 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
239 | ········string newOp = null; |
240 | ····.) |
241 | = MulExpr<out child> (. result.Add(child); .) |
242 | ····{ |
243 | ········( |
244 | ············"+" (. newOp = "+"; .) |
245 | ············| "-" (. newOp = "-"; .) |
246 | ········) |
247 | ········MulExpr<out child> (. result.Add(child, newOp); .) |
248 | ····} |
249 | (. expression = result.Simplify(); .) |
250 | . |
251 | |
252 | /*------------------------------------------------------------------------*/ |
253 | MulExpr<out OqlExpression expression> |
254 | ····(. |
255 | ········OqlExpression child; |
256 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
257 | ········string newOp = null; |
258 | ····.) |
259 | = Unary<out child> (. result.Add(child); .) |
260 | ····{ |
261 | ········( |
262 | ············"*" (. newOp = "*"; .) |
263 | ············| "/" (. newOp = "/"; .) |
264 | ············| "%" (. newOp = "%"; .) |
265 | ············| "MOD" (. newOp = "MOD"; .) |
266 | ········) |
267 | ········Unary<out child> (. result.Add(child, newOp); .) |
268 | ····} |
269 | (. expression = result.Simplify(); .) |
270 | . |
271 | |
272 | /*------------------------------------------------------------------------*/ |
273 | Unary <out OqlExpression expression> |
274 | ····(. |
275 | ········OqlExpression child; |
276 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
277 | ········string newOp = null; |
278 | ····.) |
279 | |
280 | = [······"+" (. newOp = "+"; .) |
281 | ····| "-" (. newOp = "-"; .) |
282 | ····| "~" (. newOp = "~"; .) |
283 | ··]·· Primary<out child> (. result.Add(child); child.UnaryOp = newOp; .) |
284 | (. expression = result.Simplify(); .)·· |
285 | . |
286 | /*------------------------------------------------------------------------*/ |
287 | Primary <out OqlExpression expression> |
288 | ····(. |
289 | ········OqlExpression result = null; |
290 | ····.) |
291 | =·· |
292 | ··( |
293 | ······ident (. result = new IdentifierExpression(t.val, t.line, t.col); .) |
294 | ············[ |
295 | ················"(" intCon |
296 | ····················(. |
297 | result. UnaryOp=""; // Index-Expression has Brackets, so no Op String is necessary |
298 | ····················result.Add(new IndexExpression(int.Parse(t.val), t.line, t.col)); |
299 | ····················.) |
300 | ················")" |
301 | ············] |
302 | ······| Literal <out result> |
303 | ······| parameter (. result = new ParameterExpression(t.val, t.line, t.col); .) |
304 | ······| "(" RootExpr <out result> (. result.HasBrackets = true; .) ")" |
305 | ··) |
306 | (. expression = result.Simplify(); .)·· |
307 | . |
308 | |
309 | Identifier <out OqlExpression expression> |
310 | ····(. |
311 | ········OqlExpression result = null; |
312 | ····.) |
313 | =·· |
314 | ····ident (. result = new IdentifierExpression(t.val, t.line, t.col); .) |
315 | (. expression = result.Simplify(); .)·· |
316 | . |
317 | |
318 | NumList <out OqlExpression expression> |
319 | ····(. ········ |
320 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
321 | ····.) |
322 | = |
323 | ····( |
324 | ········realCon (. result.Add(new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col)); .) |
325 | ········| intCon (. result.Add(new NumberExpression(int.Parse(t.val), t.line, t.col)); .) |
326 | ····) |
327 | { |
328 | ····"," |
329 | ····( |
330 | ········realCon (. result.Add(new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col), ","); .) |
331 | ········| intCon (. result.Add(new NumberExpression(int.Parse(t.val), t.line, t.col), ","); .) |
332 | ····) |
333 | } |
334 | (. expression = result.Simplify(); .) |
335 | . |
336 | |
337 | StringList <out OqlExpression expression> |
338 | ····(. |
339 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
340 | ····.) |
341 | = |
342 | ····stringCon (. result.Add(new StringLiteralExpression(t.val, t.line, t.col)); .) |
343 | ····{ |
344 | ········"," |
345 | ········stringCon (. result.Add(new StringLiteralExpression(t.val, t.line, t.col), ","); .) |
346 | ····} |
347 | (. expression = result; /* Do not simplify here, because otherwise the brackets are missing */ .) |
348 | . |
349 | |
350 | |
351 | |
352 | /*------------------------------------------------------------------------*/ |
353 | Literal <out OqlExpression expression> |
354 | ····(. |
355 | ········OqlExpression result = null; |
356 | ····.) |
357 | = |
358 | ( |
359 | ···· realCon (. result = new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col); .) |
360 | ····| intCon (. result = new NumberExpression(int.Parse(t.val), t.line, t.col); .) |
361 | ····| stringCon (. result = new StringLiteralExpression(t.val, t.line, t.col); .) |
362 | ····| "TRUE" (. result = new NamedConstantExpression("TRUE", t.line, t.col); .) |
363 | ····| "FALSE" (. result = new NamedConstantExpression("FALSE", t.line, t.col); .) |
364 | ····| "NULL" (. result = new NamedConstantExpression("NULL", t.line, t.col); .) |
365 | ) |
366 | (. expression = result.Simplify(); .)·· |
367 | . |
368 | |
369 | END NDOQL. |
370 |
New Commit (b47b95e)
1 | using System.Collections.Generic; |
2 | using System.Text; |
3 | using System.Globalization; |
4 | using NDOql.Expressions; |
5 | |
6 | COMPILER NDOQL |
7 | |
8 | |
9 | OqlExpression rootExpression; |
10 | public OqlExpression RootExpression |
11 | { |
12 | ····get { return rootExpression; } |
13 | } |
14 | |
15 | |
16 | |
17 | /*------------------------------------------------------------------------* |
18 | *----- SCANNER DESCRIPTION ----------------------------------------------* |
19 | *------------------------------------------------------------------------*/ |
20 | |
21 | IGNORECASE |
22 | |
23 | CHARACTERS |
24 | |
25 | ····tab················= '\u0009'. /*··9 = tabulator */ |
26 | ····eol················= '\u000a'. /* 10 = line feed */ |
27 | ····cr················ = '\u000d'. /* 13 = carriage return */ |
28 | ····newLine············= cr + eol. /* Line separator character (U+2028) + Paragraph separator character (U+2029) */ |
29 | |
30 | ····/* see https://msdn.microsoft.com/de-de/library/aa664670(v=vs.71).aspx |
31 | ······ and implementation in http://www.ssw.uni-linz.ac.at/Coco/CS/CSharp3.atg */ |
32 | |
33 | ····startletter········= 'A' .. 'Z' + 'a' .. 'z' + '_' + '\u00aa' + '\u00b5' + '\u00ba' + '\u00c0' .. '\u00d6' + '\u00d8' .. '\u00f6' + '\u00f8' .. '\u00ff'. |
34 | ····partletter········ = '.' + '0' .. '9' + 'A' .. 'Z' + 'a' .. 'z' + '_' + '\u0080' + '\u00a0' .. '\u00b3' + '\u00b5' + '\u00ba' + '\u00c0' .. '\u00d6' + '\u00d8' .. '\u00f6' + '\u00f8' .. '\u00ff'. |
35 | |
36 | ····digit··············= "0123456789". |
37 | ····hexDigit·········· = digit + "ABCDEFabcdef". |
38 | ····notDigit·········· = ANY - digit. |
39 | |
40 | ····regularStringChar··= ANY - "'" - newLine. |
41 | ····notNewLine········ = ANY - newLine . |
42 | ····ws················ = " " + tab + '\u000b' + '\u000c'. /* Any character with Unicode class Zs */ |
43 | |
44 | |
45 | TOKENS |
46 | |
47 | ··/* This definition is not exact, as it allows '_.x' or 'x..y' as valid identifiers. But we couldn't get a mapping to that kind of wrong identifiers anyway. */ |
48 | ····ident = startletter { partletter }.···· |
49 | |
50 | ··/*--------------------------------------------------------------------------------*/ |
51 | ····realCon = |
52 | ····['-'] [digit {digit}] "." digit {digit} |
53 | ············[("e" | "E" ) ["+" | "-"] digit {digit} ] ···················· |
54 | ········. |
55 | |
56 | ··/*--------------------------------------------------------------------------------*/ |
57 | ····intCon = |
58 | ········['-'] (digit {digit} | digit {digit} ) |
59 | ········. |
60 | |
61 | ··/*--------------------------------------------------------------------------------*/ |
62 | ····stringCon = "'"····{ regularStringChar } "'". |
63 | |
64 | |
65 | ····/*----- keyword names needed in LL(1) resolvers -----*/ |
66 | ····AND······= "AND". |
67 | ····OR······ = "OR". |
68 | ····NOT······= "NOT". |
69 | ····LIKE···· = "LIKE". |
70 | ····ESCAPE·· = "ESCAPE". |
71 | ····BETWEEN··= "BETWEEN". |
72 | ····IS······ = "IS". |
73 | ····NULL···· = "NULL". |
74 | ····TRUE······= "TRUE". |
75 | ····MOD···· = "MOD". |
76 | ····IN···· = "IN". |
77 | |
78 | |
79 | ····parameter =··"{" digit "}". |
80 | |
81 | |
82 | |
83 | COMMENTS FROM "--" TO eol |
84 | |
85 | IGNORE eol + cr + tab |
86 | |
87 | PRODUCTIONS |
88 | |
89 | /*------------------------------------------------------------------------* |
90 | *--------------------------- Declarations -------------------------------* |
91 | *------------------------------------------------------------------------*/ |
92 | |
93 | NDOQL = RootExpr<out this.rootExpression> . |
94 | |
95 | /*------------------------------------------------------------------------*/ |
96 | |
97 | RootExpr<out OqlExpression expression> |
98 | ····(.··OqlExpression child; |
99 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
100 | ········bool negated = false; |
101 | ····.) |
102 | = ····[NOT (.negated = true; .)] OrExpr<out child> |
103 | (. |
104 | ····if (negated) result.UnaryOp = "NOT"; |
105 | ····result.Add(child); |
106 | ····expression = result.Simplify(); |
107 | .) |
108 | . |
109 | |
110 | /*------------------------------------------------------------------------*/ |
111 | OrExpr <out OqlExpression expression>·· |
112 | ····(. |
113 | ········OqlExpression child; |
114 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
115 | ····.) |
116 | |
117 | = AndExpr ············<out child> (. result.Add(child); .) |
118 | ··{ "OR" (. bool negated = false; .) [NOT (. negated = true; .)] |
119 | ··AndExpr<out child> (. if (negated) child.UnaryOp = "NOT"; result.Add(child, "OR"); .) |
120 | ··} |
121 | |
122 | (. expression = result.Simplify(); .) |
123 | . |
124 | |
125 | |
126 | /*------------------------------------------------------------------------*/ |
127 | AndExpr<out OqlExpression expression>·· |
128 | ····(. |
129 | ········OqlExpression child; |
130 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
131 | ····.) |
132 | = EqlExpr<out child> (. result.Add(child); .) { |
133 | ················································"AND" (. bool negated = false; .) [NOT (. negated = true; .)] |
134 | ················································EqlExpr<out child> (. if (negated) child.UnaryOp = "NOT"; result.Add(child, "AND"); .) |
135 | ··············································} |
136 | (. expression = result.Simplify(); .) |
137 | . |
138 | |
139 | |
140 | /*------------------------------------------------------------------------*/ |
141 | EqlExpr<out OqlExpression expression> |
142 | ····(. |
143 | ········OqlExpression child; |
144 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
145 | ········string newOp = null; |
146 | ········bool negated = false; |
147 | ····.) |
148 | ···· |
149 | = ( |
150 | ····IF(!(scanner.Peek().kind==_IN)) |
151 | ····RelExpr<out child> (. result.Add(child); .) |
152 | ····{ |
153 | ········( |
154 | ············"!=" (. newOp = "<>"; .) |
155 | ············| "<>" (. newOp = "<>"; .) |
156 | ············| "=" (. newOp = "="; .) [NOT (. negated = true; .)] |
157 | ············| "LIKE" (. newOp = "LIKE"; .) /*[ESCAPE stringCon]*/ |
158 | ········) |
159 | ········RelExpr<out child> (. if (negated) child.UnaryOp = "NOT"; result.Add(child, newOp); .) |
160 | ····} |
161 | ····| |
162 | ····Identifier <out child> (. result.Add(child); .) |
163 | ········IN "(" |
164 | ········( |
165 | ············NumList <out child> (. child.HasBrackets = true; result.Add(child, "IN"); .) |
166 | ············| StringList <out child> (. child.HasBrackets = true; result.Add(child, "IN"); .) |
167 | ········) |
168 | ········")" |
169 | ·· ) |
170 | (. expression = result.Simplify(); .) |
171 | . |
172 | |
173 | /*------------------------------------------------------------------------*/ |
174 | RelExpr <out OqlExpression expression> |
175 | ····(. |
176 | ········OqlExpression child; |
177 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
178 | ········string newOp = null; |
179 | ········bool negated = false; |
180 | ····.) |
181 | = BitOrExpr<out child> (. result.Add(child); .) |
182 | ··[ |
183 | ····( |
184 | ········"<" (. newOp = "<"; .) |
185 | ········| ">" (. newOp = ">"; .) |
186 | ········| "<=" (. newOp = "<="; .) |
187 | ········| ">=" (. newOp = ">="; .) |
188 | ········| "!<" (. newOp = ">="; .) |
189 | ········| "!>" (. newOp = "<="; .) |
190 | ····) BitOrExpr <out child> (. result.Add(child, newOp); .) |
191 | ····| IS [NOT (. negated = true; .)] NULL (. result.Add(new NamedConstantExpression("NULL", negated, t.line, t.col), "IS"); .) |
192 | ····| [NOT (. negated = true; .)] BETWEEN BitOrExpr <out child> (. result.Add(child, "BETWEEN"); .) |
193 | ································AND BitOrExpr <out child> (. result.Add(child, "BETWEEN"); .) |
194 | ··] |
195 | (. expression = result.Simplify(); .) |
196 | . |
197 | |
198 | /*------------------------------------------------------------------------*/ |
199 | BitOrExpr<out OqlExpression expression> |
200 | ····(. |
201 | ········OqlExpression child; |
202 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
203 | ····.) |
204 | = BitXorExpr <out child> (. result.Add(child); .) |
205 | ··{"|" BitXorExpr <out child> (. result.Add(child, "|"); .) } |
206 | (. expression = result.Simplify(); .) |
207 | . |
208 | |
209 | |
210 | /*------------------------------------------------------------------------*/ |
211 | BitXorExpr<out OqlExpression expression> |
212 | ····(. |
213 | ········OqlExpression child; |
214 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
215 | ····.) |
216 | = BitAndExpr <out child> (. result.Add(child); .) |
217 | ··{"^" BitAndExpr <out child> (. result.Add(child, "^"); .) } |
218 | (. expression = result.Simplify(); .) |
219 | . |
220 | |
221 | |
222 | /*------------------------------------------------------------------------*/ |
223 | BitAndExpr<out OqlExpression expression> |
224 | ····(. |
225 | ········OqlExpression child; |
226 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
227 | ····.) |
228 | = AddExpr <out child> (. result.Add(child); .) |
229 | ··{"&" AddExpr <out child> (. result.Add(child, "&"); .) } |
230 | (. expression = result.Simplify(); .) |
231 | . |
232 | |
233 | |
234 | /*------------------------------------------------------------------------*/ |
235 | AddExpr<out OqlExpression expression> |
236 | ····(. |
237 | ········OqlExpression child; |
238 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
239 | ········string newOp = null; |
240 | ····.) |
241 | = MulExpr<out child> (. result.Add(child); .) |
242 | ····{ |
243 | ········( |
244 | ············"+" (. newOp = "+"; .) |
245 | ············| "-" (. newOp = "-"; .) |
246 | ········) |
247 | ········MulExpr<out child> (. result.Add(child, newOp); .) |
248 | ····} |
249 | (. expression = result.Simplify(); .) |
250 | . |
251 | |
252 | /*------------------------------------------------------------------------*/ |
253 | MulExpr<out OqlExpression expression> |
254 | ····(. |
255 | ········OqlExpression child; |
256 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
257 | ········string newOp = null; |
258 | ····.) |
259 | = Unary<out child> (. result.Add(child); .) |
260 | ····{ |
261 | ········( |
262 | ············"*" (. newOp = "*"; .) |
263 | ············| "/" (. newOp = "/"; .) |
264 | ············| "%" (. newOp = "%"; .) |
265 | ············| "MOD" (. newOp = "MOD"; .) |
266 | ········) |
267 | ········Unary<out child> (. result.Add(child, newOp); .) |
268 | ····} |
269 | (. expression = result.Simplify(); .) |
270 | . |
271 | |
272 | /*------------------------------------------------------------------------*/ |
273 | Unary <out OqlExpression expression> |
274 | ····(. |
275 | ········OqlExpression child; |
276 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
277 | ········string newOp = null; |
278 | ····.) |
279 | |
280 | = [······"+" (. newOp = "+"; .) |
281 | ····| "-" (. newOp = "-"; .) |
282 | ····| "~" (. newOp = "~"; .) |
283 | ··]·· Primary<out child> (. result.Add(child); child.UnaryOp = newOp; .) |
284 | (. expression = result.Simplify(); .)·· |
285 | . |
286 | /*------------------------------------------------------------------------*/ |
287 | Primary <out OqlExpression expression> |
288 | ····(. |
289 | ········OqlExpression result = null; |
290 | ········OqlExpression child; |
291 | ····.) |
292 | =·· |
293 | ··( |
294 | ······ident (. result = new IdentifierExpression(t.val, t.line, t.col); .) |
295 | ············[ |
296 | ················IF(IsOidIdentifier(result)) |
297 | ················"(" intCon |
298 | ····················(. |
299 | result. UnaryOp=""; |
300 | ····················result.Add(new IndexExpression(int.Parse(t.val), t.line, t.col)); |
301 | ····················.) |
302 | ················")" |
303 | ················| |
304 | ················"(" |
305 | ····················ParameterList <out child> |
306 | ····················(. |
307 | ························result = new FunctionExpression(result.Value, t.line, t.col); |
308 | ························result.UnaryOp="";························ |
309 | ························result.Add(child); |
310 | ····················.) |
311 | ················")" |
312 | ············] |
313 | ······| Literal <out result> |
314 | ······| parameter (. result = new ParameterExpression(t.val, t.line, t.col); .) |
315 | ······| "(" RootExpr <out result> (. result.HasBrackets = true; .) ")" |
316 | ··) |
317 | (. expression = result.Simplify(); .)·· |
318 | . |
319 | |
320 | Identifier <out OqlExpression expression> |
321 | ····(. |
322 | ········OqlExpression result = null; |
323 | ····.) |
324 | =·· |
325 | ····ident (. result = new IdentifierExpression(t.val, t.line, t.col); .) |
326 | (. expression = result.Simplify(); .)·· |
327 | . |
328 | |
329 | NumList <out OqlExpression expression> |
330 | ····(. ········ |
331 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
332 | ····.) |
333 | = |
334 | ····( |
335 | ········realCon (. result.Add(new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col)); .) |
336 | ········| intCon (. result.Add(new NumberExpression(int.Parse(t.val), t.line, t.col)); .) |
337 | ····) |
338 | { |
339 | ····"," |
340 | ····( |
341 | ········realCon (. result.Add(new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col), ","); .) |
342 | ········| intCon (. result.Add(new NumberExpression(int.Parse(t.val), t.line, t.col), ","); .) |
343 | ····) |
344 | } |
345 | (. expression = result.Simplify(); .) |
346 | . |
347 | |
348 | StringList <out OqlExpression expression> |
349 | ····(. |
350 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
351 | ····.) |
352 | = |
353 | ····stringCon (. result.Add(new StringLiteralExpression(t.val, t.line, t.col)); .) |
354 | ····{ |
355 | ········"," |
356 | ········stringCon (. result.Add(new StringLiteralExpression(t.val, t.line, t.col), ","); .) |
357 | ····} |
358 | (. expression = result; /* Do not simplify here, because otherwise the brackets are missing */ .) |
359 | . |
360 | |
361 | ParameterList <out OqlExpression expression> |
362 | ····(. |
363 | ········OqlExpression result = new ParameterListExpression(la.line, la.col); |
364 | ········OqlExpression child; |
365 | ····.) |
366 | = |
367 | ····[ |
368 | ········Primary <out child> (. result.Add(child); .) |
369 | ········{ |
370 | ············"," |
371 | ············Primary <out child> (. result.Add(child, ","); .) |
372 | ········} |
373 | ····] |
374 | (. expression = result; /* Do not simplify here, because otherwise the brackets are missing */ .) |
375 | . |
376 | |
377 | |
378 | |
379 | /*------------------------------------------------------------------------*/ |
380 | Literal <out OqlExpression expression> |
381 | ····(. |
382 | ········OqlExpression result = null; |
383 | ····.) |
384 | = |
385 | ( |
386 | ···· realCon (. result = new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col); .) |
387 | ····| intCon (. result = new NumberExpression(int.Parse(t.val), t.line, t.col); .) |
388 | ····| stringCon (. result = new StringLiteralExpression(t.val, t.line, t.col); .) |
389 | ····| "TRUE" (. result = new NamedConstantExpression("TRUE", t.line, t.col); .) |
390 | ····| "FALSE" (. result = new NamedConstantExpression("FALSE", t.line, t.col); .) |
391 | ····| "NULL" (. result = new NamedConstantExpression("NULL", t.line, t.col); .) |
392 | ) |
393 | (. expression = result.Simplify(); .)·· |
394 | . |
395 | |
396 | END NDOQL. |
397 |