1/** \file 2 * This OBJC source file was generated by $ANTLR version 3.4 3 * 4 * - From the grammar source file : /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g 5 * - On : 2012-02-16 17:58:54 6 * - for the parser : LangParserParser 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 3.4 /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g 2012-02-16 17:58:54 15 16 17/* ----------------------------------------- 18 * Include the ANTLR3 generated header file. 19 */ 20#import "LangParser.h" 21/* ----------------------------------------- */ 22 23 24/* ============================================================================= */ 25/* ============================================================================= 26 * Start of recognizer 27 */ 28 29#pragma mark Bitsets 30static ANTLRBitSet *FOLLOW_decl_in_start41; 31static const unsigned long long FOLLOW_decl_in_start41_data[] = { 0x0000000000000002LL}; 32static ANTLRBitSet *FOLLOW_type_in_decl50; 33static const unsigned long long FOLLOW_type_in_decl50_data[] = { 0x0000000000000040LL}; 34static ANTLRBitSet *FOLLOW_ID_in_decl52; 35static const unsigned long long FOLLOW_ID_in_decl52_data[] = { 0x0000000000000400LL}; 36static ANTLRBitSet *FOLLOW_10_in_decl54; 37static const unsigned long long FOLLOW_10_in_decl54_data[] = { 0x0000000000000002LL}; 38 39 40#pragma mark Dynamic Global globalAttributeScopeImplementation 41 42#pragma mark Dynamic Rule Scopes ruleAttributeScopeImplementation 43 44#pragma mark Rule Return Scopes returnScopeImplementation 45@implementation LangParser_start_return /* returnScopeImplementation */ 46/* AST returnScope.synthesize */ 47@synthesize tree; /* start of synthesize -- OBJC-Line 1837 */ 48+ (LangParser_start_return *)newLangParser_start_return 49{ 50return [[[LangParser_start_return alloc] init] retain]; 51} 52 53- (id) init 54{ 55self = [super init]; 56return self; 57} 58 59/* AST returnScope.methods */ 60- (CommonTree *)getTree 61{ 62 return tree; 63} 64 65- (void) setTree:(CommonTree *)aTree 66{ 67 if (tree != aTree) { 68 if (tree != nil) [tree release]; 69 if (aTree != nil) [aTree retain]; 70 tree = aTree; 71 } 72} 73 74- (void) dealloc 75{ 76 self.tree = nil; 77 [super dealloc]; 78} 79 80 81@end /* end of returnScope implementation */ 82 83@implementation LangParser_decl_return /* returnScopeImplementation */ 84/* AST returnScope.synthesize */ 85@synthesize tree; /* start of synthesize -- OBJC-Line 1837 */ 86+ (LangParser_decl_return *)newLangParser_decl_return 87{ 88return [[[LangParser_decl_return alloc] init] retain]; 89} 90 91- (id) init 92{ 93self = [super init]; 94return self; 95} 96 97/* AST returnScope.methods */ 98- (CommonTree *)getTree 99{ 100 return tree; 101} 102 103- (void) setTree:(CommonTree *)aTree 104{ 105 if (tree != aTree) { 106 if (tree != nil) [tree release]; 107 if (aTree != nil) [aTree retain]; 108 tree = aTree; 109 } 110} 111 112- (void) dealloc 113{ 114 self.tree = nil; 115 [super dealloc]; 116} 117 118 119@end /* end of returnScope implementation */ 120 121@implementation LangParser_type_return /* returnScopeImplementation */ 122/* AST returnScope.synthesize */ 123@synthesize tree; /* start of synthesize -- OBJC-Line 1837 */ 124+ (LangParser_type_return *)newLangParser_type_return 125{ 126return [[[LangParser_type_return alloc] init] retain]; 127} 128 129- (id) init 130{ 131self = [super init]; 132return self; 133} 134 135/* AST returnScope.methods */ 136- (CommonTree *)getTree 137{ 138 return tree; 139} 140 141- (void) setTree:(CommonTree *)aTree 142{ 143 if (tree != aTree) { 144 if (tree != nil) [tree release]; 145 if (aTree != nil) [aTree retain]; 146 tree = aTree; 147 } 148} 149 150- (void) dealloc 151{ 152 self.tree = nil; 153 [super dealloc]; 154} 155 156 157@end /* end of returnScope implementation */ 158 159 160 161@implementation LangParser // line 637 162 163/* ObjC start of ruleAttributeScope */ 164#pragma mark Dynamic Rule Scopes ruleAttributeScope 165/* ObjC end of ruleAttributeScope */ 166#pragma mark global Attribute Scopes globalAttributeScope 167/* ObjC start globalAttributeScope */ 168/* ObjC end globalAttributeScope */ 169/* ObjC start actions.(actionScope).synthesize */ 170/* ObjC start synthesize() */ 171/* AST genericParser.synthesize */ 172/* AST parserProperties */ 173@synthesize treeAdaptor; 174 175+ (void) initialize 176{ 177 #pragma mark Bitsets 178 FOLLOW_decl_in_start41 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_decl_in_start41_data Count:(NSUInteger)1] retain]; 179 FOLLOW_type_in_decl50 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_type_in_decl50_data Count:(NSUInteger)1] retain]; 180 FOLLOW_ID_in_decl52 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_ID_in_decl52_data Count:(NSUInteger)1] retain]; 181 FOLLOW_10_in_decl54 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_10_in_decl54_data Count:(NSUInteger)1] retain]; 182 183 [BaseRecognizer setTokenNames:[[AMutableArray arrayWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>", 184 @"DECL", @"FLOATTYPE", @"ID", @"INT", @"INTTYPE", @"WS", @"';'", nil] retain]]; 185 [BaseRecognizer setGrammarFileName:@"/Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g"]; 186} 187 188+ (LangParser *)newLangParser:(id<TokenStream>)aStream 189{ 190 return [[LangParser alloc] initWithTokenStream:aStream]; 191} 192 193- (id) initWithTokenStream:(id<TokenStream>)aStream 194{ 195 self = [super initWithTokenStream:aStream State:[[RecognizerSharedState newRecognizerSharedStateWithRuleLen:3+1] retain]]; 196 if ( self != nil ) { 197 /* start of actions-actionScope-init */ 198 /* start of init */ 199 /* AST genericParser.init */ 200 [self setTreeAdaptor:[[CommonTreeAdaptor newTreeAdaptor] retain]]; 201 } 202 return self; 203} 204 205- (void) dealloc 206{ 207 /* AST genericParser.dealloc */ 208 [self setTreeAdaptor:nil]; 209 210 [super dealloc]; 211} 212 213/* ObjC start actions.(actionScope).methods */ 214/* ObjC end actions.(actionScope).methods */ 215/* ObjC start methods() */ 216/* AST genericParser.methods */ 217/* AST parserMethods */ 218- (id<TreeAdaptor>) getTreeAdaptor 219{ 220 return treeAdaptor; 221} 222 223- (void) setTreeAdaptor:(id<TreeAdaptor>)aTreeAdaptor 224{ 225 if (aTreeAdaptor != treeAdaptor) { 226 treeAdaptor = aTreeAdaptor; 227 } 228} 229/* ObjC end methods() */ 230/* ObjC start rules */ 231/* 232 * $ANTLR start start 233 * /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g:10:1: start : decl ; 234 */ 235- (LangParser_start_return *) start 236{ 237 /* ruleScopeSetUp */ 238 239 /* AST ruleDeclarations */ 240 /* ruleDeclarations */ 241 LangParser_start_return * retval = [LangParser_start_return newLangParser_start_return]; 242 [retval setStart:[input LT:1]]; 243 244 245 CommonTree *root_0 = nil; 246 247 @try { 248 /* AST ruleLabelDefs */ 249 /* ruleLabelDefs entry */ 250 LangParser_decl_return * decl1 = nil ; 251 252 253 254 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g:10:7: ( decl ) // ruleBlockSingleAlt 255 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g:10:9: decl // alt 256 { 257 root_0 = (CommonTree *)[[[treeAdaptor class] newEmptyTree] retain]; 258 259 260 261 /* ASTParser ruleRef */ 262 /* ruleRef */ 263 [self pushFollow:FOLLOW_decl_in_start41]; 264 decl1 = [self decl]; 265 266 [self popFollow]; 267 268 269 [treeAdaptor addChild:[decl1 getTree] toTree:root_0]; 270 271 } 272 273 /* ASTParser ruleCleanUp */ 274 /* AST ruleCleanUp */ 275 /* token+rule list labels */ 276 [retval setStop:[input LT:-1]]; 277 278 279 280 retval.tree = (CommonTree *)[treeAdaptor rulePostProcessing:root_0]; 281 [treeAdaptor setTokenBoundaries:retval.tree From:retval.start To:retval.stopToken]; 282 283 } 284 @catch (RecognitionException *re) { 285 [self reportError:re]; 286 [self recover:input Exception:re]; 287 /* ASTParser rule.setErrorReturnValue */ 288 retval.tree = (CommonTree *)[treeAdaptor errorNode:input From:retval.start To:[input LT:-1] Exception:re]; 289 290 } 291 292 @finally { 293 /* ruleScopeCleanUp */ 294 295 } 296 return retval; 297} 298/* $ANTLR end start */ 299 300/* 301 * $ANTLR start decl 302 * /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g:12:1: decl : type ID ';' -> ^( DECL type ID ) ; 303 */ 304- (LangParser_decl_return *) decl 305{ 306 /* ruleScopeSetUp */ 307 308 /* AST ruleDeclarations */ 309 /* ruleDeclarations */ 310 LangParser_decl_return * retval = [LangParser_decl_return newLangParser_decl_return]; 311 [retval setStart:[input LT:1]]; 312 313 314 CommonTree *root_0 = nil; 315 316 @try { 317 /* AST ruleLabelDefs */ 318 /* ruleLabelDefs entry */ 319 CommonToken *ID3 = nil; 320 CommonToken *char_literal4 = nil;LangParser_type_return * type2 = nil ; 321 322 323 CommonTree *ID3_tree=nil; 324 CommonTree *char_literal4_tree=nil; 325 RewriteRuleTokenStream *stream_10 = 326 [[RewriteRuleTokenStream newRewriteRuleTokenStream:treeAdaptor 327 description:@"token 10"] retain]; 328 RewriteRuleTokenStream *stream_ID = 329 [[RewriteRuleTokenStream newRewriteRuleTokenStream:treeAdaptor 330 description:@"token ID"] retain]; 331 RewriteRuleSubtreeStream *stream_type = 332 [[RewriteRuleSubtreeStream newRewriteRuleSubtreeStream:treeAdaptor 333 description:@"rule type"] retain]; 334 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g:12:6: ( type ID ';' -> ^( DECL type ID ) ) // ruleBlockSingleAlt 335 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g:12:8: type ID ';' // alt 336 { 337 338 /* ruleRef */ 339 [self pushFollow:FOLLOW_type_in_decl50]; 340 type2 = [self type]; 341 342 [self popFollow]; 343 344 345 [stream_type addElement:[type2 getTree]]; 346 347 ID3=(CommonToken *)[self match:input TokenType:ID Follow:FOLLOW_ID_in_decl52]; 348 [stream_ID addElement:ID3]; 349 350 351 char_literal4=(CommonToken *)[self match:input TokenType:10 Follow:FOLLOW_10_in_decl54]; 352 [stream_10 addElement:char_literal4]; 353 354 355 // AST REWRITE 356 // elements: type, ID 357 // token labels: 358 // rule labels: retval 359 // token list labels: 360 // rule list labels: 361 // wildcard labels: 362 retval.tree = root_0; 363 364 RewriteRuleSubtreeStream *stream_retval = 365 [[RewriteRuleSubtreeStream newRewriteRuleSubtreeStream:treeAdaptor 366 description:@"token retval" element:retval!=nil?[retval getTree]:nil] retain]; 367 368 root_0 = (CommonTree *)[[[treeAdaptor class] newEmptyTree] retain]; 369 370 // 12:20: -> ^( DECL type ID ) 371 { 372 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g:12:23: ^( DECL type ID ) 373 { 374 CommonTree *root_1 = (CommonTree *)[[[treeAdaptor class] newEmptyTree] retain]; 375 root_1 = (CommonTree *)[treeAdaptor becomeRoot: 376 [[treeAdaptor createTree:DECL Text:@"DECL"] retain] 377 old:root_1]; 378 379 [treeAdaptor addChild:[stream_type nextTree] toTree:root_1]; 380 381 // TODO: args: 382 [treeAdaptor addChild: 383 [stream_ID nextNode] 384 toTree:root_1]; 385 386 [treeAdaptor addChild:root_1 toTree:root_0]; 387 } 388 389 } 390 391 392 retval.tree = root_0; 393 394 395 } 396 397 /* ASTParser ruleCleanUp */ 398 /* AST ruleCleanUp */ 399 /* token+rule list labels */ 400 [retval setStop:[input LT:-1]]; 401 402 403 [stream_10 release]; 404 [stream_ID release]; 405 [stream_type release]; 406 407 retval.tree = (CommonTree *)[treeAdaptor rulePostProcessing:root_0]; 408 [treeAdaptor setTokenBoundaries:retval.tree From:retval.start To:retval.stopToken]; 409 410 } 411 @catch (RecognitionException *re) { 412 [self reportError:re]; 413 [self recover:input Exception:re]; 414 /* ASTParser rule.setErrorReturnValue */ 415 retval.tree = (CommonTree *)[treeAdaptor errorNode:input From:retval.start To:[input LT:-1] Exception:re]; 416 417 } 418 419 @finally { 420 /* ruleScopeCleanUp */ 421 422 } 423 return retval; 424} 425/* $ANTLR end decl */ 426 427/* 428 * $ANTLR start type 429 * /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g:14:1: type : ( INTTYPE | FLOATTYPE ); 430 */ 431- (LangParser_type_return *) type 432{ 433 /* ruleScopeSetUp */ 434 435 /* AST ruleDeclarations */ 436 /* ruleDeclarations */ 437 LangParser_type_return * retval = [LangParser_type_return newLangParser_type_return]; 438 [retval setStart:[input LT:1]]; 439 440 441 CommonTree *root_0 = nil; 442 443 @try { 444 /* AST ruleLabelDefs */ 445 /* ruleLabelDefs entry */ 446 CommonToken *set5 = nil; 447 448 CommonTree *set5_tree=nil; 449 450 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g:14:6: ( INTTYPE | FLOATTYPE ) // ruleBlockSingleAlt 451 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treeparser/Lang.g: // alt 452 { 453 root_0 = (CommonTree *)[[[treeAdaptor class] newEmptyTree] retain]; 454 455 456 457 /* ASTParser matchRuleBlockSet */ 458 /* ASTParser matchSet */ 459 set5 = (CommonToken *)[input LT:1]; /* matchSet */ 460 461 if ([input LA:1] == FLOATTYPE||[input LA:1] == INTTYPE) { 462 [input consume]; 463 [treeAdaptor addChild:/* ASTParser createNodeFromToken */ 464 (CommonTree *)[[treeAdaptor create:set5] retain] 465 toTree:root_0 ]; 466 [state setIsErrorRecovery:NO]; 467 } else { 468 MismatchedSetException *mse = [MismatchedSetException newException:nil stream:input]; 469 @throw mse; 470 } 471 472 473 } 474 475 /* ASTParser ruleCleanUp */ 476 /* AST ruleCleanUp */ 477 /* token+rule list labels */ 478 [retval setStop:[input LT:-1]]; 479 480 481 482 retval.tree = (CommonTree *)[treeAdaptor rulePostProcessing:root_0]; 483 [treeAdaptor setTokenBoundaries:retval.tree From:retval.start To:retval.stopToken]; 484 485 } 486 @catch (RecognitionException *re) { 487 [self reportError:re]; 488 [self recover:input Exception:re]; 489 /* ASTParser rule.setErrorReturnValue */ 490 retval.tree = (CommonTree *)[treeAdaptor errorNode:input From:retval.start To:[input LT:-1] Exception:re]; 491 492 } 493 494 @finally { 495 /* ruleScopeCleanUp */ 496 497 } 498 return retval; 499} 500/* $ANTLR end type */ 501/* ObjC end rules */ 502 503@end /* end of LangParser implementation line 692 */ 504