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