vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1 | options { |
| 2 | |
| 3 | |
| 4 | STATIC = false; |
| 5 | |
| 6 | } |
| 7 | |
| 8 | |
| 9 | PARSER_BEGIN(AQLParser) |
| 10 | |
| 11 | package edu.uci.ics.asterix.aql.parser; |
| 12 | |
| 13 | import java.io.*; |
| 14 | import java.util.List; |
| 15 | import java.util.ArrayList; |
| 16 | import java.util.Stack; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import java.util.HashMap; |
| 20 | import edu.uci.ics.asterix.aql.literal.FloatLiteral; |
| 21 | import edu.uci.ics.asterix.aql.literal.DoubleLiteral; |
| 22 | import edu.uci.ics.asterix.aql.literal.FalseLiteral; |
| 23 | import edu.uci.ics.asterix.aql.base.ILiteral; |
| 24 | import edu.uci.ics.asterix.aql.literal.IntegerLiteral; |
| 25 | import edu.uci.ics.asterix.aql.literal.NullLiteral; |
| 26 | import edu.uci.ics.asterix.aql.literal.StringLiteral; |
| 27 | import edu.uci.ics.asterix.aql.literal.TrueLiteral; |
| 28 | |
| 29 | import edu.uci.ics.asterix.aql.base.*; |
| 30 | import edu.uci.ics.asterix.aql.expression.*; |
| 31 | import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType; |
| 32 | import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType; |
| 33 | import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor; |
| 34 | import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign; |
| 35 | import edu.uci.ics.asterix.aql.base.Statement.Kind; |
| 36 | import edu.uci.ics.asterix.aql.context.Scope; |
| 37 | import edu.uci.ics.asterix.aql.context.RootScopeFactory; |
| 38 | import edu.uci.ics.asterix.common.annotations.*; |
| 39 | import edu.uci.ics.asterix.common.exceptions.AsterixException; |
| 40 | |
| 41 | |
| 42 | public class AQLParser extends ScopeChecker { |
| 43 | |
| 44 | /* |
| 45 | private void printHints(Token t) { |
| 46 | //System.err.println("token="+t.image+"\t special="+t.specialToken); |
| 47 | if (t.specialToken == null) return; |
| 48 | Token tmp_t = t.specialToken; |
| 49 | while (tmp_t.specialToken != null) tmp_t = tmp_t.specialToken; |
| 50 | while (tmp_t != null) { |
| 51 | System.out.println(tmp_t.image); |
| 52 | tmp_t = tmp_t.next; |
| 53 | } |
| 54 | } |
| 55 | */ |
| 56 | |
| 57 | // optimizer hints |
| 58 | private static final String HASH_GROUP_BY_HINT = "hash"; |
| 59 | private static final String BROADCAST_JOIN_HINT = "bcast"; |
| 60 | private static final String INMEMORY_HINT = "inmem"; |
| 61 | private static final String VAL_FILE_HINT = "val-files"; |
| 62 | private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx"; |
| 63 | private static final String INTERVAL_HINT = "interval"; |
| 64 | private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files"; |
| 65 | private static final String INSERT_RAND_INT_HINT = "insert-rand-int"; |
| 66 | private static final String LIST_VAL_FILE_HINT = "list-val-file"; |
| 67 | private static final String LIST_HINT = "list"; |
| 68 | private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years"; |
| 69 | private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years"; |
| 70 | private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours"; |
| 71 | private static final String AUTO_HINT = "auto"; |
| 72 | |
| 73 | private static final String GEN_FIELDS_HINT = "gen-fields"; |
| 74 | |
| 75 | // data generator hints |
| 76 | private static final String DGEN_HINT = "dgen"; |
| 77 | |
| 78 | private static String getHint(Token t) { |
| 79 | if (t.specialToken == null) { |
| 80 | return null; |
| 81 | } |
| 82 | String s = t.specialToken.image; |
| 83 | int n = s.length(); |
| 84 | if (n < 2) { |
| 85 | return null; |
| 86 | } |
| 87 | return s.substring(1).trim(); |
| 88 | } |
| 89 | |
| 90 | public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException { |
| 91 | File file = new File(args[0]); |
| 92 | Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); |
| 93 | AQLParser parser = new AQLParser(fis); |
| 94 | Statement st = parser.Statement(); |
| 95 | st.accept(new AQLPrintVisitor(), 0); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | } |
| 100 | |
| 101 | PARSER_END(AQLParser) |
| 102 | |
| 103 | |
| 104 | Statement Statement() throws ParseException: |
| 105 | { |
| 106 | Query query = null; |
| 107 | scopeStack.push(RootScopeFactory.createRootScope(this)); |
| 108 | List<Statement> decls = new ArrayList<Statement>(); |
| 109 | } |
| 110 | { |
| 111 | ( |
| 112 | ( |
| 113 | ( |
| 114 | "use" |
| 115 | { |
| 116 | decls.add(DataverseDeclaration()); |
| 117 | } |
| 118 | | "declare" "function" { |
| 119 | decls.add(FunctionDeclaration()); |
| 120 | } |
| 121 | | "create" ( |
| 122 | { |
| 123 | String hint = getHint(token); |
| 124 | boolean dgen = false; |
| 125 | if (hint != null && hint.startsWith(DGEN_HINT)) { |
| 126 | dgen = true; |
| 127 | } |
| 128 | } |
| 129 | "type" |
| 130 | { |
| 131 | decls.add(TypeDeclaration(dgen, hint)); |
| 132 | } |
| 133 | | "nodegroup" |
| 134 | { |
| 135 | decls.add(NodegroupDeclaration()); |
| 136 | } |
| 137 | | "external" <DATASET> |
| 138 | { |
| 139 | decls.add(DatasetDeclaration(DatasetType.EXTERNAL)); |
| 140 | } |
| 141 | | "feed" <DATASET> |
| 142 | { |
| 143 | decls.add(DatasetDeclaration(DatasetType.FEED)); |
| 144 | } |
| 145 | | <DATASET> |
| 146 | { |
| 147 | decls.add(DatasetDeclaration(DatasetType.INTERNAL)); |
| 148 | } |
| 149 | | "index" |
| 150 | { |
| 151 | decls.add(CreateIndexStatement()); |
| 152 | } |
| 153 | | "dataverse" |
| 154 | { |
| 155 | decls.add(CreateDataverseStatement()); |
| 156 | } |
| 157 | | "function" |
| 158 | { |
| 159 | decls.add(FunctionCreation()); |
| 160 | } |
| 161 | ) |
| 162 | | "load" { |
| 163 | decls.add(LoadStatement()); |
| 164 | } |
| 165 | |
| 166 | | "drop" |
| 167 | ( |
| 168 | <DATASET> |
| 169 | { |
| 170 | decls.add(DropStatement()); |
| 171 | } |
| 172 | | "index" |
| 173 | { |
| 174 | decls.add(IndexDropStatement()); |
| 175 | } |
| 176 | | "nodegroup" |
| 177 | { |
| 178 | decls.add(NodeGroupDropStatement()); |
| 179 | } |
| 180 | | "type" |
| 181 | { |
| 182 | decls.add(TypeDropStatement()); |
| 183 | } |
| 184 | | "dataverse" |
| 185 | { |
| 186 | decls.add(DataverseDropStatement()); |
| 187 | } |
| 188 | ) |
| 189 | | "write" { |
| 190 | decls.add(WriteStatement()); |
| 191 | } |
| 192 | | "set" { |
| 193 | decls.add(SetStatement()); |
| 194 | } |
| 195 | | "insert" { |
| 196 | decls.add(InsertStatement()); |
| 197 | } |
| 198 | | "delete" { |
| 199 | decls.add(DeleteStatement()); |
| 200 | } |
| 201 | | "update" { |
| 202 | decls.add(UpdateStatement()); |
| 203 | } |
| 204 | | "begin" "feed" <IDENTIFIER> { |
| 205 | Identifier datasetName = new Identifier(token.image); |
| 206 | decls.add(new BeginFeedStatement(datasetName, getVarCounter())); |
| 207 | } ";" |
| 208 | | "suspend" "feed" <IDENTIFIER> { |
| 209 | datasetName = new Identifier(token.image); |
| 210 | decls.add(new ControlFeedStatement(ControlFeedStatement.OperationType.SUSPEND, datasetName)); |
| 211 | } ";" |
| 212 | | "resume" "feed" <IDENTIFIER> { |
| 213 | datasetName = new Identifier(token.image); |
| 214 | decls.add(new ControlFeedStatement(ControlFeedStatement.OperationType.RESUME, datasetName)); |
| 215 | } ";" |
| 216 | | "end" "feed" <IDENTIFIER> { |
| 217 | datasetName = new Identifier(token.image); |
| 218 | decls.add(new ControlFeedStatement(ControlFeedStatement.OperationType.END, datasetName)); |
| 219 | } ";" |
| 220 | | "alter" "feed" <IDENTIFIER> { |
| 221 | datasetName = new Identifier(token.image); |
| 222 | decls.add(AlterFeedDeclaration(datasetName)); |
| 223 | } |
| 224 | |
| 225 | )* |
| 226 | (query = Query())? |
| 227 | ) |
| 228 | |
| 229 | <EOF> |
| 230 | ) |
| 231 | { |
| 232 | if (query == null) { |
| 233 | query = new Query(true); |
| 234 | } |
| 235 | query.setPrologDeclList(decls); |
| 236 | |
| 237 | return query; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | InsertStatement InsertStatement() throws ParseException: |
| 242 | { |
| 243 | Identifier datasetName; |
| 244 | Query query; |
| 245 | } |
| 246 | { |
| 247 | "into" <DATASET> <IDENTIFIER> { datasetName = new Identifier(token.image); } |
| 248 | <LEFTPAREN> query = Query() <RIGHTPAREN> ";" |
| 249 | {return new InsertStatement(datasetName, query, getVarCounter());} |
| 250 | } |
| 251 | |
| 252 | DeleteStatement DeleteStatement() throws ParseException: |
| 253 | { |
| 254 | VariableExpr var = null; |
| 255 | Identifier datasetName = null; |
| 256 | Expression condition = null; |
| 257 | Clause dieClause = null; |
| 258 | } |
| 259 | { |
| 260 | var = Variable() { getCurrentScope().addNewVarSymbolToScope(var.getVar()); } |
| 261 | "from" <DATASET> <IDENTIFIER> { datasetName = new Identifier(token.image); } |
| 262 | ("where" condition = Expression())? (dieClause = DieClause())? ";" |
| 263 | {return new DeleteStatement(var, datasetName, condition, dieClause, getVarCounter()); } |
| 264 | } |
| 265 | |
| 266 | UpdateStatement UpdateStatement() throws ParseException: |
| 267 | { |
| 268 | VariableExpr vars; |
| 269 | Expression target; |
| 270 | Expression condition; |
| 271 | UpdateClause uc; |
| 272 | List<UpdateClause> ucs = new ArrayList<UpdateClause>(); |
| 273 | } |
| 274 | { |
| 275 | vars = Variable() "in" target = Expression() |
| 276 | "where" condition = Expression() |
| 277 | <LEFTPAREN> (uc=UpdateClause() {ucs.add(uc); } ("," uc=UpdateClause() {ucs.add(uc); } )*) <RIGHTPAREN> ";" |
| 278 | {return new UpdateStatement(vars, target, condition, ucs);} |
| 279 | } |
| 280 | |
| 281 | |
| 282 | |
| 283 | UpdateClause UpdateClause() throws ParseException: |
| 284 | { |
| 285 | Expression target = null; |
| 286 | Expression value = null ; |
| 287 | InsertStatement is = null; |
| 288 | DeleteStatement ds = null; |
| 289 | UpdateStatement us = null; |
| 290 | Expression condition = null; |
| 291 | UpdateClause ifbranch = null; |
| 292 | UpdateClause elsebranch = null; |
| 293 | } |
| 294 | { |
| 295 | "set" target = Expression() ":=" value = Expression() |
| 296 | | "insert" is = InsertStatement() |
| 297 | | "delete" ds = DeleteStatement() |
| 298 | | "update" us = UpdateStatement() |
| 299 | | "if" <LEFTPAREN> condition = Expression() <RIGHTPAREN> "then" ifbranch = UpdateClause() [LOOKAHEAD(1) "else" elsebranch = UpdateClause()] |
| 300 | {return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);} |
| 301 | } |
| 302 | |
| 303 | |
| 304 | Statement SetStatement() throws ParseException: |
| 305 | { |
| 306 | String pn = null; |
| 307 | Statement stmt = null; |
| 308 | } |
| 309 | { |
| 310 | <IDENTIFIER> { pn = token.image; } |
| 311 | <STRING_LITERAL> |
| 312 | { String pv = removeQuotesAndEscapes(token.image); } |
| 313 | ";" |
| 314 | { |
| 315 | return new SetStatement(pn, pv); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | Statement WriteStatement() throws ParseException: |
| 320 | { |
| 321 | Identifier nodeName = null; |
| 322 | String fileName = null; |
| 323 | Identifier datasetName = null; |
| 324 | Statement stmt = null; |
| 325 | Query query; |
| 326 | String writerClass = null; |
| 327 | } |
| 328 | { |
| 329 | (( "output" "to" |
| 330 | <IDENTIFIER> { nodeName = new Identifier(token.image); } |
| 331 | ":" <STRING_LITERAL> { fileName = removeQuotesAndEscapes(token.image); } |
| 332 | ( "using" <STRING_LITERAL> { writerClass = removeQuotesAndEscapes(token.image); } )? |
| 333 | { |
| 334 | stmt = new WriteStatement(nodeName, fileName, writerClass); |
| 335 | } ) |
| 336 | | |
| 337 | ( "into" |
| 338 | <DATASET> <IDENTIFIER> { datasetName = new Identifier(token.image); } |
| 339 | <LEFTPAREN> query = Query() <RIGHTPAREN> |
| 340 | { |
| 341 | stmt = new WriteFromQueryResultStatement(datasetName, query, getVarCounter()); |
| 342 | } )) |
| 343 | |
| 344 | ";" |
| 345 | { |
| 346 | return stmt; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | CreateIndexStatement CreateIndexStatement() throws ParseException: |
| 351 | { |
| 352 | CreateIndexStatement cis = new CreateIndexStatement(); |
| 353 | } |
| 354 | { |
| 355 | <IDENTIFIER> { cis.setIndexName(new Identifier(token.image)); } |
| 356 | ( |
| 357 | "if not exists" |
| 358 | { |
| 359 | cis.setIfNotExists(true); |
| 360 | } |
| 361 | )? |
| 362 | "on" |
| 363 | <IDENTIFIER> { cis.setDatasetName(new Identifier(token.image)); } |
| 364 | <LEFTPAREN> |
| 365 | ( <IDENTIFIER> { cis.addFieldExpr(token.image); } ) |
| 366 | ("," <IDENTIFIER> { cis.addFieldExpr(token.image); })* |
| 367 | <RIGHTPAREN> |
| 368 | ("type" |
| 369 | ("btree" { cis.setIndexType(IndexType.BTREE); } |
| 370 | | "keyword" { cis.setIndexType(IndexType.KEYWORD); } |
| 371 | | "qgram" { cis.setIndexType(IndexType.QGRAM); } |
| 372 | | "rtree" { cis.setIndexType(IndexType.RTREE); } |
| 373 | ) |
| 374 | ";" |
| 375 | | ";" |
| 376 | ) |
| 377 | { |
| 378 | return cis; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | DataverseDecl DataverseDeclaration() throws ParseException: |
| 383 | { |
| 384 | Identifier dvName = null; |
| 385 | } |
| 386 | { |
| 387 | "dataverse" <IDENTIFIER> { dvName = new Identifier(token.image); } |
| 388 | ";" |
| 389 | { |
| 390 | return new DataverseDecl(dvName); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | DropStatement DropStatement() throws ParseException : |
| 395 | { |
| 396 | Identifier datasetName = null; |
| 397 | boolean ifExists = false; |
| 398 | } |
| 399 | { |
| 400 | < IDENTIFIER > |
| 401 | { |
| 402 | datasetName = new Identifier(token.image); |
| 403 | } |
| 404 | ( |
| 405 | "if exists" |
| 406 | { |
| 407 | ifExists = true; |
| 408 | } |
| 409 | )? ";" |
| 410 | { |
| 411 | return new DropStatement(datasetName, ifExists); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | IndexDropStatement IndexDropStatement() throws ParseException : |
| 416 | { |
| 417 | Identifier datasetName = null; |
| 418 | Identifier indexName = null; |
| 419 | boolean ifExists = false; |
| 420 | } |
| 421 | { |
| 422 | < IDENTIFIER > |
| 423 | { |
| 424 | datasetName = new Identifier(token.image); |
| 425 | } |
| 426 | "." < IDENTIFIER > |
| 427 | { |
| 428 | indexName = new Identifier(token.image); |
| 429 | } |
| 430 | ( |
| 431 | "if exists" |
| 432 | { |
| 433 | ifExists = true; |
| 434 | } |
| 435 | )? ";" |
| 436 | { |
| 437 | return new IndexDropStatement(datasetName, indexName, ifExists); |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | NodeGroupDropStatement NodeGroupDropStatement() throws ParseException : |
| 442 | { |
| 443 | Identifier groupName = null; |
| 444 | boolean ifExists = false; |
| 445 | } |
| 446 | { |
| 447 | < IDENTIFIER > |
| 448 | { |
| 449 | groupName = new Identifier(token.image); |
| 450 | } |
| 451 | ( |
| 452 | "if exists" |
| 453 | { |
| 454 | ifExists = true; |
| 455 | } |
| 456 | )? ";" |
| 457 | { |
| 458 | return new NodeGroupDropStatement(groupName, ifExists); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | TypeDropStatement TypeDropStatement() throws ParseException : |
| 463 | { |
| 464 | Identifier typeName = null; |
| 465 | boolean ifExists = false; |
| 466 | } |
| 467 | { |
| 468 | < IDENTIFIER > |
| 469 | { |
| 470 | typeName = new Identifier(token.image); |
| 471 | } |
| 472 | ( |
| 473 | "if exists" |
| 474 | { |
| 475 | ifExists = true; |
| 476 | } |
| 477 | )? ";" |
| 478 | { |
| 479 | return new TypeDropStatement(typeName, ifExists); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | DataverseDropStatement DataverseDropStatement() throws ParseException : |
| 484 | { |
| 485 | Identifier dataverseName = null; |
| 486 | boolean ifExists = false; |
| 487 | } |
| 488 | { |
| 489 | < IDENTIFIER > |
| 490 | { |
| 491 | dataverseName = new Identifier(token.image); |
| 492 | } |
| 493 | ( |
| 494 | "if exists" |
| 495 | { |
| 496 | ifExists = true; |
| 497 | } |
| 498 | )? ";" |
| 499 | { |
| 500 | return new DataverseDropStatement(dataverseName, ifExists); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | CreateDataverseStatement CreateDataverseStatement() throws ParseException : |
| 505 | { |
| 506 | Identifier dvName = null; |
| 507 | boolean ifNotExists = false; |
| 508 | String format = null; |
| 509 | } |
| 510 | { |
| 511 | < IDENTIFIER > |
| 512 | { |
| 513 | dvName = new Identifier(token.image); |
| 514 | } |
| 515 | ( |
| 516 | "if not exists" |
| 517 | { |
| 518 | ifNotExists = true; |
| 519 | } |
| 520 | )? |
| 521 | ( |
| 522 | "with format" < STRING_LITERAL > |
| 523 | { |
| 524 | format = removeQuotesAndEscapes(token.image); |
| 525 | } |
| 526 | )? |
| 527 | ";" |
| 528 | { |
| 529 | return new CreateDataverseStatement(dvName, format, ifNotExists); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | LoadFromFileStatement LoadStatement() throws ParseException: |
| 534 | { |
| 535 | Identifier datasetName = null; |
| 536 | boolean alreadySorted = false; |
| 537 | String adapterClassname; |
| 538 | Map<String,String> properties; |
| 539 | } |
| 540 | { |
| 541 | <DATASET> <IDENTIFIER> { datasetName = new Identifier(token.image); } |
| 542 | |
| 543 | "using" |
| 544 | |
| 545 | <STRING_LITERAL> |
| 546 | { |
| 547 | adapterClassname = removeQuotesAndEscapes(token.image); |
| 548 | } |
| 549 | |
| 550 | { |
| 551 | properties = getConfiguration(); |
| 552 | } |
| 553 | |
| 554 | ("pre-sorted" |
| 555 | { alreadySorted = true; } |
| 556 | )? |
| 557 | |
| 558 | ";" |
| 559 | { |
| 560 | return new LoadFromFileStatement(datasetName, adapterClassname, properties, alreadySorted); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | |
| 565 | |
| 566 | DatasetDecl DatasetDeclaration(DatasetType datasetType) throws ParseException : |
| 567 | { |
| 568 | DatasetDecl dd = null; |
| 569 | Identifier datasetName = null; |
| 570 | Identifier itemTypeName = null; |
| 571 | boolean ifNotExists = false; |
| 572 | IDatasetDetailsDecl idd = null; |
| 573 | } |
| 574 | { |
| 575 | < IDENTIFIER > |
| 576 | { |
| 577 | datasetName = new Identifier(token.image); |
| 578 | } |
| 579 | ( |
| 580 | "if not exists" |
| 581 | { |
| 582 | ifNotExists = true; |
| 583 | } |
| 584 | )? |
| 585 | ( |
| 586 | < LEFTPAREN > < IDENTIFIER > |
| 587 | { |
| 588 | itemTypeName = new Identifier(token.image); |
| 589 | } |
| 590 | < RIGHTPAREN > |
| 591 | )? |
| 592 | { |
| 593 | if(datasetType == DatasetType.INTERNAL) { |
| 594 | idd = InternalDatasetDeclaration(); |
| 595 | dd = new DatasetDecl(datasetName, itemTypeName, idd, ifNotExists); |
| 596 | } |
| 597 | else if(datasetType == DatasetType.EXTERNAL) { |
| 598 | idd = ExternalDatasetDeclaration(); |
| 599 | dd = new DatasetDecl(datasetName, itemTypeName, idd,ifNotExists); |
| 600 | } |
| 601 | else if(datasetType == DatasetType.FEED) { |
| 602 | idd = FeedDatasetDeclaration(); |
| 603 | dd = new DatasetDecl(datasetName, itemTypeName, idd,ifNotExists); |
| 604 | } |
| 605 | dd.setDatasetType(datasetType); |
| 606 | } |
| 607 | { |
| 608 | return dd; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | InternalDetailsDecl InternalDatasetDeclaration() throws ParseException : |
| 613 | { |
| 614 | InternalDetailsDecl idd = null; |
| 615 | } |
| 616 | { |
| 617 | { |
| 618 | idd = new InternalDetailsDecl(); |
| 619 | } |
| 620 | "partitioned" "by" "key" |
| 621 | < IDENTIFIER > |
| 622 | { |
| 623 | idd.addPartitioningExpr(token.image); |
| 624 | } |
| 625 | ( |
| 626 | "," < IDENTIFIER > |
| 627 | { |
| 628 | idd.addPartitioningExpr(token.image); |
| 629 | } |
| 630 | )* |
| 631 | ( |
| 632 | "on" < IDENTIFIER > |
| 633 | { |
| 634 | idd.setNodegroupName(new Identifier(token.image)); |
| 635 | } |
| 636 | )? |
| 637 | ";" |
| 638 | { |
| 639 | return idd; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | ExternalDetailsDecl ExternalDatasetDeclaration() throws ParseException : |
| 644 | { |
| 645 | ExternalDetailsDecl edd = null; |
| 646 | String adapterClassname = null; |
| 647 | Map < String, String > properties; |
| 648 | } |
| 649 | { |
| 650 | { |
| 651 | edd = new ExternalDetailsDecl(); |
| 652 | } |
| 653 | |
| 654 | "using" |
| 655 | |
| 656 | <STRING_LITERAL> |
| 657 | { |
| 658 | adapterClassname = removeQuotesAndEscapes(token.image); |
| 659 | } |
| 660 | |
| 661 | { |
| 662 | properties = getConfiguration(); |
| 663 | } |
| 664 | |
| 665 | { |
| 666 | edd = new ExternalDetailsDecl(); |
| 667 | edd.setAdapter(adapterClassname); |
| 668 | edd.setProperties(properties); |
| 669 | } |
| 670 | ";" |
| 671 | |
| 672 | { |
| 673 | return edd; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | FeedDetailsDecl FeedDatasetDeclaration() throws ParseException : |
| 678 | { |
| 679 | FeedDetailsDecl fdd = null; |
| 680 | String adapterClassname = null; |
| 681 | Map < String, String > properties; |
| 682 | } |
| 683 | { |
| 684 | { |
| 685 | fdd = new FeedDetailsDecl(); |
| 686 | } |
| 687 | |
| 688 | "using" |
| 689 | |
| 690 | <STRING_LITERAL> |
| 691 | { |
| 692 | adapterClassname = removeQuotesAndEscapes(token.image); |
| 693 | } |
| 694 | |
| 695 | { |
| 696 | properties = getConfiguration(); |
| 697 | } |
| 698 | |
| 699 | ("apply" "function" |
| 700 | < IDENTIFIER > |
| 701 | { |
| 702 | fdd.setFunctionIdentifier(token.image); |
| 703 | } |
| 704 | )? |
| 705 | |
| 706 | "partitioned" "by" "key" |
| 707 | < IDENTIFIER > |
| 708 | { |
| 709 | fdd.addPartitioningExpr(token.image); |
| 710 | } |
| 711 | ( |
| 712 | "," < IDENTIFIER > |
| 713 | { |
| 714 | fdd.addPartitioningExpr(token.image); |
| 715 | } |
| 716 | )* |
| 717 | ( |
| 718 | "on" < IDENTIFIER > |
| 719 | { |
| 720 | fdd.setNodegroupName(new Identifier(token.image)); |
| 721 | } |
| 722 | )? |
| 723 | ";" |
| 724 | { |
| 725 | fdd.setAdapterClassname(adapterClassname); |
| 726 | fdd.setProperties(properties); |
| 727 | return fdd; |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | ControlFeedStatement AlterFeedDeclaration(Identifier datasetName) throws ParseException : |
| 732 | { |
| 733 | String name = null; |
| 734 | String value = null; |
| 735 | Map < String, String > configuration = new HashMap < String, String > (); |
| 736 | } |
| 737 | { |
| 738 | "set" |
| 739 | { |
| 740 | configuration = getConfiguration(); |
| 741 | } |
| 742 | ";" |
| 743 | { |
| 744 | return new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, datasetName, configuration); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | Map<String,String> getConfiguration() throws ParseException : |
| 749 | { |
| 750 | Map<String,String> configuration = new HashMap<String,String>(); |
| 751 | String key; |
| 752 | String value; |
| 753 | } |
| 754 | { |
| 755 | |
| 756 | <LEFTPAREN> |
| 757 | ( |
| 758 | ( |
| 759 | <LEFTPAREN> |
| 760 | ( |
| 761 | <STRING_LITERAL> |
| 762 | { |
| 763 | key = removeQuotesAndEscapes(token.image); |
| 764 | } |
| 765 | "=" <STRING_LITERAL> |
| 766 | { |
| 767 | value = removeQuotesAndEscapes(token.image); |
| 768 | } |
| 769 | ) |
| 770 | <RIGHTPAREN> |
| 771 | { |
| 772 | configuration.put(key, value); |
| 773 | } |
| 774 | ) |
| 775 | ( |
| 776 | "," <LEFTPAREN> |
| 777 | ( |
| 778 | <STRING_LITERAL> |
| 779 | { |
| 780 | key = removeQuotesAndEscapes(token.image); |
| 781 | } |
| 782 | "=" <STRING_LITERAL> |
| 783 | { |
| 784 | value = removeQuotesAndEscapes(token.image); |
| 785 | } |
| 786 | ) |
| 787 | <RIGHTPAREN> |
| 788 | { |
| 789 | configuration.put(key, value); |
| 790 | } |
| 791 | )* |
| 792 | )? |
| 793 | <RIGHTPAREN> |
| 794 | { |
| 795 | return configuration; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | |
| 800 | NodegroupDecl NodegroupDeclaration() throws ParseException : |
| 801 | { |
| 802 | Identifier name = null; |
| 803 | List < Identifier > ncNames = new ArrayList < Identifier > (); |
| 804 | boolean ifNotExists = false; |
| 805 | } |
| 806 | { |
| 807 | < IDENTIFIER > |
| 808 | { |
| 809 | name = new Identifier(token.image); |
| 810 | } |
| 811 | ( |
| 812 | "if not exists" |
| 813 | { |
| 814 | ifNotExists = true; |
| 815 | } |
| 816 | )? |
| 817 | "on" < IDENTIFIER > |
| 818 | { |
| 819 | ncNames.add(new Identifier(token.image)); |
| 820 | } |
| 821 | ( |
| 822 | "," < IDENTIFIER > |
| 823 | { |
| 824 | ncNames.add(new Identifier(token.image)); |
| 825 | } |
| 826 | )* |
| 827 | ";" |
| 828 | { |
| 829 | return new NodegroupDecl(name, ncNames, ifNotExists); |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | |
| 834 | TypeDecl TypeDeclaration(boolean dgen, String hint) throws ParseException: |
| 835 | { |
| 836 | Identifier ident; |
| 837 | TypeExpression typeExpr; |
| 838 | boolean ifNotExists = false; |
| 839 | } |
| 840 | { |
| 841 | <IDENTIFIER> |
| 842 | { |
| 843 | ident = new Identifier(token.image.toString()); |
| 844 | } |
| 845 | ( |
| 846 | "if not exists" |
| 847 | { |
| 848 | ifNotExists = true; |
| 849 | } |
| 850 | )? |
| 851 | "as" |
| 852 | ( typeExpr = TypeExpr() ) |
| 853 | { |
| 854 | long numValues = -1; |
| 855 | String filename = null; |
| 856 | if (dgen) { |
| 857 | String splits[] = hint.split(" +"); |
| 858 | if (splits.length != 3) { |
| 859 | throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */"); |
| 860 | } |
| 861 | filename = splits[1]; |
| 862 | numValues = Long.parseLong(splits[2]); |
| 863 | } |
| 864 | TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues); |
| 865 | return new TypeDecl(ident, typeExpr, tddg, ifNotExists); |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | TypeExpression TypeExpr() throws ParseException: |
| 870 | { |
| 871 | TypeExpression typeExpr = null; |
| 872 | } |
| 873 | { |
| 874 | ( |
| 875 | typeExpr = RecordTypeDef() |
| 876 | | typeExpr = TypeReference() |
| 877 | | typeExpr = OrderedListTypeDef() |
| 878 | | typeExpr = UnorderedListTypeDef() |
| 879 | ) |
| 880 | { |
| 881 | return typeExpr; |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | RecordTypeDefinition RecordTypeDef() throws ParseException: |
| 886 | { |
| 887 | RecordTypeDefinition recType = new RecordTypeDefinition(); |
| 888 | RecordTypeDefinition.RecordKind recordKind = null; |
| 889 | } |
| 890 | { |
| 891 | ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; } |
| 892 | | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )? |
| 893 | "{" |
| 894 | { |
| 895 | String hint = getHint(token); |
| 896 | if (hint != null) { |
| 897 | String splits[] = hint.split(" +"); |
| 898 | if (splits[0].equals(GEN_FIELDS_HINT)) { |
| 899 | if (splits.length != 5) { |
| 900 | throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/"); |
| 901 | } |
| 902 | if (!splits[1].equals("int")) { |
| 903 | throw new ParseException("The only supported type for gen-fields is int."); |
| 904 | } |
| 905 | UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT, |
| 906 | Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]); |
| 907 | recType.setUndeclaredFieldsDataGen(ufdg); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | } |
| 912 | ( |
| 913 | RecordField(recType) |
| 914 | ( "," RecordField(recType) )* |
| 915 | )? |
| 916 | "}" |
| 917 | { |
| 918 | if (recordKind == null) { |
| 919 | recordKind = RecordTypeDefinition.RecordKind.OPEN; |
| 920 | } |
| 921 | recType.setRecordKind(recordKind); |
| 922 | return recType; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | void RecordField(RecordTypeDefinition recType) throws ParseException: |
| 927 | { |
| 928 | String fieldName; |
| 929 | TypeExpression type = null; |
| 930 | boolean nullable = false; |
| 931 | } |
| 932 | { |
| 933 | <IDENTIFIER> |
| 934 | { |
| 935 | Token t = getToken(0); |
| 936 | fieldName = t.toString(); |
| 937 | String hint = getHint(t); |
| 938 | IRecordFieldDataGen rfdg = null; |
| 939 | if (hint != null) { |
| 940 | String splits[] = hint.split(" +"); |
| 941 | if (splits[0].equals(VAL_FILE_HINT)) { |
| 942 | File[] valFiles = new File[splits.length - 1]; |
| 943 | for (int k=1; k<splits.length; k++) { |
| 944 | valFiles[k-1] = new File(splits[k]); |
| 945 | } |
| 946 | rfdg = new FieldValFileDataGen(valFiles); |
| 947 | } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) { |
| 948 | rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]); |
| 949 | } else if (splits[0].equals(LIST_VAL_FILE_HINT)) { |
| 950 | rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3])); |
| 951 | } else if (splits[0].equals(LIST_HINT)) { |
| 952 | rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 953 | } else if (splits[0].equals(INTERVAL_HINT)) { |
| 954 | FieldIntervalDataGen.ValueType vt; |
| 955 | if (splits[1].equals("int")) { |
| 956 | vt = FieldIntervalDataGen.ValueType.INT; |
| 957 | } else if (splits[1].equals("long")) { |
| 958 | vt = FieldIntervalDataGen.ValueType.LONG; |
| 959 | } else if (splits[1].equals("float")) { |
| 960 | vt = FieldIntervalDataGen.ValueType.FLOAT; |
| 961 | } else if (splits[1].equals("double")) { |
| 962 | vt = FieldIntervalDataGen.ValueType.DOUBLE; |
| 963 | } else { |
| 964 | throw new ParseException("Unknown type for interval data gen: " + splits[1]); |
| 965 | } |
| 966 | rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]); |
| 967 | } else if (splits[0].equals(INSERT_RAND_INT_HINT)) { |
| 968 | rfdg = new InsertRandIntDataGen(splits[1], splits[2]); |
| 969 | } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) { |
| 970 | rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 971 | } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) { |
| 972 | rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 973 | } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) { |
| 974 | rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]); |
| 975 | } else if (splits[0].equals(AUTO_HINT)) { |
| 976 | rfdg = new AutoDataGen(splits[1]); |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | ":" |
| 981 | ( type = TypeExpr() ) |
| 982 | ("?" { nullable = true; } )? |
| 983 | { |
| 984 | recType.addField(fieldName, type, nullable, rfdg); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | TypeReferenceExpression TypeReference() throws ParseException: |
| 989 | {} |
| 990 | { |
| 991 | <IDENTIFIER> |
| 992 | { |
| 993 | Token t = getToken(0); |
| 994 | Identifier id = new Identifier(t.toString()); |
| 995 | return new TypeReferenceExpression(id); |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | OrderedListTypeDefinition OrderedListTypeDef() throws ParseException: |
| 1000 | { |
| 1001 | TypeExpression type = null; |
| 1002 | } |
| 1003 | { |
| 1004 | "[" |
| 1005 | ( type = TypeExpr() ) |
| 1006 | "]" |
| 1007 | { |
| 1008 | return new OrderedListTypeDefinition(type); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | |
| 1013 | UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException: |
| 1014 | { |
| 1015 | TypeExpression type = null; |
| 1016 | } |
| 1017 | { |
| 1018 | "{{" |
| 1019 | ( type = TypeExpr() ) |
| 1020 | "}}" |
| 1021 | { |
| 1022 | return new UnorderedListTypeDefinition(type); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | |
| 1027 | FunctionDecl FunctionDeclaration() throws ParseException: |
| 1028 | { |
| 1029 | FunctionDecl func = new FunctionDecl(); |
| 1030 | FunIdentifier ident = new FunIdentifier(); |
| 1031 | int arity = 0; |
| 1032 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 1033 | Expression funcBody; |
| 1034 | VarIdentifier var = null; |
| 1035 | createNewScope(); |
| 1036 | } |
| 1037 | { |
| 1038 | |
| 1039 | <IDENTIFIER> |
| 1040 | { |
| 1041 | Token t = getToken(0); |
| 1042 | ident.setValue(t.toString()); |
| 1043 | } |
| 1044 | <LEFTPAREN> (<VARIABLE> |
| 1045 | { |
| 1046 | var = new VarIdentifier(); |
| 1047 | var.setValue(getToken(0).toString()); |
| 1048 | paramList.add(var); |
| 1049 | getCurrentScope().addNewVarSymbolToScope(var); |
| 1050 | arity++; |
| 1051 | } |
| 1052 | ("," <VARIABLE> |
| 1053 | { |
| 1054 | var = new VarIdentifier(); |
| 1055 | var.setValue(getToken(0).toString()); |
| 1056 | paramList.add(var); |
| 1057 | getCurrentScope().addNewVarSymbolToScope(var); |
| 1058 | arity++; |
| 1059 | })*)? <RIGHTPAREN> "{" funcBody = Expression() "}" |
| 1060 | |
| 1061 | { |
| 1062 | ident.setArity(arity); |
| 1063 | getCurrentScope().addFunctionDescriptor(ident, false); |
| 1064 | func.setIdent(ident); |
| 1065 | func.setFuncBody(funcBody); |
| 1066 | func.setParamList(paramList); |
| 1067 | return func; |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | CreateFunctionStatement FunctionCreation() throws ParseException: |
| 1072 | { |
| 1073 | CreateFunctionStatement cfs = null; |
| 1074 | FunIdentifier ident = new FunIdentifier(); |
| 1075 | int arity = 0; |
| 1076 | boolean ifNotExists = false; |
| 1077 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 1078 | String funcBody; |
| 1079 | VarIdentifier var = null; |
| 1080 | createNewScope(); |
| 1081 | } |
| 1082 | { |
| 1083 | |
| 1084 | <IDENTIFIER> |
| 1085 | { |
| 1086 | Token t = getToken(0); |
| 1087 | ident.setValue(t.toString()); |
| 1088 | } |
| 1089 | |
| 1090 | ( |
| 1091 | "if not exists" |
| 1092 | { |
| 1093 | ifNotExists = true; |
| 1094 | } |
| 1095 | )? |
| 1096 | |
| 1097 | <LEFTPAREN> (<VARIABLE> |
| 1098 | { |
| 1099 | var = new VarIdentifier(); |
| 1100 | var.setValue(getToken(0).toString()); |
| 1101 | paramList.add(var); |
| 1102 | getCurrentScope().addNewVarSymbolToScope(var); |
| 1103 | arity++; |
| 1104 | } |
| 1105 | ("," <VARIABLE> |
| 1106 | { |
| 1107 | var = new VarIdentifier(); |
| 1108 | var.setValue(getToken(0).toString()); |
| 1109 | paramList.add(var); |
| 1110 | getCurrentScope().addNewVarSymbolToScope(var); |
| 1111 | arity++; |
| 1112 | })*)? <RIGHTPAREN> "{" <STRING_LITERAL> |
| 1113 | { |
| 1114 | funcBody = removeQuotesAndEscapes(token.image); |
| 1115 | } |
| 1116 | "}" |
| 1117 | { |
| 1118 | ident.setArity(arity); |
| 1119 | getCurrentScope().addFunctionDescriptor(ident, false); |
| 1120 | cfs = new CreateFunctionStatement(ident, paramList, funcBody, ifNotExists); |
| 1121 | return cfs; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | Query Query()throws ParseException: |
| 1128 | { |
| 1129 | Query query = new Query(); |
| 1130 | Expression expr; |
| 1131 | } |
| 1132 | { |
| 1133 | expr = Expression() |
| 1134 | |
| 1135 | { |
| 1136 | query.setBody(expr); |
| 1137 | return query; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | |
| 1143 | Expression Expression(): |
| 1144 | { |
| 1145 | Expression expr = null; |
| 1146 | Expression exprP = null; |
| 1147 | } |
| 1148 | { |
| 1149 | ( |
| 1150 | |
| 1151 | //OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression |
| 1152 | expr = OperatorExpr() |
| 1153 | | expr = IfThenElse() |
| 1154 | | expr = FLWOGR() |
| 1155 | | expr = QuantifiedExpression() |
| 1156 | |
| 1157 | |
| 1158 | ) |
| 1159 | { |
| 1160 | return (exprP==null) ? expr : exprP; |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | Expression OperatorExpr()throws ParseException: |
| 1167 | { |
| 1168 | OperatorExpr op = null; |
| 1169 | Expression operand = null; |
| 1170 | } |
| 1171 | { |
| 1172 | operand = AndExpr() |
| 1173 | ( |
| 1174 | |
| 1175 | "or" |
| 1176 | { |
| 1177 | if (op == null) { |
| 1178 | op = new OperatorExpr(); |
| 1179 | op.addOperand(operand); |
| 1180 | op.setCurrentop(true); |
| 1181 | } |
| 1182 | Token t = getToken(0); |
| 1183 | op.addOperator(t.toString()); |
| 1184 | } |
| 1185 | |
| 1186 | operand = AndExpr() |
| 1187 | { |
| 1188 | op.addOperand(operand); |
| 1189 | } |
| 1190 | |
| 1191 | )* |
| 1192 | |
| 1193 | { |
| 1194 | return op==null? operand: op; |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | Expression AndExpr()throws ParseException: |
| 1199 | { |
| 1200 | OperatorExpr op = null; |
| 1201 | Expression operand = null; |
| 1202 | } |
| 1203 | { |
| 1204 | operand = RelExpr() |
| 1205 | ( |
| 1206 | |
| 1207 | "and" |
| 1208 | { |
| 1209 | if (op == null) { |
| 1210 | op = new OperatorExpr(); |
| 1211 | op.addOperand(operand); |
| 1212 | op.setCurrentop(true); |
| 1213 | } |
| 1214 | Token t = getToken(0); |
| 1215 | op.addOperator(t.toString()); |
| 1216 | } |
| 1217 | |
| 1218 | operand = RelExpr() |
| 1219 | { |
| 1220 | op.addOperand(operand); |
| 1221 | } |
| 1222 | |
| 1223 | )* |
| 1224 | |
| 1225 | { |
| 1226 | return op==null? operand: op; |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | |
| 1231 | |
| 1232 | Expression RelExpr()throws ParseException: |
| 1233 | { |
| 1234 | OperatorExpr op = null; |
| 1235 | Expression operand = null; |
| 1236 | boolean broadcast = false; |
| 1237 | } |
| 1238 | { |
| 1239 | operand = AddExpr() |
| 1240 | { |
| 1241 | if (operand instanceof VariableExpr) { |
| 1242 | String hint = getHint(token); |
| 1243 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1244 | broadcast = true; |
| 1245 | } |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | ( |
| 1250 | LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=") |
| 1251 | { |
| 1252 | if (op == null) { |
| 1253 | op = new OperatorExpr(); |
| 1254 | op.addOperand(operand, broadcast); |
| 1255 | op.setCurrentop(true); |
| 1256 | broadcast = false; |
| 1257 | } |
| 1258 | Token t = getToken(0); |
| 1259 | op.addOperator(t.toString()); |
| 1260 | } |
| 1261 | |
| 1262 | operand = AddExpr() |
| 1263 | { |
| 1264 | broadcast = false; |
| 1265 | if (operand instanceof VariableExpr) { |
| 1266 | String hint = getHint(token); |
| 1267 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1268 | broadcast = true; |
| 1269 | } |
| 1270 | } |
| 1271 | op.addOperand(operand, broadcast); |
| 1272 | } |
| 1273 | )? |
| 1274 | |
| 1275 | { |
| 1276 | return op==null? operand: op; |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | Expression AddExpr()throws ParseException: |
| 1281 | { |
| 1282 | OperatorExpr op = null; |
| 1283 | Expression operand = null; |
| 1284 | } |
| 1285 | { |
| 1286 | operand = MultExpr() |
| 1287 | |
| 1288 | ( ("+" | "-") |
| 1289 | { |
| 1290 | if (op == null) { |
| 1291 | op = new OperatorExpr(); |
| 1292 | op.addOperand(operand); |
| 1293 | op.setCurrentop(true); |
| 1294 | } |
| 1295 | Token t = getToken(0); |
| 1296 | ((OperatorExpr)op).addOperator(t.toString()); |
| 1297 | } |
| 1298 | |
| 1299 | operand = MultExpr() |
| 1300 | { |
| 1301 | op.addOperand(operand); |
| 1302 | } |
| 1303 | )* |
| 1304 | |
| 1305 | { |
| 1306 | return op==null? operand: op; |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | Expression MultExpr()throws ParseException: |
| 1311 | { |
| 1312 | OperatorExpr op = null; |
| 1313 | Expression operand = null; |
| 1314 | } |
| 1315 | { |
| 1316 | operand = UnionExpr() |
| 1317 | |
| 1318 | (( "*" | "/" | "%" | <CARET> | "idiv") |
| 1319 | { |
| 1320 | if (op == null) { |
| 1321 | op = new OperatorExpr(); |
| 1322 | op.addOperand(operand); |
| 1323 | op.setCurrentop(true); |
| 1324 | } |
| 1325 | Token t = getToken(0); |
| 1326 | op.addOperator(t.toString()); |
| 1327 | } |
| 1328 | operand = UnionExpr() |
| 1329 | { |
| 1330 | op.addOperand(operand); |
| 1331 | } |
| 1332 | )* |
| 1333 | |
| 1334 | { |
| 1335 | return op==null?operand:op; |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | Expression UnionExpr() throws ParseException: |
| 1340 | { |
| 1341 | UnionExpr union = null; |
| 1342 | Expression operand1 = null; |
| 1343 | Expression operand2 = null; |
| 1344 | } |
| 1345 | { |
| 1346 | operand1 = UnaryExpr() |
| 1347 | ("union" |
| 1348 | (operand2 = UnaryExpr()) { |
| 1349 | if (union == null) { |
| 1350 | union = new UnionExpr(); |
| 1351 | union.addExpr(operand1); |
| 1352 | } |
| 1353 | union.addExpr(operand2); |
| 1354 | } )* |
| 1355 | { |
| 1356 | return (union == null)? operand1: union; |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | Expression UnaryExpr() throws ParseException: |
| 1361 | { |
| 1362 | Expression uexpr = null; |
| 1363 | Expression expr = null; |
| 1364 | } |
| 1365 | { |
| 1366 | (( "+"|"-") |
| 1367 | { |
| 1368 | uexpr = new UnaryExpr(); |
| 1369 | Token t = getToken(0); |
| 1370 | if("+".equals(t.toString())) |
| 1371 | ((UnaryExpr)uexpr).setSign(Sign.POSITIVE); |
| 1372 | else if("-".equals(t.toString())) |
| 1373 | ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE); |
| 1374 | else |
| 1375 | throw new ParseException(); |
| 1376 | } |
| 1377 | )? |
| 1378 | |
| 1379 | expr = ValueExpr() |
| 1380 | { |
| 1381 | if(uexpr!=null){ |
| 1382 | ((UnaryExpr)uexpr).setExpr(expr); |
| 1383 | return uexpr; |
| 1384 | } |
| 1385 | else{ |
| 1386 | return expr; |
| 1387 | } |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | Expression ValueExpr() throws ParseException: |
| 1392 | { |
| 1393 | Expression expr; |
| 1394 | } |
| 1395 | { |
| 1396 | expr = FieldOrIndexAccessor() |
| 1397 | { |
| 1398 | return expr; |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | |
| 1403 | Expression FieldOrIndexAccessor()throws ParseException: |
| 1404 | { |
| 1405 | Expression expr = null; |
| 1406 | Identifier ident = null; |
| 1407 | AbstractAccessor fa = null; |
| 1408 | int index; |
| 1409 | |
| 1410 | } |
| 1411 | { |
| 1412 | ( expr = PrimaryExpr() |
| 1413 | |
| 1414 | ) |
| 1415 | |
| 1416 | |
| 1417 | ( |
| 1418 | ( |
| 1419 | ident = Field() |
| 1420 | { |
| 1421 | if(fa == null) |
| 1422 | fa = new FieldAccessor(expr, ident); |
| 1423 | else |
| 1424 | fa = new FieldAccessor(fa, ident); |
| 1425 | } |
| 1426 | ) |
| 1427 | | ( |
| 1428 | index = Index() |
| 1429 | { |
| 1430 | if(fa == null) |
| 1431 | fa = new IndexAccessor(expr, index); |
| 1432 | else |
| 1433 | fa = new IndexAccessor(fa, index); |
| 1434 | } |
| 1435 | ) |
| 1436 | )* |
| 1437 | |
| 1438 | |
| 1439 | { |
| 1440 | return fa==null?expr:fa; |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | Identifier Field() throws ParseException: |
| 1445 | { |
| 1446 | Identifier ident = null; |
| 1447 | |
| 1448 | } |
| 1449 | { |
| 1450 | "." < IDENTIFIER > |
| 1451 | { |
| 1452 | |
| 1453 | ident = new Identifier(); |
| 1454 | ident.setValue(getToken(0).toString()); |
| 1455 | |
| 1456 | return ident; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | int Index() throws ParseException: |
| 1461 | { |
| 1462 | Expression expr = null; |
| 1463 | int idx = -2; |
| 1464 | } |
| 1465 | { |
| 1466 | "[" ( expr = Expression() |
| 1467 | { |
| 1468 | if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION) |
| 1469 | { |
| 1470 | ILiteral lit = ((LiteralExpr)expr).getValue(); |
| 1471 | if(lit.getLiteralType() == ILiteral.Type.INTEGER) { |
| 1472 | idx = Integer.valueOf(lit.getStringValue()); |
| 1473 | } |
| 1474 | else { |
| 1475 | throw new ParseException("Index should be an INTEGER"); |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | } |
| 1480 | |
| 1481 | | "?" |
| 1482 | { |
| 1483 | idx = IndexAccessor.ANY; |
| 1484 | // ANY |
| 1485 | } |
| 1486 | |
| 1487 | ) |
| 1488 | |
| 1489 | "]" |
| 1490 | { |
| 1491 | return idx; |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | |
| 1496 | Expression PrimaryExpr()throws ParseException: |
| 1497 | { |
| 1498 | Expression expr = null; |
| 1499 | } |
| 1500 | { |
| 1501 | //ILiteral | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | ParenthesizedExpression |
| 1502 | ( |
| 1503 | expr =Literal() |
| 1504 | | expr = FunctionCallExpr() |
| 1505 | | expr =VariableRef() |
| 1506 | |
| 1507 | { |
| 1508 | if(((VariableExpr)expr).getIsNewVar() == true) |
| 1509 | throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar()); |
| 1510 | } |
| 1511 | | expr = ListConstructor() |
| 1512 | | expr = RecordConstructor() |
| 1513 | | expr = ParenthesizedExpression() |
| 1514 | ) |
| 1515 | { |
| 1516 | return expr; |
| 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | Expression Literal() throws ParseException: |
| 1521 | { |
| 1522 | |
| 1523 | LiteralExpr lit = new LiteralExpr(); |
| 1524 | Token t; |
| 1525 | } |
| 1526 | { |
| 1527 | ( |
| 1528 | <STRING_LITERAL> |
| 1529 | { |
| 1530 | t= getToken(0); |
| 1531 | lit.setValue( new StringLiteral(removeQuotesAndEscapes(t.image))); |
| 1532 | } |
| 1533 | |
| 1534 | | <INTEGER_LITERAL> |
| 1535 | { |
| 1536 | t= getToken(0); |
| 1537 | lit.setValue(new IntegerLiteral(new Integer(t.image))); |
| 1538 | } |
| 1539 | | < FLOAT_LITERAL > |
| 1540 | { |
| 1541 | t= getToken(0); |
| 1542 | lit.setValue(new FloatLiteral(new Float(t.image))); |
| 1543 | } |
| 1544 | | < DOUBLE_LITERAL > |
| 1545 | { |
| 1546 | t= getToken(0); |
| 1547 | lit.setValue(new DoubleLiteral(new Double(t.image))); |
| 1548 | } |
| 1549 | | <NULL> |
| 1550 | { |
| 1551 | t= getToken(0); |
| 1552 | lit.setValue(NullLiteral.INSTANCE); |
| 1553 | } |
| 1554 | | <TRUE> |
| 1555 | { |
| 1556 | t= getToken(0); |
| 1557 | lit.setValue(TrueLiteral.INSTANCE); |
| 1558 | } |
| 1559 | | <FALSE> |
| 1560 | { |
| 1561 | t= getToken(0); |
| 1562 | lit.setValue(FalseLiteral.INSTANCE); |
| 1563 | } |
| 1564 | ) |
| 1565 | { |
| 1566 | return lit; |
| 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | |
| 1571 | VariableExpr VariableRef() throws ParseException: |
| 1572 | { |
| 1573 | VariableExpr varExp = new VariableExpr(); |
| 1574 | VarIdentifier var = new VarIdentifier(); |
| 1575 | Token t; |
| 1576 | } |
| 1577 | { |
| 1578 | <VARIABLE> |
| 1579 | { |
| 1580 | t = getToken(0);//get current token |
| 1581 | String varName = t.toString(); |
| 1582 | Identifier ident = lookupSymbol(varName); |
| 1583 | if (isInForbiddenScopes(varName)) { |
| 1584 | throw new ParseException("Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause."); |
| 1585 | } |
| 1586 | if(ident != null) { // exist such ident |
| 1587 | varExp.setIsNewVar(false); |
| 1588 | varExp.setVar((VarIdentifier)ident); |
| 1589 | } else { |
| 1590 | varExp.setVar(var); |
| 1591 | } |
| 1592 | var.setValue(t.toString()); |
| 1593 | return varExp; |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | |
| 1598 | VariableExpr Variable() throws ParseException: |
| 1599 | { |
| 1600 | VariableExpr varExp = new VariableExpr(); |
| 1601 | VarIdentifier var = new VarIdentifier(); |
| 1602 | Token t; |
| 1603 | } |
| 1604 | { |
| 1605 | <VARIABLE> |
| 1606 | { |
| 1607 | t = getToken(0);//get current token |
| 1608 | Identifier ident = lookupSymbol(t.toString()); |
| 1609 | if(ident != null) { // exist such ident |
| 1610 | varExp.setIsNewVar(false); |
| 1611 | } |
| 1612 | varExp.setVar(var); |
| 1613 | var.setValue(t.toString()); |
| 1614 | return varExp; |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | Expression ListConstructor() throws ParseException: |
| 1619 | { |
| 1620 | Expression expr = null; |
| 1621 | } |
| 1622 | { |
| 1623 | ( |
| 1624 | expr = OrderedListConstructor() | expr = UnorderedListConstructor() |
| 1625 | ) |
| 1626 | |
| 1627 | { |
| 1628 | return expr; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | |
| 1633 | ListConstructor OrderedListConstructor() throws ParseException: |
| 1634 | { |
| 1635 | ListConstructor expr = new ListConstructor(); |
| 1636 | Expression tmp = null; |
| 1637 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1638 | expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR); |
| 1639 | } |
| 1640 | { |
| 1641 | |
| 1642 | "[" |
| 1643 | ( tmp = Expression() |
| 1644 | { |
| 1645 | exprList.add(tmp); |
| 1646 | } |
| 1647 | |
| 1648 | ("," tmp = Expression() { exprList.add(tmp); })* |
| 1649 | )? |
| 1650 | |
| 1651 | "]" |
| 1652 | |
| 1653 | { |
| 1654 | expr.setExprList(exprList); |
| 1655 | return expr; |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | ListConstructor UnorderedListConstructor() throws ParseException: |
| 1660 | { |
| 1661 | ListConstructor expr = new ListConstructor(); |
| 1662 | Expression tmp = null; |
| 1663 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1664 | expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR); |
| 1665 | } |
| 1666 | { |
| 1667 | |
| 1668 | "{{" ( tmp = Expression() |
| 1669 | { |
| 1670 | exprList.add(tmp); |
| 1671 | } |
| 1672 | ("," tmp = Expression() { exprList.add(tmp); })*)? "}}" |
| 1673 | { |
| 1674 | expr.setExprList(exprList); |
| 1675 | return expr; |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | RecordConstructor RecordConstructor() throws ParseException: |
| 1680 | { |
| 1681 | RecordConstructor expr = new RecordConstructor(); |
| 1682 | FieldBinding tmp = null; |
| 1683 | List<FieldBinding> fbList = new ArrayList<FieldBinding>(); |
| 1684 | } |
| 1685 | { |
| 1686 | "{" (tmp = FieldBinding() |
| 1687 | { |
| 1688 | fbList.add(tmp); |
| 1689 | } |
| 1690 | ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}" |
| 1691 | { |
| 1692 | expr.setFbList(fbList); |
| 1693 | return expr; |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | FieldBinding FieldBinding() throws ParseException: |
| 1698 | { |
| 1699 | FieldBinding fb = new FieldBinding(); |
| 1700 | Expression left, right; |
| 1701 | } |
| 1702 | { |
| 1703 | left = Expression() ":" right = Expression() |
| 1704 | { |
| 1705 | fb.setLeftExpr(left); |
| 1706 | fb.setRightExpr(right); |
| 1707 | return fb; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | Expression FunctionCallExpr() throws ParseException: |
| 1712 | { |
| 1713 | CallExpr pf = new CallExpr(); |
| 1714 | List<Expression > argList = new ArrayList<Expression >(); |
| 1715 | Expression tmp; |
| 1716 | int arity = 0; |
| 1717 | Token funcName; |
| 1718 | } |
| 1719 | { |
| 1720 | ( <IDENTIFIER> | <DATASET> ) |
| 1721 | { |
| 1722 | funcName = getToken(0); |
| 1723 | } |
| 1724 | <LEFTPAREN> (tmp = Expression() |
| 1725 | { |
| 1726 | argList.add(tmp); |
| 1727 | arity ++; |
| 1728 | } ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN> |
| 1729 | |
| 1730 | { |
| 1731 | FunIdentifier fd = lookupFunctionSignature(funcName.toString(), arity); |
| 1732 | if(fd == null) |
| 1733 | { |
| 1734 | fd = new FunIdentifier(funcName.toString(), arity); |
| 1735 | // notFoundFunctionList.add(fd); |
| 1736 | } |
| 1737 | // throw new ParseException("can't find function "+ funcName.toString() + "@" + arity); |
| 1738 | pf.setIdent(fd); |
| 1739 | pf.setExprList(argList); |
| 1740 | return pf; |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | |
| 1745 | Expression ParenthesizedExpression() throws ParseException: |
| 1746 | { |
| 1747 | Expression expr; |
| 1748 | } |
| 1749 | { |
| 1750 | <LEFTPAREN> expr = Expression() <RIGHTPAREN> |
| 1751 | { |
| 1752 | return expr; |
| 1753 | } |
| 1754 | } |
| 1755 | |
| 1756 | Expression IfThenElse() throws ParseException: |
| 1757 | { |
| 1758 | Expression condExpr; |
| 1759 | Expression thenExpr; |
| 1760 | Expression elseExpr; |
| 1761 | IfExpr ifExpr = new IfExpr(); |
| 1762 | } |
| 1763 | { |
| 1764 | "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression() |
| 1765 | |
| 1766 | { |
| 1767 | ifExpr.setCondExpr(condExpr); |
| 1768 | ifExpr.setThenExpr(thenExpr); |
| 1769 | ifExpr.setElseExpr(elseExpr); |
| 1770 | return ifExpr; |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | Expression FLWOGR() throws ParseException: |
| 1775 | { |
| 1776 | FLWOGRExpression flworg = new FLWOGRExpression(); |
| 1777 | List<Clause> clauseList = new ArrayList<Clause>(); |
| 1778 | Expression returnExpr; |
| 1779 | Clause tmp; |
| 1780 | createNewScope(); |
| 1781 | } |
| 1782 | { |
| 1783 | (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);}) |
| 1784 | (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression() |
| 1785 | |
| 1786 | { |
| 1787 | flworg.setClauseList(clauseList); |
| 1788 | flworg.setReturnExpr(returnExpr); |
| 1789 | removeCurrentScope(); |
| 1790 | return flworg; |
| 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | Clause Clause()throws ParseException : |
| 1795 | { |
| 1796 | Clause clause; |
| 1797 | } |
| 1798 | { |
| 1799 | ( |
| 1800 | clause = ForClause() |
| 1801 | | clause = LetClause() |
| 1802 | | clause = WhereClause() |
| 1803 | | clause = OrderbyClause() |
| 1804 | | clause = GroupClause() |
| 1805 | | clause = LimitClause() |
| 1806 | | clause = DistinctClause() |
| 1807 | | clause = DieClause() |
| 1808 | ) |
| 1809 | { |
| 1810 | return clause; |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | Clause ForClause()throws ParseException : |
| 1815 | { |
| 1816 | ForClause fc = new ForClause(); |
| 1817 | VariableExpr varExp; |
| 1818 | VariableExpr varPos = null; |
| 1819 | Expression inExp; |
| 1820 | extendCurrentScope(); |
| 1821 | } |
| 1822 | { |
| 1823 | "for" varExp = Variable() |
| 1824 | { |
| 1825 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
| 1826 | } |
| 1827 | ("at" varPos = Variable() |
| 1828 | { |
| 1829 | getCurrentScope().addNewVarSymbolToScope(varPos.getVar()); |
| 1830 | } |
| 1831 | )? |
| 1832 | "in" ( inExp = Expression() ) |
| 1833 | { |
| 1834 | fc.setVarExpr(varExp); |
| 1835 | fc.setInExpr(inExp); |
| 1836 | if (varPos != null) { |
| 1837 | fc.setPosExpr(varPos); |
| 1838 | } |
| 1839 | return fc; |
| 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | Clause LetClause() throws ParseException: |
| 1844 | { |
| 1845 | LetClause lc = new LetClause(); |
| 1846 | VariableExpr varExp; |
| 1847 | Expression beExp; |
| 1848 | extendCurrentScope(); |
| 1849 | } |
| 1850 | { |
| 1851 | "let" varExp = Variable() |
| 1852 | { |
| 1853 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
| 1854 | } |
| 1855 | ":=" beExp = Expression() |
| 1856 | { |
| 1857 | lc.setVarExpr(varExp); |
| 1858 | lc.setBeExpr(beExp); |
| 1859 | return lc; |
| 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | Clause WhereClause()throws ParseException : |
| 1864 | { |
| 1865 | WhereClause wc = new WhereClause(); |
| 1866 | Expression whereExpr; |
| 1867 | } |
| 1868 | { |
| 1869 | "where" whereExpr = Expression() |
| 1870 | { |
| 1871 | wc.setWhereExpr(whereExpr); |
| 1872 | return wc; |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | Clause OrderbyClause()throws ParseException : |
| 1877 | { |
| 1878 | OrderbyClause oc = new OrderbyClause(); |
| 1879 | Expression orderbyExpr; |
| 1880 | List<Expression> orderbyList = new ArrayList<Expression>(); |
| 1881 | List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >(); |
| 1882 | int numOfOrderby = 0; |
| 1883 | } |
| 1884 | { |
| 1885 | ( |
| 1886 | "order" |
| 1887 | { |
| 1888 | String hint = getHint(token); |
| 1889 | if (hint != null && hint.startsWith(INMEMORY_HINT)) { |
| 1890 | String splits[] = hint.split(" +"); |
| 1891 | int numFrames = Integer.parseInt(splits[1]); |
| 1892 | int numTuples = Integer.parseInt(splits[2]); |
| 1893 | oc.setNumFrames(numFrames); |
| 1894 | oc.setNumTuples(numTuples); |
| 1895 | } |
| 1896 | } |
| 1897 | "by" orderbyExpr = Expression() |
| 1898 | { |
| 1899 | orderbyList.add(orderbyExpr); |
| 1900 | OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC; |
| 1901 | } |
| 1902 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1903 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 1904 | { |
| 1905 | modifierList.add(modif); |
| 1906 | } |
| 1907 | |
| 1908 | ("," orderbyExpr = Expression() |
| 1909 | { |
| 1910 | orderbyList.add(orderbyExpr); |
| 1911 | modif = OrderbyClause.OrderModifier.ASC; |
| 1912 | } |
| 1913 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1914 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 1915 | { |
| 1916 | modifierList.add(modif); |
| 1917 | } |
| 1918 | )* |
| 1919 | ) |
| 1920 | { |
| 1921 | oc.setModifierList(modifierList); |
| 1922 | oc.setOrderbyList(orderbyList); |
| 1923 | return oc; |
| 1924 | } |
| 1925 | } |
| 1926 | Clause GroupClause()throws ParseException : |
| 1927 | { |
| 1928 | GroupbyClause gbc = new GroupbyClause(); |
| 1929 | // GbyVariableExpressionPair pair = new GbyVariableExpressionPair(); |
| 1930 | List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>(); |
| 1931 | List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>(); |
| 1932 | List<VariableExpr> withVarList= new ArrayList<VariableExpr>(); |
| 1933 | VariableExpr var = null; |
| 1934 | VariableExpr withVar = null; |
| 1935 | Expression expr = null; |
| 1936 | VariableExpr decorVar = null; |
| 1937 | Expression decorExpr = null; |
| 1938 | } |
| 1939 | { |
| 1940 | { |
| 1941 | Scope newScope = extendCurrentScopeNoPush(true); |
| 1942 | // extendCurrentScope(true); |
| 1943 | } |
| 1944 | "group" |
| 1945 | { |
| 1946 | String hint = getHint(token); |
| 1947 | if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) { |
| 1948 | gbc.setHashGroupByHint(true); |
| 1949 | } |
| 1950 | } |
| 1951 | "by" (LOOKAHEAD(2) var = Variable() |
| 1952 | { |
| 1953 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 1954 | } ":=")? |
| 1955 | expr = Expression() |
| 1956 | { |
| 1957 | GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr); |
| 1958 | vePairList.add(pair1); |
| 1959 | } |
| 1960 | ("," ( LOOKAHEAD(2) var = Variable() |
| 1961 | { |
| 1962 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 1963 | } ":=")? |
| 1964 | expr = Expression() |
| 1965 | { |
| 1966 | GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr); |
| 1967 | vePairList.add(pair2); |
| 1968 | } |
| 1969 | )* |
| 1970 | ("decor" decorVar = Variable() ":=" decorExpr = Expression() |
| 1971 | { |
| 1972 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 1973 | GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 1974 | decorPairList.add(pair3); |
| 1975 | } |
| 1976 | ("," "decor" decorVar = Variable() ":=" decorExpr = Expression() |
| 1977 | { |
| 1978 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 1979 | GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 1980 | decorPairList.add(pair4); |
| 1981 | } |
| 1982 | )* |
| 1983 | )? |
| 1984 | "with" withVar = VariableRef() |
| 1985 | { |
| 1986 | if(withVar.getIsNewVar()==true) |
| 1987 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 1988 | withVarList.add(withVar); |
| 1989 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 1990 | } |
| 1991 | ("," withVar = VariableRef() |
| 1992 | { |
| 1993 | if(withVar.getIsNewVar()==true) |
| 1994 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 1995 | withVarList.add(withVar); |
| 1996 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 1997 | })* |
| 1998 | { |
| 1999 | gbc.setGbyPairList(vePairList); |
| 2000 | gbc.setDecorPairList(decorPairList); |
| 2001 | gbc.setWithVarList(withVarList); |
| 2002 | replaceCurrentScope(newScope); |
| 2003 | return gbc; |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | |
| 2008 | LimitClause LimitClause() throws ParseException: |
| 2009 | { |
| 2010 | LimitClause lc = new LimitClause(); |
| 2011 | Expression expr; |
| 2012 | pushForbiddenScope(getCurrentScope()); |
| 2013 | } |
| 2014 | { |
| 2015 | "limit" expr = Expression() { lc.setLimitExpr(expr); } |
| 2016 | ("offset" expr = Expression() { lc.setOffset(expr); })? |
| 2017 | |
| 2018 | { |
| 2019 | popForbiddenScope(); |
| 2020 | return lc; |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | DistinctClause DistinctClause() throws ParseException: |
| 2025 | { |
| 2026 | List<Expression> exprs = new ArrayList<Expression>(); |
| 2027 | Expression expr; |
| 2028 | } |
| 2029 | { |
| 2030 | "distinct" "by" expr = Expression() |
| 2031 | { |
| 2032 | exprs.add(expr); |
| 2033 | } |
| 2034 | ("," expr = Expression() |
| 2035 | { |
| 2036 | exprs.add(expr); |
| 2037 | } |
| 2038 | )* |
| 2039 | { |
| 2040 | return new DistinctClause(exprs); |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | DieClause DieClause() throws ParseException: |
| 2045 | { |
| 2046 | DieClause lc = new DieClause(); |
| 2047 | Expression expr; |
| 2048 | pushForbiddenScope(getCurrentScope()); |
| 2049 | } |
| 2050 | { |
| 2051 | "die" "after" expr = Expression() { lc.setDieExpr(expr); } |
| 2052 | { |
| 2053 | popForbiddenScope(); |
| 2054 | return lc; |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | |
| 2059 | QuantifiedExpression QuantifiedExpression()throws ParseException: |
| 2060 | { |
| 2061 | QuantifiedExpression qc = new QuantifiedExpression(); |
| 2062 | List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>(); |
| 2063 | Expression satisfiesExpr; |
| 2064 | VariableExpr var; |
| 2065 | Expression inExpr; |
| 2066 | QuantifiedPair pair; |
| 2067 | } |
| 2068 | { |
| 2069 | { |
| 2070 | createNewScope(); |
| 2071 | } |
| 2072 | |
| 2073 | ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }) |
| 2074 | | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); })) |
| 2075 | var = Variable() "in" inExpr = Expression() |
| 2076 | { |
| 2077 | pair = new QuantifiedPair(var, inExpr); |
| 2078 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2079 | quantifiedList.add(pair); |
| 2080 | } |
| 2081 | ( |
| 2082 | "," var = Variable() "in" inExpr = Expression() |
| 2083 | { |
| 2084 | pair = new QuantifiedPair(var, inExpr); |
| 2085 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2086 | quantifiedList.add(pair); |
| 2087 | } |
| 2088 | )* |
| 2089 | "satisfies" satisfiesExpr = Expression() |
| 2090 | { |
| 2091 | qc.setSatisfiesExpr(satisfiesExpr); |
| 2092 | qc.setQuantifiedList(quantifiedList); |
| 2093 | removeCurrentScope(); |
| 2094 | return qc; |
| 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | TOKEN_MGR_DECLS: |
| 2099 | { |
| 2100 | public int commentDepth = 0; |
| 2101 | } |
| 2102 | |
| 2103 | <DEFAULT> |
| 2104 | TOKEN : |
| 2105 | { |
| 2106 | <CARET : "^" > |
| 2107 | } |
| 2108 | |
| 2109 | <DEFAULT> |
| 2110 | TOKEN : |
| 2111 | { |
| 2112 | <DATASET : "dataset" > |
| 2113 | } |
| 2114 | |
| 2115 | <DEFAULT> |
| 2116 | TOKEN : |
| 2117 | { |
| 2118 | <LEFTPAREN : "(" > |
| 2119 | } |
| 2120 | |
| 2121 | <DEFAULT> |
| 2122 | TOKEN : |
| 2123 | { |
| 2124 | <RIGHTPAREN : ")" > |
| 2125 | } |
| 2126 | |
| 2127 | |
| 2128 | <DEFAULT> |
| 2129 | TOKEN : |
| 2130 | { |
| 2131 | <INTEGER_LITERAL : (<DIGIT>)+ > |
| 2132 | } |
| 2133 | |
| 2134 | |
| 2135 | <DEFAULT> |
| 2136 | TOKEN : |
| 2137 | { |
| 2138 | <NULL : "null"> |
| 2139 | } |
| 2140 | |
| 2141 | <DEFAULT> |
| 2142 | TOKEN : |
| 2143 | { |
| 2144 | <TRUE : "true"> |
| 2145 | } |
| 2146 | |
| 2147 | <DEFAULT> |
| 2148 | TOKEN : |
| 2149 | { |
| 2150 | <FALSE : "false"> |
| 2151 | } |
| 2152 | |
| 2153 | <DEFAULT> |
| 2154 | TOKEN : |
| 2155 | { |
| 2156 | <#DIGIT : ["0" - "9"]> |
| 2157 | } |
| 2158 | |
| 2159 | |
| 2160 | TOKEN: |
| 2161 | { |
| 2162 | < DOUBLE_LITERAL: <INTEGER> |
| 2163 | | <INTEGER> ( "." <INTEGER> )? |
| 2164 | | "." <INTEGER> |
| 2165 | > |
| 2166 | | |
| 2167 | < FLOAT_LITERAL: <INTEGER> ( "f" | "F" ) |
| 2168 | | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )? |
| 2169 | | "." <INTEGER> ( "f" | "F" ) |
| 2170 | > |
| 2171 | | |
| 2172 | <INTEGER : (<DIGIT>)+ > |
| 2173 | } |
| 2174 | |
| 2175 | <DEFAULT> |
| 2176 | TOKEN : |
| 2177 | { |
| 2178 | <#LETTER : ["A" - "Z", "a" - "z"]> |
| 2179 | } |
| 2180 | |
| 2181 | <DEFAULT> |
| 2182 | TOKEN : |
| 2183 | { |
| 2184 | <SPECIALCHARS : ["$", "_", "-"] > |
| 2185 | } |
| 2186 | |
| 2187 | <DEFAULT> |
| 2188 | TOKEN : |
| 2189 | { |
| 2190 | <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")> |
| 2191 | | |
| 2192 | < #EscapeQuot: "\\\"" > |
| 2193 | | |
| 2194 | < #EscapeApos: "\\\'" > |
| 2195 | } |
| 2196 | |
| 2197 | <DEFAULT> |
| 2198 | TOKEN : |
| 2199 | { |
| 2200 | <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*> |
| 2201 | } |
| 2202 | |
| 2203 | <DEFAULT> |
| 2204 | TOKEN : |
| 2205 | { |
| 2206 | <VARIABLE : "$" <IDENTIFIER> > |
| 2207 | } |
| 2208 | |
| 2209 | SKIP: |
| 2210 | { |
| 2211 | " " |
| 2212 | | "\t" |
| 2213 | | "\r" |
| 2214 | | "\n" |
| 2215 | } |
| 2216 | |
| 2217 | SKIP: |
| 2218 | { |
| 2219 | <"//" (~["\n"])* "\n"> |
| 2220 | } |
| 2221 | |
| 2222 | SKIP: |
| 2223 | { |
| 2224 | <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
| 2225 | } |
| 2226 | |
| 2227 | |
| 2228 | SKIP: |
| 2229 | { |
| 2230 | <"/*"> {commentDepth=1;}: INSIDE_COMMENT |
| 2231 | } |
| 2232 | |
| 2233 | <INSIDE_COMMENT> |
| 2234 | SPECIAL_TOKEN: |
| 2235 | { |
| 2236 | <"+"(" ")*(~["*"])*> |
| 2237 | } |
| 2238 | |
| 2239 | <INSIDE_COMMENT> |
| 2240 | SKIP: |
| 2241 | { |
| 2242 | <"/*"> {commentDepth++;} |
| 2243 | } |
| 2244 | |
| 2245 | <INSIDE_COMMENT> |
| 2246 | SKIP: |
| 2247 | { |
| 2248 | <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);} |
| 2249 | | <~[]> |
| 2250 | } |