1 /** \file 2 * This OBJC source file was generated by $ANTLR version ${project.version} ${buildNumber} 3 * 4 * - From the grammar source file : SymbolTable.g 5 * - On : 2011-05-06 15:04:42 6 * - for the parser : SymbolTableParserParser 7 * 8 * Editing it, at least manually, is not wise. 9 * 10 * ObjC language generator and runtime by Alan Condit, acondit|hereisanat|ipns|dotgoeshere|com. 11 * 12 * 13 */ 14 // $ANTLR ${project.version} ${buildNumber} SymbolTable.g 2011-05-06 15:04:42 15 16 17 /* ----------------------------------------- 18 * Include the ANTLR3 generated header file. 19 */ 20 #import "SymbolTableParser.h" 21 /* ----------------------------------------- */ 22 23 24 /* ============================================================================= */ 25 /* ============================================================================= 26 * Start of recognizer 27 */ 28 29 #pragma mark Bitsets 30 static ANTLRBitSet *FOLLOW_globals_in_prog50; 31 static const unsigned long long FOLLOW_globals_in_prog50_data[] = { 0x0000000000001002LL}; 32 static ANTLRBitSet *FOLLOW_method_in_prog53; 33 static const unsigned long long FOLLOW_method_in_prog53_data[] = { 0x0000000000001002LL}; 34 static ANTLRBitSet *FOLLOW_decl_in_globals85; 35 static const unsigned long long FOLLOW_decl_in_globals85_data[] = { 0x0000000000000802LL}; 36 static ANTLRBitSet *FOLLOW_12_in_method116; 37 static const unsigned long long FOLLOW_12_in_method116_data[] = { 0x0000000000000010LL}; 38 static ANTLRBitSet *FOLLOW_ID_in_method118; 39 static const unsigned long long FOLLOW_ID_in_method118_data[] = { 0x0000000000000080LL}; 40 static ANTLRBitSet *FOLLOW_7_in_method120; 41 static const unsigned long long FOLLOW_7_in_method120_data[] = { 0x0000000000000100LL}; 42 static ANTLRBitSet *FOLLOW_8_in_method122; 43 static const unsigned long long FOLLOW_8_in_method122_data[] = { 0x0000000000002000LL}; 44 static ANTLRBitSet *FOLLOW_block_in_method124; 45 static const unsigned long long FOLLOW_block_in_method124_data[] = { 0x0000000000000002LL}; 46 static ANTLRBitSet *FOLLOW_13_in_block153; 47 static const unsigned long long FOLLOW_13_in_block153_data[] = { 0x0000000000006810LL}; 48 static ANTLRBitSet *FOLLOW_decl_in_block156; 49 static const unsigned long long FOLLOW_decl_in_block156_data[] = { 0x0000000000006810LL}; 50 static ANTLRBitSet *FOLLOW_stat_in_block161; 51 static const unsigned long long FOLLOW_stat_in_block161_data[] = { 0x0000000000006010LL}; 52 static ANTLRBitSet *FOLLOW_14_in_block165; 53 static const unsigned long long FOLLOW_14_in_block165_data[] = { 0x0000000000000002LL}; 54 static ANTLRBitSet *FOLLOW_ID_in_stat189; 55 static const unsigned long long FOLLOW_ID_in_stat189_data[] = { 0x0000000000000400LL}; 56 static ANTLRBitSet *FOLLOW_10_in_stat191; 57 static const unsigned long long FOLLOW_10_in_stat191_data[] = { 0x0000000000000020LL}; 58 static ANTLRBitSet *FOLLOW_INT_in_stat193; 59 static const unsigned long long FOLLOW_INT_in_stat193_data[] = { 0x0000000000000200LL}; 60 static ANTLRBitSet *FOLLOW_9_in_stat195; 61 static const unsigned long long FOLLOW_9_in_stat195_data[] = { 0x0000000000000002LL}; 62 static ANTLRBitSet *FOLLOW_block_in_stat205; 63 static const unsigned long long FOLLOW_block_in_stat205_data[] = { 0x0000000000000002LL}; 64 static ANTLRBitSet *FOLLOW_11_in_decl219; 65 static const unsigned long long FOLLOW_11_in_decl219_data[] = { 0x0000000000000010LL}; 66 static ANTLRBitSet *FOLLOW_ID_in_decl221; 67 static const unsigned long long FOLLOW_ID_in_decl221_data[] = { 0x0000000000000200LL}; 68 static ANTLRBitSet *FOLLOW_9_in_decl223; 69 static const unsigned long long FOLLOW_9_in_decl223_data[] = { 0x0000000000000002LL}; 70 71 72 #pragma mark Dynamic Global Scopes 73 @implementation Symbols_Scope /* globalAttributeScopeImplementation */ 74 /* start of synthesize -- OBJC-Line 1750 */ 75 76 @synthesize names; 77 78 + (Symbols_Scope *)newSymbols_Scope 79 { 80 return [[[Symbols_Scope alloc] init] retain]; 81 } 82 83 - (id) init 84 { 85 self = [super init]; 86 return self; 87 } 88 89 /* start of iterate get and set functions */ 90 91 - (ANTLRPtrBuffer *)getnames { return( names ); } 92 93 - (void)setnames:(ANTLRPtrBuffer *)aVal { names = aVal; } 94 95 /* End of iterate get and set functions */ 96 97 @end /* end of Symbols_Scope implementation */ 98 99 100 #pragma mark Dynamic Rule Scopes 101 102 #pragma mark Rule Return Scopes start 103 //#pragma mark Rule return scopes start 104 // 105 106 #pragma mark Rule return scopes start 107 108 @implementation SymbolTableParser // line 637 109 110 /* ObjC start of ruleAttributeScope */ 111 #pragma mark Dynamic Rule Scopes 112 /* ObjC end of ruleAttributeScope */ 113 #pragma mark global Attribute Scopes 114 /* ObjC start globalAttributeScope */ 115 static _stack; 116 117 /* ObjC end globalAttributeScope */ 118 /* ObjC start actions.(actionScope).synthesize */ 119 /* ObjC end actions.(actionScope).synthesize */ 120 /* ObjC start synthesize() */ 121 /* ObjC end synthesize() */ 122 123 + (void) initialize 124 { 125 #pragma mark Bitsets 126 FOLLOW_globals_in_prog50 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_globals_in_prog50_data Count:(NSUInteger)1] retain]; 127 FOLLOW_method_in_prog53 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_method_in_prog53_data Count:(NSUInteger)1] retain]; 128 FOLLOW_decl_in_globals85 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_decl_in_globals85_data Count:(NSUInteger)1] retain]; 129 FOLLOW_12_in_method116 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_12_in_method116_data Count:(NSUInteger)1] retain]; 130 FOLLOW_ID_in_method118 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_ID_in_method118_data Count:(NSUInteger)1] retain]; 131 FOLLOW_7_in_method120 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_7_in_method120_data Count:(NSUInteger)1] retain]; 132 FOLLOW_8_in_method122 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_8_in_method122_data Count:(NSUInteger)1] retain]; 133 FOLLOW_block_in_method124 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_block_in_method124_data Count:(NSUInteger)1] retain]; 134 FOLLOW_13_in_block153 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_13_in_block153_data Count:(NSUInteger)1] retain]; 135 FOLLOW_decl_in_block156 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_decl_in_block156_data Count:(NSUInteger)1] retain]; 136 FOLLOW_stat_in_block161 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_stat_in_block161_data Count:(NSUInteger)1] retain]; 137 FOLLOW_14_in_block165 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_14_in_block165_data Count:(NSUInteger)1] retain]; 138 FOLLOW_ID_in_stat189 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_ID_in_stat189_data Count:(NSUInteger)1] retain]; 139 FOLLOW_10_in_stat191 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_10_in_stat191_data Count:(NSUInteger)1] retain]; 140 FOLLOW_INT_in_stat193 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_INT_in_stat193_data Count:(NSUInteger)1] retain]; 141 FOLLOW_9_in_stat195 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_9_in_stat195_data Count:(NSUInteger)1] retain]; 142 FOLLOW_block_in_stat205 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_block_in_stat205_data Count:(NSUInteger)1] retain]; 143 FOLLOW_11_in_decl219 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_11_in_decl219_data Count:(NSUInteger)1] retain]; 144 FOLLOW_ID_in_decl221 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_ID_in_decl221_data Count:(NSUInteger)1] retain]; 145 FOLLOW_9_in_decl223 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_9_in_decl223_data Count:(NSUInteger)1] retain]; 146 147 [ANTLRBaseRecognizer setTokenNames:[[AMutableArray arrayWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>", 148 @"ID", @"INT", @"WS", @"'('", @"')'", @"';'", @"'='", @"'int'", @"'method'", 149 @"'{'", @"'}'", nil] retain]]; 150 [ANTLRBaseRecognizer setGrammarFileName:@"SymbolTable.g"]; 151 } 152 153 + (SymbolTableParser *)newSymbolTableParser:(id<ANTLRTokenStream>)aStream 154 { 155 return [[SymbolTableParser alloc] initWithTokenStream:aStream]; 156 157 158 } 159 160 - (id) initWithTokenStream:(id<ANTLRTokenStream>)aStream 161 { 162 self = [super initWithTokenStream:aStream State:[[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:6+1] retain]]; 163 if ( self != nil ) { 164 165 166 /* globalAttributeScopeInit */ 167 Symbols_scope = [Symbols_Scope newSymbols_Scope]; 168 Symbols_stack = [ANTLRSymbolStack newANTLRSymbolStackWithLen:30]; 169 /* start of actions-actionScope-init */ 170 171 level = 0; 172 173 /* start of init */ 174 } 175 return self; 176 } 177 178 - (void) dealloc 179 { 180 [Symbols_stack release]; 181 [super dealloc]; 182 } 183 184 /* ObjC start members */ 185 /* ObjC end members */ 186 /* ObjC start actions.(actionScope).methods */ 187 /* ObjC end actions.(actionScope).methods */ 188 /* ObjC start methods() */ 189 /* ObjC end methods() */ 190 /* ObjC start rules */ 191 /* 192 * $ANTLR start prog 193 * SymbolTable.g:25:1: prog : globals ( method )* ; 194 */ 195 - (void) prog 196 { 197 /* my ruleScopeSetUp */ 198 /* Terence's stuff */ 199 200 @try { 201 // SymbolTable.g:27:5: ( globals ( method )* ) // ruleBlockSingleAlt 202 // SymbolTable.g:27:9: globals ( method )* // alt 203 { 204 /* ruleRef */ 205 [self pushFollow:FOLLOW_globals_in_prog50]; 206 [self globals]; 207 208 [self popFollow]; 209 210 211 212 do { 213 NSInteger alt1=2; 214 NSInteger LA1_0 = [input LA:1]; 215 if ( (LA1_0==12) ) { 216 alt1=1; 217 } 218 219 220 switch (alt1) { 221 case 1 : ; 222 // SymbolTable.g:27:18: method // alt 223 { 224 /* ruleRef */ 225 [self pushFollow:FOLLOW_method_in_prog53]; 226 [self method]; 227 228 [self popFollow]; 229 230 231 232 } 233 break; 234 235 default : 236 goto loop1; 237 } 238 } while (YES); 239 loop1: ; 240 241 242 } 243 244 // token+rule list labels 245 246 } 247 @catch (ANTLRRecognitionException *re) { 248 [self reportError:re]; 249 [self recover:input Exception:re]; 250 } 251 252 @finally { 253 /* Terence's stuff */ 254 255 } 256 return ; 257 } 258 /* $ANTLR end prog */ 259 260 /* 261 * $ANTLR start globals 262 * SymbolTable.g:30:1: globals : ( decl )* ; 263 */ 264 - (void) globals 265 { 266 /* my ruleScopeSetUp */ 267 /* Terence's stuff */ 268 [Symbols_stack push:[[Symbols_Scope newSymbols_Scope] retain]]; 269 270 271 level++; 272 /* scopeSetAttributeRef */((Symbols_Scope *)[Symbols_stack peek]).names = [ANTLRPtrBuffer newANTLRPtrBufferWithLen:10]; 273 274 @try { 275 // SymbolTable.g:36:5: ( ( decl )* ) // ruleBlockSingleAlt 276 // SymbolTable.g:36:9: ( decl )* // alt 277 { 278 do { 279 NSInteger alt2=2; 280 NSInteger LA2_0 = [input LA:1]; 281 if ( (LA2_0==11) ) { 282 alt2=1; 283 } 284 285 286 switch (alt2) { 287 case 1 : ; 288 // SymbolTable.g:36:10: decl // alt 289 { 290 /* ruleRef */ 291 [self pushFollow:FOLLOW_decl_in_globals85]; 292 [self decl]; 293 294 [self popFollow]; 295 296 297 298 } 299 break; 300 301 default : 302 goto loop2; 303 } 304 } while (YES); 305 loop2: ; 306 307 308 309 NSLog( @"globals: %@", [((Symbols_Scope *)[Symbols_stack peek]).names toString] ); 310 level--; 311 312 313 314 } 315 316 // token+rule list labels 317 318 } 319 @catch (ANTLRRecognitionException *re) { 320 [self reportError:re]; 321 [self recover:input Exception:re]; 322 } 323 324 @finally { 325 /* Terence's stuff */ 326 [Symbols_stack pop]; 327 328 } 329 return ; 330 } 331 /* $ANTLR end globals */ 332 333 /* 334 * $ANTLR start method 335 * SymbolTable.g:43:1: method : 'method' ID '(' ')' block ; 336 */ 337 - (void) method 338 { 339 /* my ruleScopeSetUp */ 340 /* Terence's stuff */ 341 342 @try { 343 // SymbolTable.g:44:5: ( 'method' ID '(' ')' block ) // ruleBlockSingleAlt 344 // SymbolTable.g:44:9: 'method' ID '(' ')' block // alt 345 { 346 [self match:input TokenType:12 Follow:FOLLOW_12_in_method116]; 347 348 [self match:input TokenType:ID Follow:FOLLOW_ID_in_method118]; 349 350 [self match:input TokenType:7 Follow:FOLLOW_7_in_method120]; 351 352 [self match:input TokenType:8 Follow:FOLLOW_8_in_method122]; 353 354 /* ruleRef */ 355 [self pushFollow:FOLLOW_block_in_method124]; 356 [self block]; 357 358 [self popFollow]; 359 360 361 362 } 363 364 // token+rule list labels 365 366 } 367 @catch (ANTLRRecognitionException *re) { 368 [self reportError:re]; 369 [self recover:input Exception:re]; 370 } 371 372 @finally { 373 /* Terence's stuff */ 374 375 } 376 return ; 377 } 378 /* $ANTLR end method */ 379 380 /* 381 * $ANTLR start block 382 * SymbolTable.g:47:1: block : '{' ( decl )* ( stat )* '}' ; 383 */ 384 - (void) block 385 { 386 /* my ruleScopeSetUp */ 387 /* Terence's stuff */ 388 [Symbols_stack push:[[Symbols_Scope newSymbols_Scope] retain]]; 389 390 391 level++; 392 /* scopeSetAttributeRef */((Symbols_Scope *)[Symbols_stack peek]).names = [ANTLRPtrBuffer newANTLRPtrBufferWithLen:10]; 393 394 @try { 395 // SymbolTable.g:53:5: ( '{' ( decl )* ( stat )* '}' ) // ruleBlockSingleAlt 396 // SymbolTable.g:53:9: '{' ( decl )* ( stat )* '}' // alt 397 { 398 [self match:input TokenType:13 Follow:FOLLOW_13_in_block153]; 399 400 do { 401 NSInteger alt3=2; 402 NSInteger LA3_0 = [input LA:1]; 403 if ( (LA3_0==11) ) { 404 alt3=1; 405 } 406 407 408 switch (alt3) { 409 case 1 : ; 410 // SymbolTable.g:53:14: decl // alt 411 { 412 /* ruleRef */ 413 [self pushFollow:FOLLOW_decl_in_block156]; 414 [self decl]; 415 416 [self popFollow]; 417 418 419 420 } 421 break; 422 423 default : 424 goto loop3; 425 } 426 } while (YES); 427 loop3: ; 428 429 430 do { 431 NSInteger alt4=2; 432 NSInteger LA4_0 = [input LA:1]; 433 if ( (LA4_0==ID||LA4_0==13) ) { 434 alt4=1; 435 } 436 437 438 switch (alt4) { 439 case 1 : ; 440 // SymbolTable.g:53:22: stat // alt 441 { 442 /* ruleRef */ 443 [self pushFollow:FOLLOW_stat_in_block161]; 444 [self stat]; 445 446 [self popFollow]; 447 448 449 450 } 451 break; 452 453 default : 454 goto loop4; 455 } 456 } while (YES); 457 loop4: ; 458 459 460 [self match:input TokenType:14 Follow:FOLLOW_14_in_block165]; 461 462 463 NSLog( @"level %d symbols: %@", level, [((Symbols_Scope *)[Symbols_stack peek]).names toString] ); 464 level--; 465 466 467 468 } 469 470 // token+rule list labels 471 472 } 473 @catch (ANTLRRecognitionException *re) { 474 [self reportError:re]; 475 [self recover:input Exception:re]; 476 } 477 478 @finally { 479 /* Terence's stuff */ 480 [Symbols_stack pop]; 481 482 } 483 return ; 484 } 485 /* $ANTLR end block */ 486 487 /* 488 * $ANTLR start stat 489 * SymbolTable.g:60:1: stat : ( ID '=' INT ';' | block ); 490 */ 491 - (void) stat 492 { 493 /* my ruleScopeSetUp */ 494 /* Terence's stuff */ 495 496 @try { 497 // SymbolTable.g:60:5: ( ID '=' INT ';' | block ) //ruleblock 498 NSInteger alt5=2; 499 NSInteger LA5_0 = [input LA:1]; 500 501 if ( (LA5_0==ID) ) { 502 alt5=1; 503 } 504 else if ( (LA5_0==13) ) { 505 alt5=2; 506 } 507 else { 508 ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException newException:5 state:0 stream:input]; 509 nvae.c = LA5_0; 510 @throw nvae; 511 512 } 513 switch (alt5) { 514 case 1 : ; 515 // SymbolTable.g:60:9: ID '=' INT ';' // alt 516 { 517 [self match:input TokenType:ID Follow:FOLLOW_ID_in_stat189]; 518 519 [self match:input TokenType:10 Follow:FOLLOW_10_in_stat191]; 520 521 [self match:input TokenType:INT Follow:FOLLOW_INT_in_stat193]; 522 523 [self match:input TokenType:9 Follow:FOLLOW_9_in_stat195]; 524 525 } 526 break; 527 case 2 : ; 528 // SymbolTable.g:61:9: block // alt 529 { 530 /* ruleRef */ 531 [self pushFollow:FOLLOW_block_in_stat205]; 532 [self block]; 533 534 [self popFollow]; 535 536 537 538 } 539 break; 540 541 } 542 // token+rule list labels 543 544 } 545 @catch (ANTLRRecognitionException *re) { 546 [self reportError:re]; 547 [self recover:input Exception:re]; 548 } 549 550 @finally { 551 /* Terence's stuff */ 552 553 } 554 return ; 555 } 556 /* $ANTLR end stat */ 557 558 /* 559 * $ANTLR start decl 560 * SymbolTable.g:64:1: decl : 'int' ID ';' ; 561 */ 562 - (void) decl 563 { 564 /* my ruleScopeSetUp */ 565 /* Terence's stuff */ 566 567 @try { 568 ANTLRCommonToken *ID1 = nil; 569 570 // SymbolTable.g:64:5: ( 'int' ID ';' ) // ruleBlockSingleAlt 571 // SymbolTable.g:64:9: 'int' ID ';' // alt 572 { 573 [self match:input TokenType:11 Follow:FOLLOW_11_in_decl219]; 574 575 ID1=(ANTLRCommonToken *)[self match:input TokenType:ID Follow:FOLLOW_ID_in_decl221]; 576 577 [self match:input TokenType:9 Follow:FOLLOW_9_in_decl223]; 578 579 [((Symbols_Scope *)[Symbols_stack peek]).names addObject:ID1]; 580 581 582 } 583 584 // token+rule list labels 585 586 } 587 @catch (ANTLRRecognitionException *re) { 588 [self reportError:re]; 589 [self recover:input Exception:re]; 590 } 591 592 @finally { 593 /* Terence's stuff */ 594 595 } 596 return ; 597 } 598 /* $ANTLR end decl */ 599 /* ObjC end rules */ 600 601 @end /* end of SymbolTableParser implementation line 692 */ 602