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/treerewrite/TreeRewrite.g 5 * - On : 2012-02-16 17:42:35 6 * - for the parser : TreeRewriteParserParser 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/treerewrite/TreeRewrite.g 2012-02-16 17:42:35 15 16 17/* ----------------------------------------- 18 * Include the ANTLR3 generated header file. 19 */ 20#import "TreeRewriteParser.h" 21/* ----------------------------------------- */ 22 23 24/* ============================================================================= */ 25/* ============================================================================= 26 * Start of recognizer 27 */ 28 29#pragma mark Bitsets 30static ANTLRBitSet *FOLLOW_INT_in_rule26; 31static const unsigned long long FOLLOW_INT_in_rule26_data[] = { 0x0000000000000010LL}; 32static ANTLRBitSet *FOLLOW_subrule_in_rule28; 33static const unsigned long long FOLLOW_subrule_in_rule28_data[] = { 0x0000000000000002LL}; 34static ANTLRBitSet *FOLLOW_INT_in_subrule53; 35static const unsigned long long FOLLOW_INT_in_subrule53_data[] = { 0x0000000000000002LL}; 36 37 38#pragma mark Dynamic Global globalAttributeScopeImplementation 39 40#pragma mark Dynamic Rule Scopes ruleAttributeScopeImplementation 41 42#pragma mark Rule Return Scopes returnScopeImplementation 43@implementation TreeRewriteParser_rule_return /* returnScopeImplementation */ 44/* AST returnScope.synthesize */ 45@synthesize tree; /* start of synthesize -- OBJC-Line 1837 */ 46+ (TreeRewriteParser_rule_return *)newTreeRewriteParser_rule_return 47{ 48return [[[TreeRewriteParser_rule_return alloc] init] retain]; 49} 50 51- (id) init 52{ 53self = [super init]; 54return self; 55} 56 57/* AST returnScope.methods */ 58- (CommonTree *)getTree 59{ 60 return tree; 61} 62 63- (void) setTree:(CommonTree *)aTree 64{ 65 if (tree != aTree) { 66 if (tree != nil) [tree release]; 67 if (aTree != nil) [aTree retain]; 68 tree = aTree; 69 } 70} 71 72- (void) dealloc 73{ 74 self.tree = nil; 75 [super dealloc]; 76} 77 78 79@end /* end of returnScope implementation */ 80 81@implementation TreeRewriteParser_subrule_return /* returnScopeImplementation */ 82/* AST returnScope.synthesize */ 83@synthesize tree; /* start of synthesize -- OBJC-Line 1837 */ 84+ (TreeRewriteParser_subrule_return *)newTreeRewriteParser_subrule_return 85{ 86return [[[TreeRewriteParser_subrule_return alloc] init] retain]; 87} 88 89- (id) init 90{ 91self = [super init]; 92return self; 93} 94 95/* AST returnScope.methods */ 96- (CommonTree *)getTree 97{ 98 return tree; 99} 100 101- (void) setTree:(CommonTree *)aTree 102{ 103 if (tree != aTree) { 104 if (tree != nil) [tree release]; 105 if (aTree != nil) [aTree retain]; 106 tree = aTree; 107 } 108} 109 110- (void) dealloc 111{ 112 self.tree = nil; 113 [super dealloc]; 114} 115 116 117@end /* end of returnScope implementation */ 118 119 120 121@implementation TreeRewriteParser // line 637 122 123/* ObjC start of ruleAttributeScope */ 124#pragma mark Dynamic Rule Scopes ruleAttributeScope 125/* ObjC end of ruleAttributeScope */ 126#pragma mark global Attribute Scopes globalAttributeScope 127/* ObjC start globalAttributeScope */ 128/* ObjC end globalAttributeScope */ 129/* ObjC start actions.(actionScope).synthesize */ 130/* ObjC start synthesize() */ 131/* AST genericParser.synthesize */ 132/* AST parserProperties */ 133@synthesize treeAdaptor; 134 135+ (void) initialize 136{ 137 #pragma mark Bitsets 138 FOLLOW_INT_in_rule26 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_INT_in_rule26_data Count:(NSUInteger)1] retain]; 139 FOLLOW_subrule_in_rule28 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_subrule_in_rule28_data Count:(NSUInteger)1] retain]; 140 FOLLOW_INT_in_subrule53 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_INT_in_subrule53_data Count:(NSUInteger)1] retain]; 141 142 [BaseRecognizer setTokenNames:[[AMutableArray arrayWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>", 143 @"INT", @"WS", nil] retain]]; 144 [BaseRecognizer setGrammarFileName:@"/Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treerewrite/TreeRewrite.g"]; 145} 146 147+ (TreeRewriteParser *)newTreeRewriteParser:(id<TokenStream>)aStream 148{ 149 return [[TreeRewriteParser alloc] initWithTokenStream:aStream]; 150} 151 152- (id) initWithTokenStream:(id<TokenStream>)aStream 153{ 154 self = [super initWithTokenStream:aStream State:[[RecognizerSharedState newRecognizerSharedStateWithRuleLen:2+1] retain]]; 155 if ( self != nil ) { 156 /* start of actions-actionScope-init */ 157 /* start of init */ 158 /* AST genericParser.init */ 159 [self setTreeAdaptor:[[CommonTreeAdaptor newTreeAdaptor] retain]]; 160 } 161 return self; 162} 163 164- (void) dealloc 165{ 166 /* AST genericParser.dealloc */ 167 [self setTreeAdaptor:nil]; 168 169 [super dealloc]; 170} 171 172/* ObjC start actions.(actionScope).methods */ 173/* ObjC end actions.(actionScope).methods */ 174/* ObjC start methods() */ 175/* AST genericParser.methods */ 176/* AST parserMethods */ 177- (id<TreeAdaptor>) getTreeAdaptor 178{ 179 return treeAdaptor; 180} 181 182- (void) setTreeAdaptor:(id<TreeAdaptor>)aTreeAdaptor 183{ 184 if (aTreeAdaptor != treeAdaptor) { 185 treeAdaptor = aTreeAdaptor; 186 } 187} 188/* ObjC end methods() */ 189/* ObjC start rules */ 190/* 191 * $ANTLR start rule 192 * /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treerewrite/TreeRewrite.g:8:1: rule : INT subrule -> ^( subrule INT ) ; 193 */ 194- (TreeRewriteParser_rule_return *) rule 195{ 196 /* ruleScopeSetUp */ 197 198 /* AST ruleDeclarations */ 199 /* ruleDeclarations */ 200 TreeRewriteParser_rule_return * retval = [TreeRewriteParser_rule_return newTreeRewriteParser_rule_return]; 201 [retval setStart:[input LT:1]]; 202 203 204 CommonTree *root_0 = nil; 205 206 @try { 207 /* AST ruleLabelDefs */ 208 /* ruleLabelDefs entry */ 209 CommonToken *INT1 = nil;TreeRewriteParser_subrule_return * subrule2 = nil ; 210 211 212 CommonTree *INT1_tree=nil; 213 RewriteRuleTokenStream *stream_INT = 214 [[RewriteRuleTokenStream newRewriteRuleTokenStream:treeAdaptor 215 description:@"token INT"] retain]; 216 RewriteRuleSubtreeStream *stream_subrule = 217 [[RewriteRuleSubtreeStream newRewriteRuleSubtreeStream:treeAdaptor 218 description:@"rule subrule"] retain]; 219 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treerewrite/TreeRewrite.g:8:5: ( INT subrule -> ^( subrule INT ) ) // ruleBlockSingleAlt 220 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treerewrite/TreeRewrite.g:8:7: INT subrule // alt 221 { 222 223 INT1=(CommonToken *)[self match:input TokenType:INT Follow:FOLLOW_INT_in_rule26]; 224 [stream_INT addElement:INT1]; 225 226 227 /* ruleRef */ 228 [self pushFollow:FOLLOW_subrule_in_rule28]; 229 subrule2 = [self subrule]; 230 231 [self popFollow]; 232 233 234 [stream_subrule addElement:[subrule2 getTree]]; 235 236 // AST REWRITE 237 // elements: subrule, INT 238 // token labels: 239 // rule labels: retval 240 // token list labels: 241 // rule list labels: 242 // wildcard labels: 243 retval.tree = root_0; 244 245 RewriteRuleSubtreeStream *stream_retval = 246 [[RewriteRuleSubtreeStream newRewriteRuleSubtreeStream:treeAdaptor 247 description:@"token retval" element:retval!=nil?[retval getTree]:nil] retain]; 248 249 root_0 = (CommonTree *)[[[treeAdaptor class] newEmptyTree] retain]; 250 251 // 8:19: -> ^( subrule INT ) 252 { 253 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treerewrite/TreeRewrite.g:8:22: ^( subrule INT ) 254 { 255 CommonTree *root_1 = (CommonTree *)[[[treeAdaptor class] newEmptyTree] retain]; 256 root_1 = (CommonTree *)[treeAdaptor becomeRoot:(id<Tree>)[stream_subrule nextNode] old:root_1]; 257 258 // TODO: args: 259 [treeAdaptor addChild: 260 [stream_INT nextNode] 261 toTree:root_1]; 262 263 [treeAdaptor addChild:root_1 toTree:root_0]; 264 } 265 266 } 267 268 269 retval.tree = root_0; 270 271 272 } 273 274 /* ASTParser ruleCleanUp */ 275 /* AST ruleCleanUp */ 276 /* token+rule list labels */ 277 [retval setStop:[input LT:-1]]; 278 279 280 [stream_INT release]; 281 [stream_subrule release]; 282 283 retval.tree = (CommonTree *)[treeAdaptor rulePostProcessing:root_0]; 284 [treeAdaptor setTokenBoundaries:retval.tree From:retval.start To:retval.stopToken]; 285 286 } 287 @catch (RecognitionException *re) { 288 [self reportError:re]; 289 [self recover:input Exception:re]; 290 /* ASTParser rule.setErrorReturnValue */ 291 retval.tree = (CommonTree *)[treeAdaptor errorNode:input From:retval.start To:[input LT:-1] Exception:re]; 292 293 } 294 295 @finally { 296 /* ruleScopeCleanUp */ 297 298 } 299 return retval; 300} 301/* $ANTLR end rule */ 302 303/* 304 * $ANTLR start subrule 305 * /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treerewrite/TreeRewrite.g:11:1: subrule : INT ; 306 */ 307- (TreeRewriteParser_subrule_return *) subrule 308{ 309 /* ruleScopeSetUp */ 310 311 /* AST ruleDeclarations */ 312 /* ruleDeclarations */ 313 TreeRewriteParser_subrule_return * retval = [TreeRewriteParser_subrule_return newTreeRewriteParser_subrule_return]; 314 [retval setStart:[input LT:1]]; 315 316 317 CommonTree *root_0 = nil; 318 319 @try { 320 /* AST ruleLabelDefs */ 321 /* ruleLabelDefs entry */ 322 CommonToken *INT3 = nil; 323 324 CommonTree *INT3_tree=nil; 325 326 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treerewrite/TreeRewrite.g:12:5: ( INT ) // ruleBlockSingleAlt 327 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/treerewrite/TreeRewrite.g:12:9: INT // alt 328 { 329 root_0 = (CommonTree *)[[[treeAdaptor class] newEmptyTree] retain]; 330 331 332 333 /* ASTParser tokenRef */ 334 INT3=(CommonToken *)[self match:input TokenType:INT Follow:FOLLOW_INT_in_subrule53]; 335 INT3_tree = /* ASTParser createNodeFromToken */ 336 (CommonTree *)[[treeAdaptor create:INT3] retain] 337 ; 338 [treeAdaptor addChild:INT3_tree toTree:root_0]; 339 340 341 } 342 343 /* ASTParser ruleCleanUp */ 344 /* AST ruleCleanUp */ 345 /* token+rule list labels */ 346 [retval setStop:[input LT:-1]]; 347 348 349 350 retval.tree = (CommonTree *)[treeAdaptor rulePostProcessing:root_0]; 351 [treeAdaptor setTokenBoundaries:retval.tree From:retval.start To:retval.stopToken]; 352 353 } 354 @catch (RecognitionException *re) { 355 [self reportError:re]; 356 [self recover:input Exception:re]; 357 /* ASTParser rule.setErrorReturnValue */ 358 retval.tree = (CommonTree *)[treeAdaptor errorNode:input From:retval.start To:[input LT:-1] Exception:re]; 359 360 } 361 362 @finally { 363 /* ruleScopeCleanUp */ 364 365 } 366 return retval; 367} 368/* $ANTLR end subrule */ 369/* ObjC end rules */ 370 371@end /* end of TreeRewriteParser implementation line 692 */ 372