Changeset 3085 for proto/RE/src/parser
 Timestamp:
 Apr 27, 2013, 8:43:00 PM (6 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

proto/RE/src/parser/Parser.java
r3076 r3085 44 44 } 45 45 public ASTNode parseStart() { 46 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant. SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) {47 return syntaxErrorNode("startÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]");46 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant.LEFTSQUARENEGATE, Lextant.SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) { 47 return syntaxErrorNode("startÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, LEFTSQUARENEGATEÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]"); 48 48 } 49 49 … … 64 64 65 65 public ASTNode parseRe() { 66 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant. SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) {67 return syntaxErrorNode("reÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]");66 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant.LEFTSQUARENEGATE, Lextant.SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) { 67 return syntaxErrorNode("reÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, LEFTSQUARENEGATEÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]"); 68 68 } 69 69 … … 84 84 85 85 public ASTNode parseAlternation() { 86 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant. SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) {87 return syntaxErrorNode("alternationÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]");86 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant.LEFTSQUARENEGATE, Lextant.SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) { 87 return syntaxErrorNode("alternationÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, LEFTSQUARENEGATEÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]"); 88 88 } 89 89 … … 113 113 114 114 public ASTNode parseConcatenation() { 115 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant. SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) {116 return syntaxErrorNode("concatenationÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]");115 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant.LEFTSQUARENEGATE, Lextant.SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) { 116 return syntaxErrorNode("concatenationÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, LEFTSQUARENEGATEÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]"); 117 117 } 118 118 … … 127 127 allChildren.add(child); 128 128 } 129 } while( nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant. SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE)) );129 } while( nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant.LEFTSQUARENEGATE, Lextant.SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE)) ); 130 130 if(allowCompression) { 131 131 return compressIfPossible(result); … … 135 135 136 136 public ASTNode parseRepetition() { 137 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant. SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) {138 return syntaxErrorNode("repetitionÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]");137 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant.LEFTSQUARENEGATE, Lextant.SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) { 138 return syntaxErrorNode("repetitionÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, LEFTSQUARENEGATEÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]"); 139 139 } 140 140 … … 236 236 237 237 boolean allowCompression = true; 238 ASTNode result = new BoundedRepetitionIndicatorNode(nowReading);238 ASTNode result = new RepetitionIndicatorNode(nowReading); 239 239 result.setProductionTag(7); 240 240 RevList<ASTNode> allChildren = new ReverseAccessibleArrayList<ASTNode>(); 241 241 lexController.pushTo("boundedRepetition"); 242 242 expect(Lextant.LEFTCURLY); 243 if( (nowReading.isLexicalType(LexicalType.INTEGER_CONST)) ) { 244 { 245 ASTNode child = parseLowerBound(); 246 result.appendChild(child); 247 allChildren.add(child); 248 } 243 { 244 ASTNode child = parseLowerBound(); 245 // node omitted  no result.appendChild(child); 246 allChildren.add(child); 247 } 248 { 249 ASTNode temp_25 = result; 250 IntRangeNodeType temp_27 = (IntRangeNodeType)temp_25; 251 ASTNode temp_28 = allChildren.revGet(0); 252 IntValuedNodeType temp_30 = (IntValuedNodeType)temp_28; 253 int temp_29 = temp_30.getValue(); 254 temp_27.setLowerBound( temp_29 ); 249 255 } 250 256 if( nowReading.isLextant(Lextant.COMMA) ) { 251 257 expect(Lextant.COMMA); 252 258 { 253 ASTNode temp_25 = result; 254 RepeatableNodeType temp_27 = (RepeatableNodeType)temp_25; 255 boolean temp_28 = false; 256 temp_27.setIsRepeated( temp_28 ); 257 } 258 if( (nowReading.isLexicalType(LexicalType.INTEGER_CONST)) ) { 259 { 260 ASTNode child = parseUpperBound(); 261 result.appendChild(child); 262 allChildren.add(child); 263 } 259 ASTNode child = parseUpperBound(); 260 // node omitted  no result.appendChild(child); 261 allChildren.add(child); 262 } 263 { 264 ASTNode temp_31 = result; 265 IntRangeNodeType temp_33 = (IntRangeNodeType)temp_31; 266 ASTNode temp_34 = allChildren.revGet(0); 267 IntValuedNodeType temp_36 = (IntValuedNodeType)temp_34; 268 int temp_35 = temp_36.getValue(); 269 temp_33.setUpperBound( temp_35 ); 270 } 271 } 272 else if( true ) { 273 // epsilon 274 { 275 ASTNode temp_37 = result; 276 IntRangeNodeType temp_39 = (IntRangeNodeType)temp_37; 277 ASTNode temp_40 = result; 278 IntRangeNodeType temp_42 = (IntRangeNodeType)temp_40; 279 int temp_41 = temp_42.getLowerBound(); 280 temp_39.setUpperBound( temp_41 ); 264 281 } 265 282 } … … 273 290 274 291 public ASTNode parseLowerBound() { 275 if( !((nowReading.isLexicalType(LexicalType.INTEGER_CONST))) ) {276 return syntaxErrorNode("lowerBoundÂ² [INTEGER_CONSTÂ¹]");277 }278 279 292 boolean allowCompression = true; 280 293 ASTNode result = new LowerBoundNode(nowReading); 281 294 result.setProductionTag(8); 282 295 RevList<ASTNode> allChildren = new ReverseAccessibleArrayList<ASTNode>(); 283 if( !(nowReading.isLexicalType(LexicalType.INTEGER_CONST)) ) { 284 return syntaxErrorNode("INTEGER_CONST"); 285 } 286 readToken(); 287 { 288 ASTNode temp_29 = result; 289 IntValuedNodeType temp_31 = (IntValuedNodeType)temp_29; 290 IntValuedToken temp_34 = (IntValuedToken)previouslyRead; 291 int temp_33 = temp_34.getValue(); 292 temp_31.setValue( temp_33 ); 296 if( (nowReading.isLexicalType(LexicalType.INTEGER_CONST)) ) { 297 if( !(nowReading.isLexicalType(LexicalType.INTEGER_CONST)) ) { 298 return syntaxErrorNode("INTEGER_CONST"); 299 } 300 readToken(); 301 { 302 ASTNode temp_43 = result; 303 IntValuedNodeType temp_45 = (IntValuedNodeType)temp_43; 304 IntValuedToken temp_48 = (IntValuedToken)previouslyRead; 305 int temp_47 = temp_48.getValue(); 306 temp_45.setValue( temp_47 ); 307 } 308 } 309 else if( true ) { 310 // epsilon 311 { 312 ASTNode temp_49 = result; 313 IntValuedNodeType temp_51 = (IntValuedNodeType)temp_49; 314 int temp_52 = 0; 315 temp_51.setValue( temp_52 ); 316 } 293 317 } 294 318 if(allowCompression) { … … 299 323 300 324 public ASTNode parseUpperBound() { 301 if( !((nowReading.isLexicalType(LexicalType.INTEGER_CONST))) ) {302 return syntaxErrorNode("upperBoundÂ² [INTEGER_CONSTÂ¹]");303 }304 305 325 boolean allowCompression = true; 306 326 ASTNode result = new UpperBoundNode(nowReading); 307 327 result.setProductionTag(9); 308 328 RevList<ASTNode> allChildren = new ReverseAccessibleArrayList<ASTNode>(); 309 if( !(nowReading.isLexicalType(LexicalType.INTEGER_CONST)) ) { 310 return syntaxErrorNode("INTEGER_CONST"); 311 } 312 readToken(); 313 { 314 ASTNode temp_35 = result; 315 IntValuedNodeType temp_37 = (IntValuedNodeType)temp_35; 316 IntValuedToken temp_40 = (IntValuedToken)previouslyRead; 317 int temp_39 = temp_40.getValue(); 318 temp_37.setValue( temp_39 ); 329 if( (nowReading.isLexicalType(LexicalType.INTEGER_CONST)) ) { 330 if( !(nowReading.isLexicalType(LexicalType.INTEGER_CONST)) ) { 331 return syntaxErrorNode("INTEGER_CONST"); 332 } 333 readToken(); 334 { 335 ASTNode temp_53 = result; 336 IntValuedNodeType temp_55 = (IntValuedNodeType)temp_53; 337 IntValuedToken temp_58 = (IntValuedToken)previouslyRead; 338 int temp_57 = temp_58.getValue(); 339 temp_55.setValue( temp_57 ); 340 } 341 } 342 else if( true ) { 343 // epsilon 344 { 345 ASTNode temp_59 = result; 346 IntValuedNodeType temp_61 = (IntValuedNodeType)temp_59; 347 int temp_62 = 1; 348 temp_61.setValue( temp_62 ); 349 } 319 350 } 320 351 if(allowCompression) { … … 325 356 326 357 public ASTNode parseAtom() { 327 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant. SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) {328 return syntaxErrorNode("atomÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]");358 if( !(nowReading.isLextant(Lextant.ANY, Lextant.EOS, Lextant.LEFTROUND, Lextant.LEFTSQUARE, Lextant.LEFTSQUARENEGATE, Lextant.SOS)  (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE))) ) { 359 return syntaxErrorNode("atomÂ² [ANYÂ¹, CHARACTERÂ¹, CHARACTER_ESCAPEÂ¹, EOSÂ¹, HEXADECIMAL_ESCAPEÂ¹, LEFTROUNDÂ¹, LEFTSQUAREÂ¹, LEFTSQUARENEGATEÂ¹, SOSÂ¹, UNICODE_ESCAPEÂ¹]"); 329 360 } 330 361 … … 352 383 { 353 384 ASTNode child = parseCharacterClass(); 385 result.appendChild(child); 386 allChildren.add(child); 387 } 388 } 389 else if( nowReading.isLextant(Lextant.LEFTSQUARENEGATE) ) { 390 { 391 ASTNode child = parseNegatedCharacterClass(); 354 392 result.appendChild(child); 355 393 allChildren.add(child); … … 433 471 lexController.pushTo("charClass"); 434 472 expect(Lextant.LEFTSQUARE); 435 if( nowReading.isLextant(Lextant.NOT) ) { 436 expect(Lextant.NOT); 437 { 438 ASTNode temp_41 = result; 439 ComplementableNodeType temp_43 = (ComplementableNodeType)temp_41; 440 boolean temp_44 = true; 441 temp_43.setIsComplemented( temp_44 ); 442 } 443 } 473 while( (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE)) ) { 474 { 475 ASTNode child = parseRange(); 476 result.appendChild(child); 477 allChildren.add(child); 478 } 479 } 480 lexController.pop(); 481 expect(Lextant.RIGHTSQUARE); 482 if(allowCompression) { 483 return result; 484 } 485 return result; 486 } 487 488 public ASTNode parseNegatedCharacterClass() { 489 if( !(nowReading.isLextant(Lextant.LEFTSQUARENEGATE)) ) { 490 return syntaxErrorNode("negatedCharacterClassÂ² [LEFTSQUARENEGATEÂ¹]"); 491 } 492 493 boolean allowCompression = true; 494 ASTNode result = new NegatedCharacterClassNode(nowReading); 495 result.setProductionTag(13); 496 RevList<ASTNode> allChildren = new ReverseAccessibleArrayList<ASTNode>(); 497 lexController.pushTo("charClass"); 498 expect(Lextant.LEFTSQUARENEGATE); 444 499 while( (nowReading.isLexicalType(LexicalType.CHARACTER))  (nowReading.isLexicalType(LexicalType.CHARACTER_ESCAPE))  (nowReading.isLexicalType(LexicalType.HEXADECIMAL_ESCAPE))  (nowReading.isLexicalType(LexicalType.UNICODE_ESCAPE)) ) { 445 500 { … … 464 519 boolean allowCompression = true; 465 520 ASTNode result = new RangeNode(nowReading); 466 result.setProductionTag(1 3);521 result.setProductionTag(14); 467 522 RevList<ASTNode> allChildren = new ReverseAccessibleArrayList<ASTNode>(); 468 523 { … … 493 548 boolean allowCompression = true; 494 549 ASTNode result = new AnyNode(nowReading); 495 result.setProductionTag(1 4);550 result.setProductionTag(15); 496 551 RevList<ASTNode> allChildren = new ReverseAccessibleArrayList<ASTNode>(); 497 552 expect(Lextant.ANY); … … 509 564 boolean allowCompression = true; 510 565 ASTNode result = new SosNode(nowReading); 511 result.setProductionTag(1 5);566 result.setProductionTag(16); 512 567 RevList<ASTNode> allChildren = new ReverseAccessibleArrayList<ASTNode>(); 513 568 expect(Lextant.SOS); … … 525 580 boolean allowCompression = true; 526 581 ASTNode result = new EosNode(nowReading); 527 result.setProductionTag(1 6);582 result.setProductionTag(17); 528 583 RevList<ASTNode> allChildren = new ReverseAccessibleArrayList<ASTNode>(); 529 584 expect(Lextant.EOS);
Note: See TracChangeset
for help on using the changeset viewer.