Datei: NDODLL/NDOql/Parser.cs
Last Commit (fe801ed)
| 1 | using System.Collections.Generic; |
| 2 | using System.Text; |
| 3 | using System.Globalization; |
| 4 | using NDOql.Expressions; |
| 5 | |
| 6 | |
| 7 | |
| 8 | // |
| 9 | // This is generated code. Do not change it directly, change the Parser.frame file and rebuild the grammar. |
| 10 | // |
| 11 | |
| 12 | using System; |
| 13 | #pragma warning disable 3008, 1591 |
| 14 | |
| 15 | namespace NDOql { |
| 16 | |
| 17 | |
| 18 | |
| 19 | public class Parser { |
| 20 | ····public const int _EOF = 0; |
| 21 | ····public const int _ident = 1; |
| 22 | ····public const int _realCon = 2; |
| 23 | ····public const int _intCon = 3; |
| 24 | ····public const int _stringCon = 4; |
| 25 | ····public const int _AND = 5; |
| 26 | ····public const int _OR = 6; |
| 27 | ····public const int _NOT = 7; |
| 28 | ····public const int _LIKE = 8; |
| 29 | ····public const int _ESCAPE = 9; |
| 30 | ····public const int _BETWEEN = 10; |
| 31 | ····public const int _IS = 11; |
| 32 | ····public const int _NULL = 12; |
| 33 | ····public const int _TRUE = 13; |
| 34 | ····public const int _MOD = 14; |
| 35 | ····public const int _IN = 15; |
| 36 | ····public const int _parameter = 16; |
| 37 | ····public const int maxT = 39; |
| 38 | |
| 39 | ····const bool T = true; |
| 40 | ····const bool x = false; |
| 41 | ····const int minErrDist = 2; |
| 42 | ···· |
| 43 | ····public Scanner scanner; |
| 44 | ····public Errors··errors; |
| 45 | |
| 46 | ····public Token t;····// last recognized token |
| 47 | ····public Token la;·· // lookahead token |
| 48 | ····int errDist = minErrDist; |
| 49 | |
| 50 | OqlExpression rootExpression; |
| 51 | public OqlExpression RootExpression |
| 52 | { |
| 53 | ····get { return rootExpression; } |
| 54 | } |
| 55 | |
| 56 | |
| 57 | |
| 58 | /*------------------------------------------------------------------------* |
| 59 | *----- SCANNER DESCRIPTION ----------------------------------------------* |
| 60 | *------------------------------------------------------------------------*/ |
| 61 | |
| 62 | |
| 63 | |
| 64 | ····public Parser(Scanner scanner) { |
| 65 | ········this.scanner = scanner; |
| 66 | ········errors = new Errors(); |
| 67 | ····} |
| 68 | |
| 69 | ····void SynErr (int n) { |
| 70 | ········if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n); |
| 71 | ········errDist = 0; |
| 72 | ····} |
| 73 | |
| 74 | ····public void SemErr (string msg) { |
| 75 | ········if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg); |
| 76 | ········errDist = 0; |
| 77 | ····} |
| 78 | ···· |
| 79 | ····void Get () { |
| 80 | ········for (;;) { |
| 81 | ············t = la; |
| 82 | ············la = scanner.Scan(); |
| 83 | ············if (la.kind <= maxT) { ++errDist; break; } |
| 84 | |
| 85 | ············la = t; |
| 86 | ········} |
| 87 | ····} |
| 88 | ···· |
| 89 | ····void Expect (int n) { |
| 90 | ········if (la.kind==n) Get(); else { SynErr(n); } |
| 91 | ····} |
| 92 | ···· |
| 93 | ····bool StartOf (int s) { |
| 94 | ········return set[s, la.kind]; |
| 95 | ····} |
| 96 | ···· |
| 97 | ····void ExpectWeak (int n, int follow) { |
| 98 | ········if (la.kind == n) Get(); |
| 99 | ········else { |
| 100 | ············SynErr(n); |
| 101 | ············while (!StartOf(follow)) Get(); |
| 102 | ········} |
| 103 | ····} |
| 104 | |
| 105 | |
| 106 | ····bool WeakSeparator(int n, int syFol, int repFol) { |
| 107 | ········int kind = la.kind; |
| 108 | ········if (kind == n) {Get(); return true;} |
| 109 | ········else if (StartOf(repFol)) {return false;} |
| 110 | ········else { |
| 111 | ············SynErr(n); |
| 112 | ············while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) { |
| 113 | ················Get(); |
| 114 | ················kind = la.kind; |
| 115 | ············} |
| 116 | ············return StartOf(syFol); |
| 117 | ········} |
| 118 | ····} |
| 119 | |
| 120 | ····bool IsOidIdentifier(OqlExpression iexp) { |
| 121 | ········return ((string)iexp.Value).EndsWith("oid"); |
| 122 | ····} |
| 123 | |
| 124 | ···· |
| 125 | ····void NDOQL() { |
| 126 | ········RootExpr(out this.rootExpression); |
| 127 | ····} |
| 128 | |
| 129 | ····void RootExpr(out OqlExpression expression) { |
| 130 | ········OqlExpression child; |
| 131 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 132 | ········bool negated = false; |
| 133 | ········ |
| 134 | ········if (la.kind == 7) { |
| 135 | ············Get(); |
| 136 | ············negated = true; |
| 137 | ········} |
| 138 | ········OrExpr(out child); |
| 139 | ········if (negated) result.UnaryOp = "NOT"; |
| 140 | ········result.Add(child); |
| 141 | ········expression = result.Simplify(); |
| 142 | ········ |
| 143 | ····} |
| 144 | |
| 145 | ····void OrExpr(out OqlExpression expression) { |
| 146 | ········OqlExpression child; |
| 147 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 148 | ········ |
| 149 | ········AndExpr(out child); |
| 150 | ········result.Add(child); |
| 151 | ········while (la.kind == 6) { |
| 152 | ············Get(); |
| 153 | ············bool negated = false; |
| 154 | ············if (la.kind == 7) { |
| 155 | ················Get(); |
| 156 | ················negated = true; |
| 157 | ············} |
| 158 | ············AndExpr(out child); |
| 159 | ············if (negated) child.UnaryOp = "NOT"; result.Add(child, "OR"); |
| 160 | ········} |
| 161 | ········expression = result.Simplify(); |
| 162 | ····} |
| 163 | |
| 164 | ····void AndExpr(out OqlExpression expression) { |
| 165 | ········OqlExpression child; |
| 166 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 167 | ········ |
| 168 | ········EqlExpr(out child); |
| 169 | ········result.Add(child); |
| 170 | ········while (la.kind == 5) { |
| 171 | ············Get(); |
| 172 | ············bool negated = false; |
| 173 | ············if (la.kind == 7) { |
| 174 | ················Get(); |
| 175 | ················negated = true; |
| 176 | ············} |
| 177 | ············EqlExpr(out child); |
| 178 | ············if (negated) child.UnaryOp = "NOT"; result.Add(child, "AND"); |
| 179 | ········} |
| 180 | ········expression = result.Simplify(); |
| 181 | ····} |
| 182 | |
| 183 | ····void EqlExpr(out OqlExpression expression) { |
| 184 | ········OqlExpression child; |
| 185 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 186 | ········string newOp = null; |
| 187 | ········bool negated = false; |
| 188 | ········ |
| 189 | ········if (!(scanner.Peek().kind==_IN)) { |
| 190 | ············RelExpr(out child); |
| 191 | ············result.Add(child); |
| 192 | ············while (StartOf(1)) { |
| 193 | ················if (la.kind == 17) { |
| 194 | ····················Get(); |
| 195 | ····················newOp = "<>"; |
| 196 | ················} else if (la.kind == 18) { |
| 197 | ····················Get(); |
| 198 | ····················newOp = "<>"; |
| 199 | ················} else if (la.kind == 19) { |
| 200 | ····················Get(); |
| 201 | ····················newOp = "="; |
| 202 | ····················if (la.kind == 7) { |
| 203 | ························Get(); |
| 204 | ························negated = true; |
| 205 | ····················} |
| 206 | ················} else { |
| 207 | ····················Get(); |
| 208 | ····················newOp = "LIKE"; |
| 209 | ················} |
| 210 | ················RelExpr(out child); |
| 211 | ················if (negated) child.UnaryOp = "NOT"; result.Add(child, newOp); |
| 212 | ············} |
| 213 | ········} else if (la.kind == 1) { |
| 214 | ············Identifier(out child); |
| 215 | ············result.Add(child); |
| 216 | ············Expect(15); |
| 217 | ············Expect(20); |
| 218 | ············if (la.kind == 2 || la.kind == 3) { |
| 219 | ················NumList(out child); |
| 220 | ················child.HasBrackets = true; result.Add(child, "IN"); |
| 221 | ············} else if (la.kind == 4) { |
| 222 | ················StringList(out child); |
| 223 | ················child.HasBrackets = true; result.Add(child, "IN"); |
| 224 | ············} else SynErr(40); |
| 225 | ············Expect(21); |
| 226 | ········} else SynErr(41); |
| 227 | ········expression = result.Simplify(); |
| 228 | ····} |
| 229 | |
| 230 | ····void RelExpr(out OqlExpression expression) { |
| 231 | ········OqlExpression child; |
| 232 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 233 | ········string newOp = null; |
| 234 | ········bool negated = false; |
| 235 | ········ |
| 236 | ········BitOrExpr(out child); |
| 237 | ········result.Add(child); |
| 238 | ········if (StartOf(2)) { |
| 239 | ············if (StartOf(3)) { |
| 240 | ················switch (la.kind) { |
| 241 | ················case 22: { |
| 242 | ····················Get(); |
| 243 | ····················newOp = "<"; |
| 244 | ····················break; |
| 245 | ················} |
| 246 | ················case 23: { |
| 247 | ····················Get(); |
| 248 | ····················newOp = ">"; |
| 249 | ····················break; |
| 250 | ················} |
| 251 | ················case 24: { |
| 252 | ····················Get(); |
| 253 | ····················newOp = "<="; |
| 254 | ····················break; |
| 255 | ················} |
| 256 | ················case 25: { |
| 257 | ····················Get(); |
| 258 | ····················newOp = ">="; |
| 259 | ····················break; |
| 260 | ················} |
| 261 | ················case 26: { |
| 262 | ····················Get(); |
| 263 | ····················newOp = ">="; |
| 264 | ····················break; |
| 265 | ················} |
| 266 | ················case 27: { |
| 267 | ····················Get(); |
| 268 | ····················newOp = "<="; |
| 269 | ····················break; |
| 270 | ················} |
| 271 | ················} |
| 272 | ················BitOrExpr(out child); |
| 273 | ················result.Add(child, newOp); |
| 274 | ············} else if (la.kind == 11) { |
| 275 | ················Get(); |
| 276 | ················if (la.kind == 7) { |
| 277 | ····················Get(); |
| 278 | ····················negated = true; |
| 279 | ················} |
| 280 | ················Expect(12); |
| 281 | ················result.Add(new NamedConstantExpression("NULL", negated, t.line, t.col), "IS"); |
| 282 | ············} else { |
| 283 | ················if (la.kind == 7) { |
| 284 | ····················Get(); |
| 285 | ····················negated = true; |
| 286 | ················} |
| 287 | ················Expect(10); |
| 288 | ················BitOrExpr(out child); |
| 289 | ················result.Add(child, "BETWEEN"); |
| 290 | ················Expect(5); |
| 291 | ················BitOrExpr(out child); |
| 292 | ················result.Add(child, "BETWEEN"); |
| 293 | ············} |
| 294 | ········} |
| 295 | ········expression = result.Simplify(); |
| 296 | ····} |
| 297 | |
| 298 | ····void Identifier(out OqlExpression expression) { |
| 299 | ········OqlExpression result = null; |
| 300 | ········ |
| 301 | ········Expect(1); |
| 302 | ········result = new IdentifierExpression(t.val, t.line, t.col); |
| 303 | ········expression = result.Simplify(); |
| 304 | ····} |
| 305 | |
| 306 | ····void NumList(out OqlExpression expression) { |
| 307 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 308 | ········ |
| 309 | ········if (la.kind == 2) { |
| 310 | ············Get(); |
| 311 | ············result.Add(new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col)); |
| 312 | ········} else if (la.kind == 3) { |
| 313 | ············Get(); |
| 314 | ············result.Add(new NumberExpression(int.Parse(t.val), t.line, t.col)); |
| 315 | ········} else SynErr(42); |
| 316 | ········while (la.kind == 37) { |
| 317 | ············Get(); |
| 318 | ············if (la.kind == 2) { |
| 319 | ················Get(); |
| 320 | ················result.Add(new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col), ","); |
| 321 | ············} else if (la.kind == 3) { |
| 322 | ················Get(); |
| 323 | ················result.Add(new NumberExpression(int.Parse(t.val), t.line, t.col), ","); |
| 324 | ············} else SynErr(43); |
| 325 | ········} |
| 326 | expression = result. Simplify( ) ; |
| 327 | ····} |
| 328 | |
| 329 | ····void StringList(out OqlExpression expression) { |
| 330 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 331 | ········ |
| 332 | ········Expect(4); |
| 333 | ········result.Add(new StringLiteralExpression(t.val, t.line, t.col)); |
| 334 | ········while (la.kind == 37) { |
| 335 | ············Get(); |
| 336 | ············Expect(4); |
| 337 | ············result.Add(new StringLiteralExpression(t.val, t.line, t.col), ","); |
| 338 | ········} |
| 339 | expression = result; /* Do not simplify here, because otherwise the brackets are missing */ |
| 340 | ····} |
| 341 | |
| 342 | ····void BitOrExpr(out OqlExpression expression) { |
| 343 | ········OqlExpression child; |
| 344 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 345 | ········ |
| 346 | ········BitXorExpr(out child); |
| 347 | ········result.Add(child); |
| 348 | ········while (la.kind == 28) { |
| 349 | ············Get(); |
| 350 | ············BitXorExpr(out child); |
| 351 | ············result.Add(child, "|"); |
| 352 | ········} |
| 353 | ········expression = result.Simplify(); |
| 354 | ····} |
| 355 | |
| 356 | ····void BitXorExpr(out OqlExpression expression) { |
| 357 | ········OqlExpression child; |
| 358 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 359 | ········ |
| 360 | ········BitAndExpr(out child); |
| 361 | ········result.Add(child); |
| 362 | ········while (la.kind == 29) { |
| 363 | ············Get(); |
| 364 | ············BitAndExpr(out child); |
| 365 | ············result.Add(child, "^"); |
| 366 | ········} |
| 367 | ········expression = result.Simplify(); |
| 368 | ····} |
| 369 | |
| 370 | ····void BitAndExpr(out OqlExpression expression) { |
| 371 | ········OqlExpression child; |
| 372 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 373 | ········ |
| 374 | ········AddExpr(out child); |
| 375 | ········result.Add(child); |
| 376 | ········while (la.kind == 30) { |
| 377 | ············Get(); |
| 378 | ············AddExpr(out child); |
| 379 | ············result.Add(child, "&"); |
| 380 | ········} |
| 381 | ········expression = result.Simplify(); |
| 382 | ····} |
| 383 | |
| 384 | ····void AddExpr(out OqlExpression expression) { |
| 385 | ········OqlExpression child; |
| 386 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 387 | ········string newOp = null; |
| 388 | ········ |
| 389 | ········MulExpr(out child); |
| 390 | ········result.Add(child); |
| 391 | ········while (la.kind == 31 || la.kind == 32) { |
| 392 | ············if (la.kind == 31) { |
| 393 | ················Get(); |
| 394 | ················newOp = "+"; |
| 395 | ············} else { |
| 396 | ················Get(); |
| 397 | ················newOp = "-"; |
| 398 | ············} |
| 399 | ············MulExpr(out child); |
| 400 | ············result.Add(child, newOp); |
| 401 | ········} |
| 402 | ········expression = result.Simplify(); |
| 403 | ····} |
| 404 | |
| 405 | ····void MulExpr(out OqlExpression expression) { |
| 406 | ········OqlExpression child; |
| 407 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 408 | ········string newOp = null; |
| 409 | ········ |
| 410 | ········Unary(out child); |
| 411 | ········result.Add(child); |
| 412 | ········while (StartOf(4)) { |
| 413 | ············if (la.kind == 33) { |
| 414 | ················Get(); |
| 415 | ················newOp = "*"; |
| 416 | ············} else if (la.kind == 34) { |
| 417 | ················Get(); |
| 418 | ················newOp = "/"; |
| 419 | ············} else if (la.kind == 35) { |
| 420 | ················Get(); |
| 421 | ················newOp = "%"; |
| 422 | ············} else { |
| 423 | ················Get(); |
| 424 | ················newOp = "MOD"; |
| 425 | ············} |
| 426 | ············Unary(out child); |
| 427 | ············result.Add(child, newOp); |
| 428 | ········} |
| 429 | ········expression = result.Simplify(); |
| 430 | ····} |
| 431 | |
| 432 | ····void Unary(out OqlExpression expression) { |
| 433 | ········OqlExpression child; |
| 434 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 435 | ········string newOp = null; |
| 436 | ········ |
| 437 | ········if (la.kind == 31 || la.kind == 32 || la.kind == 36) { |
| 438 | ············if (la.kind == 31) { |
| 439 | ················Get(); |
| 440 | ················newOp = "+"; |
| 441 | ············} else if (la.kind == 32) { |
| 442 | ················Get(); |
| 443 | ················newOp = "-"; |
| 444 | ············} else { |
| 445 | ················Get(); |
| 446 | ················newOp = "~"; |
| 447 | ············} |
| 448 | ········} |
| 449 | ········Primary(out child); |
| 450 | ········result.Add(child); child.UnaryOp = newOp; |
| 451 | ········expression = result.Simplify(); |
| 452 | ····} |
| 453 | |
| 454 | ····void Primary(out OqlExpression expression) { |
| 455 | ········OqlExpression result = null; |
| 456 | ········OqlExpression child; |
| 457 | ········ |
| 458 | ········if (la.kind == 1) { |
| 459 | ············Get(); |
| 460 | ············result = new IdentifierExpression(t.val, t.line, t.col); |
| 461 | ············if (la.kind == 20) { |
| 462 | ················if (IsOidIdentifier(result)) { |
| 463 | ····················Expect(20); |
| 464 | ····················Expect(3); |
| 465 | ····················result.UnaryOp=""; |
| 466 | ····················result.Add(new IndexExpression(int.Parse(t.val), t.line, t.col)); |
| 467 | ···················· |
| 468 | ····················Expect(21); |
| 469 | ················} else { |
| 470 | ····················Get(); |
| 471 | ····················ParameterList(out child); |
| 472 | ····················result = new FunctionExpression(result.Value, t.line, t.col); |
| 473 | ····················result.UnaryOp="";························ |
| 474 | ····················result.Add(child); |
| 475 | ···················· |
| 476 | ····················Expect(21); |
| 477 | ················} |
| 478 | ············} |
| 479 | ········} else if (StartOf(5)) { |
| 480 | ············Literal(out result); |
| 481 | ········} else if (la.kind == 16) { |
| 482 | ············Get(); |
| 483 | ············result = new ParameterExpression(t.val, t.line, t.col); |
| 484 | ········} else if (la.kind == 20) { |
| 485 | ············Get(); |
| 486 | ············RootExpr(out result); |
| 487 | ············result.HasBrackets = true; |
| 488 | ············Expect(21); |
| 489 | ········} else SynErr(44); |
| 490 | ········expression = result.Simplify(); |
| 491 | ····} |
| 492 | |
| 493 | ····void ParameterList(out OqlExpression expression) { |
| 494 | ········OqlExpression result = new ParameterListExpression(la.line, la.col); |
| 495 | ········OqlExpression child; |
| 496 | ········ |
| 497 | ········if (StartOf(6)) { |
| 498 | ············Primary(out child); |
| 499 | ············result.Add(child); |
| 500 | ············while (la.kind == 37) { |
| 501 | ················Get(); |
| 502 | ················Primary(out child); |
| 503 | ················result.Add(child, ","); |
| 504 | ············} |
| 505 | ········} |
| 506 | ········expression = result; /* Do not simplify here, because otherwise the brackets are missing */ |
| 507 | ····} |
| 508 | |
| 509 | ····void Literal(out OqlExpression expression) { |
| 510 | ········OqlExpression result = null; |
| 511 | ········ |
| 512 | ········switch (la.kind) { |
| 513 | ········case 2: { |
| 514 | ············Get(); |
| 515 | ············result = new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col); |
| 516 | ············break; |
| 517 | ········} |
| 518 | ········case 3: { |
| 519 | ············Get(); |
| 520 | ············result = new NumberExpression(int.Parse(t.val), t.line, t.col); |
| 521 | ············break; |
| 522 | ········} |
| 523 | ········case 4: { |
| 524 | ············Get(); |
| 525 | ············result = new StringLiteralExpression(t.val, t.line, t.col); |
| 526 | ············break; |
| 527 | ········} |
| 528 | ········case 13: { |
| 529 | ············Get(); |
| 530 | ············result = new NamedConstantExpression("TRUE", t.line, t.col); |
| 531 | ············break; |
| 532 | ········} |
| 533 | ········case 38: { |
| 534 | ············Get(); |
| 535 | ············result = new NamedConstantExpression("FALSE", t.line, t.col); |
| 536 | ············break; |
| 537 | ········} |
| 538 | ········case 12: { |
| 539 | ············Get(); |
| 540 | ············result = new NamedConstantExpression("NULL", t.line, t.col); |
| 541 | ············break; |
| 542 | ········} |
| 543 | ········default: SynErr(45); break; |
| 544 | ········} |
| 545 | ········expression = result.Simplify(); |
| 546 | ····} |
| 547 | |
| 548 | |
| 549 | |
| 550 | ····public void Parse() { |
| 551 | ········la = new Token(); |
| 552 | ········la.val = "";········ |
| 553 | ········Get(); |
| 554 | ········NDOQL(); |
| 555 | ········Expect(0); |
| 556 | |
| 557 | ····} |
| 558 | ···· |
| 559 | ····static readonly bool[,] set = { |
| 560 | ········{T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x}, |
| 561 | ········{x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x}, |
| 562 | ········{x,x,x,x, x,x,x,T, x,x,T,T, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x}, |
| 563 | ········{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x}, |
| 564 | ········{x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x}, |
| 565 | ········{x,x,T,T, T,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x}, |
| 566 | ········{x,T,T,T, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x} |
| 567 | |
| 568 | ····}; |
| 569 | } // end Parser |
| 570 | |
| 571 | |
| 572 | public class Errors { |
| 573 | ····public int count = 0;····································// number of errors detected |
| 574 | ····public System.IO.TextWriter errorStream = Console.Out;·· // error messages go to this stream |
| 575 | ····public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text |
| 576 | |
| 577 | ····public virtual void SynErr (int line, int col, int n) { |
| 578 | ········string s; |
| 579 | ········switch (n) { |
| 580 | ············case 0: s = "EOF expected"; break; |
| 581 | ············case 1: s = "ident expected"; break; |
| 582 | ············case 2: s = "realCon expected"; break; |
| 583 | ············case 3: s = "intCon expected"; break; |
| 584 | ············case 4: s = "stringCon expected"; break; |
| 585 | ············case 5: s = "AND expected"; break; |
| 586 | ············case 6: s = "OR expected"; break; |
| 587 | ············case 7: s = "NOT expected"; break; |
| 588 | ············case 8: s = "LIKE expected"; break; |
| 589 | ············case 9: s = "ESCAPE expected"; break; |
| 590 | ············case 10: s = "BETWEEN expected"; break; |
| 591 | ············case 11: s = "IS expected"; break; |
| 592 | ············case 12: s = "NULL expected"; break; |
| 593 | ············case 13: s = "TRUE expected"; break; |
| 594 | ············case 14: s = "MOD expected"; break; |
| 595 | ············case 15: s = "IN expected"; break; |
| 596 | ············case 16: s = "parameter expected"; break; |
| 597 | ············case 17: s = "\"!=\" expected"; break; |
| 598 | ············case 18: s = "\"<>\" expected"; break; |
| 599 | ············case 19: s = "\"=\" expected"; break; |
| 600 | ············case 20: s = "\"(\" expected"; break; |
| 601 | ············case 21: s = "\")\" expected"; break; |
| 602 | ············case 22: s = "\"<\" expected"; break; |
| 603 | ············case 23: s = "\">\" expected"; break; |
| 604 | ············case 24: s = "\"<=\" expected"; break; |
| 605 | ············case 25: s = "\">=\" expected"; break; |
| 606 | ············case 26: s = "\"!<\" expected"; break; |
| 607 | ············case 27: s = "\"!>\" expected"; break; |
| 608 | ············case 28: s = "\"|\" expected"; break; |
| 609 | ············case 29: s = "\"^\" expected"; break; |
| 610 | ············case 30: s = "\"&\" expected"; break; |
| 611 | ············case 31: s = "\"+\" expected"; break; |
| 612 | ············case 32: s = "\"-\" expected"; break; |
| 613 | ············case 33: s = "\"*\" expected"; break; |
| 614 | ············case 34: s = "\"/\" expected"; break; |
| 615 | ············case 35: s = "\"%\" expected"; break; |
| 616 | ············case 36: s = "\"~\" expected"; break; |
| 617 | ············case 37: s = "\",\" expected"; break; |
| 618 | ············case 38: s = "\"false\" expected"; break; |
| 619 | ············case 39: s = "??? expected"; break; |
| 620 | ············case 40: s = "invalid EqlExpr"; break; |
| 621 | ············case 41: s = "invalid EqlExpr"; break; |
| 622 | ············case 42: s = "invalid NumList"; break; |
| 623 | ············case 43: s = "invalid NumList"; break; |
| 624 | ············case 44: s = "invalid Primary"; break; |
| 625 | ············case 45: s = "invalid Literal"; break; |
| 626 | |
| 627 | ············default: s = "error " + n; break; |
| 628 | ········} |
| 629 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 630 | ········count++; |
| 631 | ····} |
| 632 | |
| 633 | ····public virtual void SemErr (int line, int col, string s) { |
| 634 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 635 | ········count++; |
| 636 | ····} |
| 637 | ···· |
| 638 | ····public virtual void SemErr (string s) { |
| 639 | ········errorStream.WriteLine(s); |
| 640 | ········count++; |
| 641 | ····} |
| 642 | ···· |
| 643 | ····public virtual void Warning (int line, int col, string s) { |
| 644 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 645 | ····} |
| 646 | ···· |
| 647 | ····public virtual void Warning(string s) { |
| 648 | ········errorStream.WriteLine(s); |
| 649 | ····} |
| 650 | } // Errors |
| 651 | |
| 652 | |
| 653 | public class FatalError: Exception { |
| 654 | ····public FatalError(string m): base(m) {} |
| 655 | } |
| 656 | } |
New Commit (397e4c7)
| 1 | using System.Collections.Generic; |
| 2 | using System.Text; |
| 3 | using System.Globalization; |
| 4 | using NDOql.Expressions; |
| 5 | |
| 6 | |
| 7 | |
| 8 | // |
| 9 | // This is generated code. Do not change it directly, change the Parser.frame file and rebuild the grammar. |
| 10 | // |
| 11 | |
| 12 | using System; |
| 13 | #pragma warning disable 3008, 1591 |
| 14 | |
| 15 | namespace NDOql { |
| 16 | |
| 17 | |
| 18 | |
| 19 | public class Parser { |
| 20 | ····public const int _EOF = 0; |
| 21 | ····public const int _ident = 1; |
| 22 | ····public const int _realCon = 2; |
| 23 | ····public const int _intCon = 3; |
| 24 | ····public const int _stringCon = 4; |
| 25 | ····public const int _AND = 5; |
| 26 | ····public const int _OR = 6; |
| 27 | ····public const int _NOT = 7; |
| 28 | ····public const int _LIKE = 8; |
| 29 | ····public const int _ESCAPE = 9; |
| 30 | ····public const int _BETWEEN = 10; |
| 31 | ····public const int _IS = 11; |
| 32 | ····public const int _NULL = 12; |
| 33 | ····public const int _TRUE = 13; |
| 34 | ····public const int _MOD = 14; |
| 35 | ····public const int _IN = 15; |
| 36 | ····public const int _parameter = 16; |
| 37 | ····public const int maxT = 39; |
| 38 | |
| 39 | ····const bool T = true; |
| 40 | ····const bool x = false; |
| 41 | ····const int minErrDist = 2; |
| 42 | ···· |
| 43 | ····public Scanner scanner; |
| 44 | ····public Errors··errors; |
| 45 | |
| 46 | ····public Token t;····// last recognized token |
| 47 | ····public Token la;·· // lookahead token |
| 48 | ····int errDist = minErrDist; |
| 49 | |
| 50 | OqlExpression rootExpression; |
| 51 | public OqlExpression RootExpression |
| 52 | { |
| 53 | ····get { return rootExpression; } |
| 54 | } |
| 55 | |
| 56 | |
| 57 | |
| 58 | /*------------------------------------------------------------------------* |
| 59 | *----- SCANNER DESCRIPTION ----------------------------------------------* |
| 60 | *------------------------------------------------------------------------*/ |
| 61 | |
| 62 | |
| 63 | |
| 64 | ····public Parser(Scanner scanner) { |
| 65 | ········this.scanner = scanner; |
| 66 | ········errors = new Errors(); |
| 67 | ····} |
| 68 | |
| 69 | ····void SynErr (int n) { |
| 70 | ········if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n); |
| 71 | ········errDist = 0; |
| 72 | ····} |
| 73 | |
| 74 | ····public void SemErr (string msg) { |
| 75 | ········if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg); |
| 76 | ········errDist = 0; |
| 77 | ····} |
| 78 | ···· |
| 79 | ····void Get () { |
| 80 | ········for (;;) { |
| 81 | ············t = la; |
| 82 | ············la = scanner.Scan(); |
| 83 | ············if (la.kind <= maxT) { ++errDist; break; } |
| 84 | |
| 85 | ············la = t; |
| 86 | ········} |
| 87 | ····} |
| 88 | ···· |
| 89 | ····void Expect (int n) { |
| 90 | ········if (la.kind==n) Get(); else { SynErr(n); } |
| 91 | ····} |
| 92 | ···· |
| 93 | ····bool StartOf (int s) { |
| 94 | ········return set[s, la.kind]; |
| 95 | ····} |
| 96 | ···· |
| 97 | ····void ExpectWeak (int n, int follow) { |
| 98 | ········if (la.kind == n) Get(); |
| 99 | ········else { |
| 100 | ············SynErr(n); |
| 101 | ············while (!StartOf(follow)) Get(); |
| 102 | ········} |
| 103 | ····} |
| 104 | |
| 105 | |
| 106 | ····bool WeakSeparator(int n, int syFol, int repFol) { |
| 107 | ········int kind = la.kind; |
| 108 | ········if (kind == n) {Get(); return true;} |
| 109 | ········else if (StartOf(repFol)) {return false;} |
| 110 | ········else { |
| 111 | ············SynErr(n); |
| 112 | ············while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) { |
| 113 | ················Get(); |
| 114 | ················kind = la.kind; |
| 115 | ············} |
| 116 | ············return StartOf(syFol); |
| 117 | ········} |
| 118 | ····} |
| 119 | |
| 120 | ····bool IsOidIdentifier(OqlExpression iexp) { |
| 121 | ········return ((string)iexp.Value).EndsWith("oid"); |
| 122 | ····} |
| 123 | |
| 124 | ···· |
| 125 | ····void NDOQL() { |
| 126 | ········RootExpr(out this.rootExpression); |
| 127 | ····} |
| 128 | |
| 129 | ····void RootExpr(out OqlExpression expression) { |
| 130 | ········OqlExpression child; |
| 131 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 132 | ········bool negated = false; |
| 133 | ········ |
| 134 | ········if (la.kind == 7) { |
| 135 | ············Get(); |
| 136 | ············negated = true; |
| 137 | ········} |
| 138 | ········OrExpr(out child); |
| 139 | ········if (negated) result.UnaryOp = "NOT"; |
| 140 | ········result.Add(child); |
| 141 | ········expression = result.Simplify(); |
| 142 | ········ |
| 143 | ····} |
| 144 | |
| 145 | ····void OrExpr(out OqlExpression expression) { |
| 146 | ········OqlExpression child; |
| 147 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 148 | ········ |
| 149 | ········AndExpr(out child); |
| 150 | ········result.Add(child); |
| 151 | ········while (la.kind == 6) { |
| 152 | ············Get(); |
| 153 | ············bool negated = false; |
| 154 | ············if (la.kind == 7) { |
| 155 | ················Get(); |
| 156 | ················negated = true; |
| 157 | ············} |
| 158 | ············AndExpr(out child); |
| 159 | ············if (negated) child.UnaryOp = "NOT"; result.Add(child, "OR"); |
| 160 | ········} |
| 161 | ········expression = result.Simplify(); |
| 162 | ····} |
| 163 | |
| 164 | ····void AndExpr(out OqlExpression expression) { |
| 165 | ········OqlExpression child; |
| 166 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 167 | ········ |
| 168 | ········EqlExpr(out child); |
| 169 | ········result.Add(child); |
| 170 | ········while (la.kind == 5) { |
| 171 | ············Get(); |
| 172 | ············bool negated = false; |
| 173 | ············if (la.kind == 7) { |
| 174 | ················Get(); |
| 175 | ················negated = true; |
| 176 | ············} |
| 177 | ············EqlExpr(out child); |
| 178 | ············if (negated) child.UnaryOp = "NOT"; result.Add(child, "AND"); |
| 179 | ········} |
| 180 | ········expression = result.Simplify(); |
| 181 | ····} |
| 182 | |
| 183 | ····void EqlExpr(out OqlExpression expression) { |
| 184 | ········OqlExpression child; |
| 185 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 186 | ········string newOp = null; |
| 187 | ········bool negated = false; |
| 188 | ········ |
| 189 | ········if (!(scanner.Peek().kind==_IN)) { |
| 190 | ············RelExpr(out child); |
| 191 | ············result.Add(child); |
| 192 | ············while (StartOf(1)) { |
| 193 | ················if (la.kind == 17) { |
| 194 | ····················Get(); |
| 195 | ····················newOp = "<>"; |
| 196 | ················} else if (la.kind == 18) { |
| 197 | ····················Get(); |
| 198 | ····················newOp = "<>"; |
| 199 | ················} else if (la.kind == 19) { |
| 200 | ····················Get(); |
| 201 | ····················newOp = "="; |
| 202 | ····················if (la.kind == 7) { |
| 203 | ························Get(); |
| 204 | ························negated = true; |
| 205 | ····················} |
| 206 | ················} else { |
| 207 | ····················Get(); |
| 208 | ····················newOp = "LIKE"; |
| 209 | ················} |
| 210 | ················RelExpr(out child); |
| 211 | ················if (negated) child.UnaryOp = "NOT"; result.Add(child, newOp); |
| 212 | ············} |
| 213 | ········} else if (la.kind == 1) { |
| 214 | ············Identifier(out child); |
| 215 | ············result.Add(child); |
| 216 | ············Expect(15); |
| 217 | ············Expect(20); |
| 218 | ············if (la.kind == 2 || la.kind == 3) { |
| 219 | ················NumList(out child); |
| 220 | ················child.HasBrackets = true; result.Add(child, "IN"); |
| 221 | ············} else if (la.kind == 4) { |
| 222 | ················StringList(out child); |
| 223 | ················child.HasBrackets = true; result.Add(child, "IN"); |
| 224 | ············} else SynErr(40); |
| 225 | ············Expect(21); |
| 226 | ········} else SynErr(41); |
| 227 | ········expression = result.Simplify(); |
| 228 | ····} |
| 229 | |
| 230 | ····void RelExpr(out OqlExpression expression) { |
| 231 | ········OqlExpression child; |
| 232 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 233 | ········string newOp = null; |
| 234 | ········bool negated = false; |
| 235 | ········ |
| 236 | ········BitOrExpr(out child); |
| 237 | ········result.Add(child); |
| 238 | ········if (StartOf(2)) { |
| 239 | ············if (StartOf(3)) { |
| 240 | ················switch (la.kind) { |
| 241 | ················case 22: { |
| 242 | ····················Get(); |
| 243 | ····················newOp = "<"; |
| 244 | ····················break; |
| 245 | ················} |
| 246 | ················case 23: { |
| 247 | ····················Get(); |
| 248 | ····················newOp = ">"; |
| 249 | ····················break; |
| 250 | ················} |
| 251 | ················case 24: { |
| 252 | ····················Get(); |
| 253 | ····················newOp = "<="; |
| 254 | ····················break; |
| 255 | ················} |
| 256 | ················case 25: { |
| 257 | ····················Get(); |
| 258 | ····················newOp = ">="; |
| 259 | ····················break; |
| 260 | ················} |
| 261 | ················case 26: { |
| 262 | ····················Get(); |
| 263 | ····················newOp = ">="; |
| 264 | ····················break; |
| 265 | ················} |
| 266 | ················case 27: { |
| 267 | ····················Get(); |
| 268 | ····················newOp = "<="; |
| 269 | ····················break; |
| 270 | ················} |
| 271 | ················} |
| 272 | ················BitOrExpr(out child); |
| 273 | ················result.Add(child, newOp); |
| 274 | ············} else if (la.kind == 11) { |
| 275 | ················Get(); |
| 276 | ················if (la.kind == 7) { |
| 277 | ····················Get(); |
| 278 | ····················negated = true; |
| 279 | ················} |
| 280 | ················Expect(12); |
| 281 | ················result.Add(new NamedConstantExpression("NULL", negated, t.line, t.col), "IS"); |
| 282 | ············} else { |
| 283 | ················if (la.kind == 7) { |
| 284 | ····················Get(); |
| 285 | ····················negated = true; |
| 286 | ················} |
| 287 | ················Expect(10); |
| 288 | ················BitOrExpr(out child); |
| 289 | ················result.Add(child, "BETWEEN"); |
| 290 | ················Expect(5); |
| 291 | ················BitOrExpr(out child); |
| 292 | ················result.Add(child, "BETWEEN"); |
| 293 | ············} |
| 294 | ········} |
| 295 | ········expression = result.Simplify(); |
| 296 | ····} |
| 297 | |
| 298 | ····void Identifier(out OqlExpression expression) { |
| 299 | ········OqlExpression result = null; |
| 300 | ········ |
| 301 | ········Expect(1); |
| 302 | ········result = new IdentifierExpression(t.val, t.line, t.col); |
| 303 | ········expression = result.Simplify(); |
| 304 | ····} |
| 305 | |
| 306 | ····void NumList(out OqlExpression expression) { |
| 307 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 308 | ········ |
| 309 | ········if (la.kind == 2) { |
| 310 | ············Get(); |
| 311 | ············result.Add(new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col)); |
| 312 | ········} else if (la.kind == 3) { |
| 313 | ············Get(); |
| 314 | ············result.Add(new NumberExpression(int.Parse(t.val), t.line, t.col)); |
| 315 | ········} else SynErr(42); |
| 316 | ········while (la.kind == 37) { |
| 317 | ············Get(); |
| 318 | ············if (la.kind == 2) { |
| 319 | ················Get(); |
| 320 | ················result.Add(new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col), ","); |
| 321 | ············} else if (la.kind == 3) { |
| 322 | ················Get(); |
| 323 | ················result.Add(new NumberExpression(int.Parse(t.val), t.line, t.col), ","); |
| 324 | ············} else SynErr(43); |
| 325 | ········} |
| 326 | expression = result; |
| 327 | ····} |
| 328 | |
| 329 | ····void StringList(out OqlExpression expression) { |
| 330 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 331 | ········ |
| 332 | ········Expect(4); |
| 333 | ········result.Add(new StringLiteralExpression(t.val, t.line, t.col)); |
| 334 | ········while (la.kind == 37) { |
| 335 | ············Get(); |
| 336 | ············Expect(4); |
| 337 | ············result.Add(new StringLiteralExpression(t.val, t.line, t.col), ","); |
| 338 | ········} |
| 339 | expression = result; |
| 340 | ····} |
| 341 | |
| 342 | ····void BitOrExpr(out OqlExpression expression) { |
| 343 | ········OqlExpression child; |
| 344 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 345 | ········ |
| 346 | ········BitXorExpr(out child); |
| 347 | ········result.Add(child); |
| 348 | ········while (la.kind == 28) { |
| 349 | ············Get(); |
| 350 | ············BitXorExpr(out child); |
| 351 | ············result.Add(child, "|"); |
| 352 | ········} |
| 353 | ········expression = result.Simplify(); |
| 354 | ····} |
| 355 | |
| 356 | ····void BitXorExpr(out OqlExpression expression) { |
| 357 | ········OqlExpression child; |
| 358 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 359 | ········ |
| 360 | ········BitAndExpr(out child); |
| 361 | ········result.Add(child); |
| 362 | ········while (la.kind == 29) { |
| 363 | ············Get(); |
| 364 | ············BitAndExpr(out child); |
| 365 | ············result.Add(child, "^"); |
| 366 | ········} |
| 367 | ········expression = result.Simplify(); |
| 368 | ····} |
| 369 | |
| 370 | ····void BitAndExpr(out OqlExpression expression) { |
| 371 | ········OqlExpression child; |
| 372 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 373 | ········ |
| 374 | ········AddExpr(out child); |
| 375 | ········result.Add(child); |
| 376 | ········while (la.kind == 30) { |
| 377 | ············Get(); |
| 378 | ············AddExpr(out child); |
| 379 | ············result.Add(child, "&"); |
| 380 | ········} |
| 381 | ········expression = result.Simplify(); |
| 382 | ····} |
| 383 | |
| 384 | ····void AddExpr(out OqlExpression expression) { |
| 385 | ········OqlExpression child; |
| 386 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 387 | ········string newOp = null; |
| 388 | ········ |
| 389 | ········MulExpr(out child); |
| 390 | ········result.Add(child); |
| 391 | ········while (la.kind == 31 || la.kind == 32) { |
| 392 | ············if (la.kind == 31) { |
| 393 | ················Get(); |
| 394 | ················newOp = "+"; |
| 395 | ············} else { |
| 396 | ················Get(); |
| 397 | ················newOp = "-"; |
| 398 | ············} |
| 399 | ············MulExpr(out child); |
| 400 | ············result.Add(child, newOp); |
| 401 | ········} |
| 402 | ········expression = result.Simplify(); |
| 403 | ····} |
| 404 | |
| 405 | ····void MulExpr(out OqlExpression expression) { |
| 406 | ········OqlExpression child; |
| 407 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 408 | ········string newOp = null; |
| 409 | ········ |
| 410 | ········Unary(out child); |
| 411 | ········result.Add(child); |
| 412 | ········while (StartOf(4)) { |
| 413 | ············if (la.kind == 33) { |
| 414 | ················Get(); |
| 415 | ················newOp = "*"; |
| 416 | ············} else if (la.kind == 34) { |
| 417 | ················Get(); |
| 418 | ················newOp = "/"; |
| 419 | ············} else if (la.kind == 35) { |
| 420 | ················Get(); |
| 421 | ················newOp = "%"; |
| 422 | ············} else { |
| 423 | ················Get(); |
| 424 | ················newOp = "MOD"; |
| 425 | ············} |
| 426 | ············Unary(out child); |
| 427 | ············result.Add(child, newOp); |
| 428 | ········} |
| 429 | ········expression = result.Simplify(); |
| 430 | ····} |
| 431 | |
| 432 | ····void Unary(out OqlExpression expression) { |
| 433 | ········OqlExpression child; |
| 434 | ········OqlExpression result = new OqlExpression(la.line, la.col); |
| 435 | ········string newOp = null; |
| 436 | ········ |
| 437 | ········if (la.kind == 31 || la.kind == 32 || la.kind == 36) { |
| 438 | ············if (la.kind == 31) { |
| 439 | ················Get(); |
| 440 | ················newOp = "+"; |
| 441 | ············} else if (la.kind == 32) { |
| 442 | ················Get(); |
| 443 | ················newOp = "-"; |
| 444 | ············} else { |
| 445 | ················Get(); |
| 446 | ················newOp = "~"; |
| 447 | ············} |
| 448 | ········} |
| 449 | ········Primary(out child); |
| 450 | ········result.Add(child); child.UnaryOp = newOp; |
| 451 | ········expression = result.Simplify(); |
| 452 | ····} |
| 453 | |
| 454 | ····void Primary(out OqlExpression expression) { |
| 455 | ········OqlExpression result = null; |
| 456 | ········OqlExpression child; |
| 457 | ········ |
| 458 | ········if (la.kind == 1) { |
| 459 | ············Get(); |
| 460 | ············result = new IdentifierExpression(t.val, t.line, t.col); |
| 461 | ············if (la.kind == 20) { |
| 462 | ················if (IsOidIdentifier(result)) { |
| 463 | ····················Expect(20); |
| 464 | ····················Expect(3); |
| 465 | ····················result.UnaryOp=""; |
| 466 | ····················result.Add(new IndexExpression(int.Parse(t.val), t.line, t.col)); |
| 467 | ···················· |
| 468 | ····················Expect(21); |
| 469 | ················} else { |
| 470 | ····················Get(); |
| 471 | ····················ParameterList(out child); |
| 472 | ····················result = new FunctionExpression(result.Value, t.line, t.col); |
| 473 | ····················result.UnaryOp="";························ |
| 474 | ····················result.Add(child); |
| 475 | ···················· |
| 476 | ····················Expect(21); |
| 477 | ················} |
| 478 | ············} |
| 479 | ········} else if (StartOf(5)) { |
| 480 | ············Literal(out result); |
| 481 | ········} else if (la.kind == 16) { |
| 482 | ············Get(); |
| 483 | ············result = new ParameterExpression(t.val, t.line, t.col); |
| 484 | ········} else if (la.kind == 20) { |
| 485 | ············Get(); |
| 486 | ············RootExpr(out result); |
| 487 | ············result.HasBrackets = true; |
| 488 | ············Expect(21); |
| 489 | ········} else SynErr(44); |
| 490 | ········expression = result.Simplify(); |
| 491 | ····} |
| 492 | |
| 493 | ····void ParameterList(out OqlExpression expression) { |
| 494 | ········OqlExpression result = new ParameterListExpression(la.line, la.col); |
| 495 | ········OqlExpression child; |
| 496 | ········ |
| 497 | ········if (StartOf(6)) { |
| 498 | ············Primary(out child); |
| 499 | ············result.Add(child); |
| 500 | ············while (la.kind == 37) { |
| 501 | ················Get(); |
| 502 | ················Primary(out child); |
| 503 | ················result.Add(child, ","); |
| 504 | ············} |
| 505 | ········} |
| 506 | ········expression = result; /* Do not simplify here, because otherwise the brackets are missing */ |
| 507 | ····} |
| 508 | |
| 509 | ····void Literal(out OqlExpression expression) { |
| 510 | ········OqlExpression result = null; |
| 511 | ········ |
| 512 | ········switch (la.kind) { |
| 513 | ········case 2: { |
| 514 | ············Get(); |
| 515 | ············result = new NumberExpression(double.Parse(t.val, CultureInfo.InvariantCulture ), t.line, t.col); |
| 516 | ············break; |
| 517 | ········} |
| 518 | ········case 3: { |
| 519 | ············Get(); |
| 520 | ············result = new NumberExpression(int.Parse(t.val), t.line, t.col); |
| 521 | ············break; |
| 522 | ········} |
| 523 | ········case 4: { |
| 524 | ············Get(); |
| 525 | ············result = new StringLiteralExpression(t.val, t.line, t.col); |
| 526 | ············break; |
| 527 | ········} |
| 528 | ········case 13: { |
| 529 | ············Get(); |
| 530 | ············result = new NamedConstantExpression("TRUE", t.line, t.col); |
| 531 | ············break; |
| 532 | ········} |
| 533 | ········case 38: { |
| 534 | ············Get(); |
| 535 | ············result = new NamedConstantExpression("FALSE", t.line, t.col); |
| 536 | ············break; |
| 537 | ········} |
| 538 | ········case 12: { |
| 539 | ············Get(); |
| 540 | ············result = new NamedConstantExpression("NULL", t.line, t.col); |
| 541 | ············break; |
| 542 | ········} |
| 543 | ········default: SynErr(45); break; |
| 544 | ········} |
| 545 | ········expression = result.Simplify(); |
| 546 | ····} |
| 547 | |
| 548 | |
| 549 | |
| 550 | ····public void Parse() { |
| 551 | ········la = new Token(); |
| 552 | ········la.val = "";········ |
| 553 | ········Get(); |
| 554 | ········NDOQL(); |
| 555 | ········Expect(0); |
| 556 | |
| 557 | ····} |
| 558 | ···· |
| 559 | ····static readonly bool[,] set = { |
| 560 | ········{T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x}, |
| 561 | ········{x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x}, |
| 562 | ········{x,x,x,x, x,x,x,T, x,x,T,T, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x}, |
| 563 | ········{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x}, |
| 564 | ········{x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x}, |
| 565 | ········{x,x,T,T, T,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x}, |
| 566 | ········{x,T,T,T, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x} |
| 567 | |
| 568 | ····}; |
| 569 | } // end Parser |
| 570 | |
| 571 | |
| 572 | public class Errors { |
| 573 | ····public int count = 0;····································// number of errors detected |
| 574 | ····public System.IO.TextWriter errorStream = Console.Out;·· // error messages go to this stream |
| 575 | ····public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text |
| 576 | |
| 577 | ····public virtual void SynErr (int line, int col, int n) { |
| 578 | ········string s; |
| 579 | ········switch (n) { |
| 580 | ············case 0: s = "EOF expected"; break; |
| 581 | ············case 1: s = "ident expected"; break; |
| 582 | ············case 2: s = "realCon expected"; break; |
| 583 | ············case 3: s = "intCon expected"; break; |
| 584 | ············case 4: s = "stringCon expected"; break; |
| 585 | ············case 5: s = "AND expected"; break; |
| 586 | ············case 6: s = "OR expected"; break; |
| 587 | ············case 7: s = "NOT expected"; break; |
| 588 | ············case 8: s = "LIKE expected"; break; |
| 589 | ············case 9: s = "ESCAPE expected"; break; |
| 590 | ············case 10: s = "BETWEEN expected"; break; |
| 591 | ············case 11: s = "IS expected"; break; |
| 592 | ············case 12: s = "NULL expected"; break; |
| 593 | ············case 13: s = "TRUE expected"; break; |
| 594 | ············case 14: s = "MOD expected"; break; |
| 595 | ············case 15: s = "IN expected"; break; |
| 596 | ············case 16: s = "parameter expected"; break; |
| 597 | ············case 17: s = "\"!=\" expected"; break; |
| 598 | ············case 18: s = "\"<>\" expected"; break; |
| 599 | ············case 19: s = "\"=\" expected"; break; |
| 600 | ············case 20: s = "\"(\" expected"; break; |
| 601 | ············case 21: s = "\")\" expected"; break; |
| 602 | ············case 22: s = "\"<\" expected"; break; |
| 603 | ············case 23: s = "\">\" expected"; break; |
| 604 | ············case 24: s = "\"<=\" expected"; break; |
| 605 | ············case 25: s = "\">=\" expected"; break; |
| 606 | ············case 26: s = "\"!<\" expected"; break; |
| 607 | ············case 27: s = "\"!>\" expected"; break; |
| 608 | ············case 28: s = "\"|\" expected"; break; |
| 609 | ············case 29: s = "\"^\" expected"; break; |
| 610 | ············case 30: s = "\"&\" expected"; break; |
| 611 | ············case 31: s = "\"+\" expected"; break; |
| 612 | ············case 32: s = "\"-\" expected"; break; |
| 613 | ············case 33: s = "\"*\" expected"; break; |
| 614 | ············case 34: s = "\"/\" expected"; break; |
| 615 | ············case 35: s = "\"%\" expected"; break; |
| 616 | ············case 36: s = "\"~\" expected"; break; |
| 617 | ············case 37: s = "\",\" expected"; break; |
| 618 | ············case 38: s = "\"false\" expected"; break; |
| 619 | ············case 39: s = "??? expected"; break; |
| 620 | ············case 40: s = "invalid EqlExpr"; break; |
| 621 | ············case 41: s = "invalid EqlExpr"; break; |
| 622 | ············case 42: s = "invalid NumList"; break; |
| 623 | ············case 43: s = "invalid NumList"; break; |
| 624 | ············case 44: s = "invalid Primary"; break; |
| 625 | ············case 45: s = "invalid Literal"; break; |
| 626 | |
| 627 | ············default: s = "error " + n; break; |
| 628 | ········} |
| 629 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 630 | ········count++; |
| 631 | ····} |
| 632 | |
| 633 | ····public virtual void SemErr (int line, int col, string s) { |
| 634 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 635 | ········count++; |
| 636 | ····} |
| 637 | ···· |
| 638 | ····public virtual void SemErr (string s) { |
| 639 | ········errorStream.WriteLine(s); |
| 640 | ········count++; |
| 641 | ····} |
| 642 | ···· |
| 643 | ····public virtual void Warning (int line, int col, string s) { |
| 644 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 645 | ····} |
| 646 | ···· |
| 647 | ····public virtual void Warning(string s) { |
| 648 | ········errorStream.WriteLine(s); |
| 649 | ····} |
| 650 | } // Errors |
| 651 | |
| 652 | |
| 653 | public class FatalError: Exception { |
| 654 | ····public FatalError(string m): base(m) {} |
| 655 | } |
| 656 | } |