1/** \file 2 * This OBJC source file was generated by $ANTLR version 3.2 Aug 20, 2010 15:00:19 3 * 4 * - From the grammar source file : /usr/local/ANTLR3-ObjC2.0-Runtime/Framework/examples/treerewrite/TreeRewrite.g 5 * - On : 2010-08-20 15:03:14 6 * - for the parser : TreeRewriteParserParser * 7 * Editing it, at least manually, is not wise. 8 * 9 * C language generator and runtime by Jim Idle, jimi|hereisanat|idle|dotgoeshere|ws. 10 * 11 * 12*/ 13// [The "BSD licence"] 14// Copyright (c) 2010 Alan Condit 15// 16// All rights reserved. 17// 18// Redistribution and use in source and binary forms, with or without 19// modification, are permitted provided that the following conditions 20// are met: 21// 1. Redistributions of source code must retain the above copyright 22// notice, this list of conditions and the following disclaimer. 23// 2. Redistributions in binary form must reproduce the above copyright 24// notice, this list of conditions and the following disclaimer in the 25// documentation and/or other materials provided with the distribution. 26// 3. The name of the author may not be used to endorse or promote products 27// derived from this software without specific prior written permission. 28// 29// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 30// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 31// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 32// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 33// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 34// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 38// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 40// $ANTLR 3.2 Aug 20, 2010 15:00:19 /usr/local/ANTLR3-ObjC2.0-Runtime/Framework/examples/treerewrite/TreeRewrite.g 2010-08-20 15:03:14 41 42/* ----------------------------------------- 43 * Include the ANTLR3 generated header file. 44 */ 45#import "TreeRewriteParser.h" 46/* ----------------------------------------- */ 47 48 49/* ============================================================================= */ 50 51/* ============================================================================= 52 * Start of recognizer 53 */ 54 55 56 57#pragma mark Bitsets 58static ANTLRBitSet *FOLLOW_INT_in_rule26; 59 60const unsigned long long FOLLOW_INT_in_rule26_data[] = { 0x0000000000000010LL}; 61 62static ANTLRBitSet *FOLLOW_subrule_in_rule28; 63 64const unsigned long long FOLLOW_subrule_in_rule28_data[] = { 0x0000000000000002LL}; 65 66static ANTLRBitSet *FOLLOW_INT_in_subrule53; 67 68const unsigned long long FOLLOW_INT_in_subrule53_data[] = { 0x0000000000000002LL}; 69 70 71 72#pragma mark Dynamic Global Scopes 73 74#pragma mark Dynamic Rule Scopes 75 76#pragma mark Rule return scopes start 77@implementation TreeRewriteParser_rule_return 78@synthesize tree; 79+ (TreeRewriteParser_rule_return *)newTreeRewriteParser_rule_return 80{ 81 return [[[TreeRewriteParser_rule_return alloc] init] retain]; 82} 83 84// returnScope.methods 85- (ANTLRCommonTree *)getTree 86{ 87 return tree; 88} 89 90- (void) setTree:(ANTLRCommonTree *)aTree 91{ 92 if (tree != aTree) { 93 if (tree != nil) [tree release]; 94 if (aTree != nil) [aTree retain]; 95 tree = aTree; 96 } 97} 98 99- (void) dealloc 100{ 101 [self setTree:nil]; 102 [super dealloc]; 103} 104 105 106 107 108@end 109 110@implementation TreeRewriteParser_subrule_return 111@synthesize tree; 112+ (TreeRewriteParser_subrule_return *)newTreeRewriteParser_subrule_return 113{ 114 return [[[TreeRewriteParser_subrule_return alloc] init] retain]; 115} 116 117// returnScope.methods 118- (ANTLRCommonTree *)getTree 119{ 120 return tree; 121} 122 123- (void) setTree:(ANTLRCommonTree *)aTree 124{ 125 if (tree != aTree) { 126 if (tree != nil) [tree release]; 127 if (aTree != nil) [aTree retain]; 128 tree = aTree; 129 } 130} 131 132- (void) dealloc 133{ 134 [self setTree:nil]; 135 [super dealloc]; 136} 137 138 139 140 141@end 142 143 144 145@implementation TreeRewriteParser // line 610 146 147+ (void) initialize 148{ 149 FOLLOW_INT_in_rule26 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_INT_in_rule26_data Count:(NSUInteger)1] retain]; 150 FOLLOW_subrule_in_rule28 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_subrule_in_rule28_data Count:(NSUInteger)1] retain]; 151 FOLLOW_INT_in_subrule53 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_INT_in_subrule53_data Count:(NSUInteger)1] retain]; 152 153 [ANTLRBaseRecognizer setTokenNames:[[[NSArray alloc] initWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>", 154 @"INT", @"WS", nil] retain]]; 155} 156 157+ (TreeRewriteParser *)newTreeRewriteParser:(id<ANTLRTokenStream>)aStream 158{ 159 return [[TreeRewriteParser alloc] initWithTokenStream:aStream]; 160 161} 162 163- (id) initWithTokenStream:(id<ANTLRTokenStream>)aStream 164{ 165 if ((self = [super initWithTokenStream:aStream State:[[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:2+1] retain]]) != nil) { 166 167 168 169 // start of actions-actionScope-init 170 // start of init 171 // genericParser.init 172 [self setTreeAdaptor:[[ANTLRCommonTreeAdaptor newANTLRCommonTreeAdaptor] retain]]; 173 } 174 return self; 175} 176 177- (void) dealloc 178{ 179 [self setTreeAdaptor:nil]; 180 181 [super dealloc]; 182} 183// start actions.actionScope.methods 184// start methods() 185// genericParser.methods 186// parserMethods 187- (id<ANTLRTreeAdaptor>) getTreeAdaptor 188{ 189 return treeAdaptor; 190} 191 192- (void) setTreeAdaptor:(id<ANTLRTreeAdaptor>)aTreeAdaptor 193{ 194 if (aTreeAdaptor != treeAdaptor) { 195 treeAdaptor = aTreeAdaptor; 196 } 197} 198// start rules 199/* 200 * $ANTLR start rule 201 * /usr/local/ANTLR3-ObjC2.0-Runtime/Framework/examples/treerewrite/TreeRewrite.g:8:1: rule : INT subrule -> ^( subrule INT ) ; 202 */ 203- (TreeRewriteParser_rule_return *) rule 204{ 205 // ruleScopeSetUp 206 207 // ruleDeclarations 208 TreeRewriteParser_rule_return * retval = [TreeRewriteParser_rule_return newTreeRewriteParser_rule_return]; 209 [retval setStart:[input LT:1]]; 210 211 ANTLRCommonTree *root_0 = nil; 212 213 @try { 214 // ruleLabelDefs 215 id<ANTLRToken> INT1 = nil; 216 TreeRewriteParser_subrule_return * subrule2 = nil; 217 218 219 ANTLRCommonTree *INT1_tree=nil; 220 ANTLRRewriteRuleTokenStream *stream_INT = 221 [[ANTLRRewriteRuleTokenStream newANTLRRewriteRuleTokenStream:treeAdaptor 222 description:@"token INT"] retain]; 223 ANTLRRewriteRuleSubtreeStream *stream_subrule = 224 [[ANTLRRewriteRuleSubtreeStream newANTLRRewriteRuleSubtreeStream:treeAdaptor 225 description:@"rule subrule"] retain]; 226 // /usr/local/ANTLR3-ObjC2.0-Runtime/Framework/examples/treerewrite/TreeRewrite.g:8:5: ( INT subrule -> ^( subrule INT ) ) // ruleBlockSingleAlt 227 // /usr/local/ANTLR3-ObjC2.0-Runtime/Framework/examples/treerewrite/TreeRewrite.g:8:7: INT subrule // alt 228 { 229 INT1=(id<ANTLRToken>)[self match:input TokenType:INT Follow:FOLLOW_INT_in_rule26]; 230 [stream_INT addElement:INT1]; 231 /* element() */ 232 [self pushFollow:FOLLOW_subrule_in_rule28]; 233 subrule2 = [self subrule]; 234 [self popFollow]; 235 236 237 [stream_subrule addElement:[subrule2 getTree]]; /* element() */ 238 /* elements */ 239 240 // AST REWRITE 241 // elements: INT, subrule 242 // token labels: 243 // rule labels: retval 244 // token list labels: 245 // rule list labels: 246 // wildcard labels: 247 [retval setTree:root_0]; 248 249 retval.tree = root_0; 250 251 ANTLRRewriteRuleSubtreeStream *stream_retval = 252 [[ANTLRRewriteRuleSubtreeStream newANTLRRewriteRuleSubtreeStream:treeAdaptor 253 description:@"token retval" 254 element:retval!=nil?[retval getTree]:nil] retain]; 255 256 root_0 = (ANTLRCommonTree *)[[[treeAdaptor class] newEmptyTree] retain]; 257 258 // 8:19: -> ^( subrule INT ) 259 { 260 // /usr/local/ANTLR3-ObjC2.0-Runtime/Framework/examples/treerewrite/TreeRewrite.g:8:22: ^( subrule INT ) 261 { 262 ANTLRCommonTree *root_1 = (ANTLRCommonTree *)[[[treeAdaptor class] newEmptyTree] retain]; 263 root_1 = (ANTLRCommonTree *)[treeAdaptor becomeRoot:(id<ANTLRTree>)[stream_subrule nextNode] 264 old:root_1]; 265 266 // TODO: args: 267 [treeAdaptor addChild:[stream_INT nextNode] toTree:root_1]; 268 269 [treeAdaptor addChild:root_1 toTree:root_0]; 270 } 271 272 } 273 274 retval.tree = root_0; 275 276 } 277 278 // token+rule list labels 279 [retval setStop:[input LT:-1]]; 280 281 [stream_INT release]; 282 [stream_subrule release]; 283 284 retval.tree = (ANTLRCommonTree *)[treeAdaptor rulePostProcessing:root_0]; 285 [treeAdaptor setTokenBoundaries:retval.tree From:retval.startToken To:retval.stopToken]; 286 287 } 288 @catch (ANTLRRecognitionException *re) { 289 [self reportError:re]; 290 [self recover:input Exception:re]; 291 retval.tree = (ANTLRCommonTree *)[treeAdaptor errorNode:input From:retval.startToken To:[input LT:-1] Exception:re]; 292 293 } @finally { 294 } 295 return retval; 296} 297/* $ANTLR end rule */ 298/* 299 * $ANTLR start subrule 300 * /usr/local/ANTLR3-ObjC2.0-Runtime/Framework/examples/treerewrite/TreeRewrite.g:11:1: subrule : INT ; 301 */ 302- (TreeRewriteParser_subrule_return *) subrule 303{ 304 // ruleScopeSetUp 305 306 // ruleDeclarations 307 TreeRewriteParser_subrule_return * retval = [TreeRewriteParser_subrule_return newTreeRewriteParser_subrule_return]; 308 [retval setStart:[input LT:1]]; 309 310 ANTLRCommonTree *root_0 = nil; 311 312 @try { 313 // ruleLabelDefs 314 id<ANTLRToken> INT3 = nil; 315 316 ANTLRCommonTree *INT3_tree=nil; 317 318 // /usr/local/ANTLR3-ObjC2.0-Runtime/Framework/examples/treerewrite/TreeRewrite.g:12:5: ( INT ) // ruleBlockSingleAlt 319 // /usr/local/ANTLR3-ObjC2.0-Runtime/Framework/examples/treerewrite/TreeRewrite.g:12:9: INT // alt 320 { 321 root_0 = (ANTLRCommonTree *)[[[treeAdaptor class] newEmptyTree] retain]; 322 323 INT3=(id<ANTLRToken>)[self match:input TokenType:INT Follow:FOLLOW_INT_in_subrule53]; 324 INT3_tree = (ANTLRCommonTree *)[[treeAdaptor createTree:INT3] retain]; 325 [treeAdaptor addChild:INT3_tree toTree:root_0]; 326 /* element() */ 327 /* elements */ 328 } 329 330 // token+rule list labels 331 [retval setStop:[input LT:-1]]; 332 333 334 retval.tree = (ANTLRCommonTree *)[treeAdaptor rulePostProcessing:root_0]; 335 [treeAdaptor setTokenBoundaries:retval.tree From:retval.startToken To:retval.stopToken]; 336 337 } 338 @catch (ANTLRRecognitionException *re) { 339 [self reportError:re]; 340 [self recover:input Exception:re]; 341 retval.tree = (ANTLRCommonTree *)[treeAdaptor errorNode:input From:retval.startToken To:[input LT:-1] Exception:re]; 342 343 } @finally { 344 } 345 return retval; 346} 347/* $ANTLR end subrule */ 348 349@end /* end of TreeRewriteParser implementation line 669 */ 350 351 352/* End of code 353 * ============================================================================= 354 */ 355