Home | History | Annotate | Download | only in treerewrite
      1 /** \file
      2  *  This OBJC source file was generated by $ANTLR version ${project.version} ${buildNumber}
      3  *
      4  *     -  From the grammar source file : TreeRewrite.g
      5  *     -                            On : 2011-05-06 18:56:28
      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 ${project.version} ${buildNumber} TreeRewrite.g 2011-05-06 18:56:28
     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
     30 static ANTLRBitSet *FOLLOW_INT_in_rule26;
     31 static const unsigned long long FOLLOW_INT_in_rule26_data[] = { 0x0000000000000010LL};
     32 static ANTLRBitSet *FOLLOW_subrule_in_rule28;
     33 static const unsigned long long FOLLOW_subrule_in_rule28_data[] = { 0x0000000000000002LL};
     34 static ANTLRBitSet *FOLLOW_INT_in_subrule53;
     35 static const unsigned long long FOLLOW_INT_in_subrule53_data[] = { 0x0000000000000002LL};
     36 
     37 
     38 #pragma mark Dynamic Global Scopes
     39 
     40 #pragma mark Dynamic Rule Scopes
     41 
     42 #pragma mark Rule Return Scopes start
     43 @implementation TreeRewriteParser_rule_return /* returnScope */
     44 /* AST returnScope.synthesize */
     45 @synthesize tree; /* start of synthesize -- OBJC-Line 1837 */
     46 + (TreeRewriteParser_rule_return *)newTreeRewriteParser_rule_return
     47 {
     48     return [[[TreeRewriteParser_rule_return alloc] init] retain];
     49 }
     50 
     51 - (id) init
     52 {
     53     self = [super init];
     54     return self;
     55 }
     56 
     57 /* AST returnScope.methods */
     58 - (ANTLRCommonTree *)getTree
     59 {
     60     return tree;
     61 }
     62 
     63 - (void) setTree:(ANTLRCommonTree *)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 
     80 @end /* end of returnScope implementation */
     81 
     82 
     83 @implementation TreeRewriteParser_subrule_return /* returnScope */
     84 /* AST returnScope.synthesize */
     85 @synthesize tree; /* start of synthesize -- OBJC-Line 1837 */
     86 + (TreeRewriteParser_subrule_return *)newTreeRewriteParser_subrule_return
     87 {
     88     return [[[TreeRewriteParser_subrule_return alloc] init] retain];
     89 }
     90 
     91 - (id) init
     92 {
     93     self = [super init];
     94     return self;
     95 }
     96 
     97 /* AST returnScope.methods */
     98 - (ANTLRCommonTree *)getTree
     99 {
    100     return tree;
    101 }
    102 
    103 - (void) setTree:(ANTLRCommonTree *)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 
    120 @end /* end of returnScope implementation */
    121 
    122 
    123 //#pragma mark Rule return scopes start
    124 //
    125 
    126 #pragma mark Rule return scopes start
    127 
    128 @implementation TreeRewriteParser  // line 637
    129 
    130 /* ObjC start of ruleAttributeScope */
    131 #pragma mark Dynamic Rule Scopes
    132 /* ObjC end of ruleAttributeScope */
    133 #pragma mark global Attribute Scopes
    134 /* ObjC start globalAttributeScope */
    135 /* ObjC end globalAttributeScope */
    136 /* ObjC start actions.(actionScope).synthesize */
    137 /* ObjC end actions.(actionScope).synthesize */
    138 /* ObjC start synthesize() */
    139 /* AST genericParser.synthesize */
    140 /* AST parserProperties */
    141 @synthesize treeAdaptor;
    142 /* ObjC end synthesize() */
    143 
    144 + (void) initialize
    145 {
    146     #pragma mark Bitsets
    147     FOLLOW_INT_in_rule26 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_INT_in_rule26_data Count:(NSUInteger)1] retain];
    148     FOLLOW_subrule_in_rule28 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_subrule_in_rule28_data Count:(NSUInteger)1] retain];
    149     FOLLOW_INT_in_subrule53 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_INT_in_subrule53_data Count:(NSUInteger)1] retain];
    150 
    151     [ANTLRBaseRecognizer setTokenNames:[[AMutableArray arrayWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>",
    152  @"INT", @"WS", nil] retain]];
    153     [ANTLRBaseRecognizer setGrammarFileName:@"TreeRewrite.g"];
    154 }
    155 
    156 + (TreeRewriteParser *)newTreeRewriteParser:(id<ANTLRTokenStream>)aStream
    157 {
    158     return [[TreeRewriteParser alloc] initWithTokenStream:aStream];
    159 
    160 
    161 }
    162 
    163 - (id) initWithTokenStream:(id<ANTLRTokenStream>)aStream
    164 {
    165     self = [super initWithTokenStream:aStream State:[[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:2+1] retain]];
    166     if ( self != nil ) {
    167 
    168 
    169         /* start of actions-actionScope-init */
    170         /* start of init */
    171         /* AST genericParser.init */
    172         [self setTreeAdaptor:[[ANTLRCommonTreeAdaptor newTreeAdaptor] retain]];
    173     }
    174     return self;
    175 }
    176 
    177 - (void) dealloc
    178 {
    179     /* AST genericParser.dealloc */
    180     [self setTreeAdaptor:nil];
    181 
    182     [super dealloc];
    183 }
    184 
    185 /* ObjC start members */
    186 /* ObjC end members */
    187 /* ObjC start actions.(actionScope).methods */
    188 /* ObjC end actions.(actionScope).methods */
    189 /* ObjC start methods() */
    190 /* AST genericParser.methods */
    191 /* AST parserMethods */
    192 - (id<ANTLRTreeAdaptor>) getTreeAdaptor
    193 {
    194 	return treeAdaptor;
    195 }
    196 
    197 - (void) setTreeAdaptor:(id<ANTLRTreeAdaptor>)aTreeAdaptor
    198 {
    199 	if (aTreeAdaptor != treeAdaptor) {
    200 		treeAdaptor = aTreeAdaptor;
    201 	}
    202 }
    203 /* ObjC end methods() */
    204 /* ObjC start rules */
    205 /*
    206  * $ANTLR start rule
    207  * TreeRewrite.g:8:1: rule : INT subrule -> ^( subrule INT ) ;
    208  */
    209 - (TreeRewriteParser_rule_return *) rule
    210 {
    211     /* my ruleScopeSetUp */
    212     /* Terence's stuff */
    213 
    214     /* AST ruleDeclarations */
    215     TreeRewriteParser_rule_return * retval = [TreeRewriteParser_rule_return newTreeRewriteParser_rule_return];
    216     [retval setStart:[input LT:1]];
    217 
    218 
    219     ANTLRCommonTree *root_0 = nil;
    220 
    221     @try {
    222         /* AST ruleLabelDefs */
    223         ANTLRCommonToken *INT1 = nil;
    224          TreeRewriteParser_subrule_return * subrule2 = nil ;
    225 
    226 
    227         ANTLRCommonTree *INT1_tree=nil;
    228         ANTLRRewriteRuleTokenStream *stream_INT =
    229             [[ANTLRRewriteRuleTokenStream newANTLRRewriteRuleTokenStream:treeAdaptor
    230                                                              description:@"token INT"] retain];
    231         ANTLRRewriteRuleSubtreeStream *stream_subrule =
    232             [[ANTLRRewriteRuleSubtreeStream newANTLRRewriteRuleSubtreeStream:treeAdaptor
    233                                                                 description:@"rule subrule"] retain];
    234         // TreeRewrite.g:8:5: ( INT subrule -> ^( subrule INT ) ) // ruleBlockSingleAlt
    235         // TreeRewrite.g:8:7: INT subrule // alt
    236         {
    237         INT1=(ANTLRCommonToken *)[self match:input TokenType:INT Follow:FOLLOW_INT_in_rule26];
    238             [stream_INT addElement:INT1];
    239 
    240 
    241         /* ruleRef */
    242         [self pushFollow:FOLLOW_subrule_in_rule28];
    243         subrule2 = [self subrule];
    244 
    245         [self popFollow];
    246 
    247 
    248         [stream_subrule addElement:[subrule2 getTree]];
    249 
    250         // AST REWRITE
    251         // elements: subrule, INT
    252         // token labels:
    253         // rule labels: retval
    254         // token list labels:
    255         // rule list labels:
    256         // wildcard labels:
    257         retval.tree = root_0;
    258 
    259         ANTLRRewriteRuleSubtreeStream *stream_retval =
    260             [[ANTLRRewriteRuleSubtreeStream newANTLRRewriteRuleSubtreeStream:treeAdaptor
    261                 description:@"token retval" element:retval!=nil?[retval getTree]:nil] retain];
    262 
    263         root_0 = (ANTLRCommonTree *)[[[treeAdaptor class] newEmptyTree] retain];
    264 
    265         // 8:19: -> ^( subrule INT )
    266         {
    267             // TreeRewrite.g:8:22: ^( subrule INT )
    268             {
    269                 ANTLRCommonTree *root_1 = (ANTLRCommonTree *)[[[treeAdaptor class] newEmptyTree] retain];
    270                 root_1 = (ANTLRCommonTree *)[treeAdaptor becomeRoot:(id<ANTLRTree>)[stream_subrule nextNode] old:root_1];
    271 
    272                  // TODO: args:
    273                 [treeAdaptor addChild:
    274                             [stream_INT nextNode]
    275                  toTree:root_1];
    276 
    277                 [treeAdaptor addChild:root_1 toTree:root_0];
    278             }
    279 
    280         }
    281 
    282 
    283         retval.tree = root_0;
    284 
    285 
    286         }
    287 
    288         /* ASTParser ruleCleanUp */
    289         /* AST ruleCleanUp */
    290         // token+rule list labels
    291         [retval setStop:[input LT:-1]];
    292 
    293 
    294         [stream_INT release];
    295         [stream_subrule release];
    296 
    297             retval.tree = (ANTLRCommonTree *)[treeAdaptor rulePostProcessing:root_0];
    298             [treeAdaptor setTokenBoundaries:retval.tree From:retval.start To:retval.stopToken];
    299 
    300     }
    301     @catch (ANTLRRecognitionException *re) {
    302         [self reportError:re];
    303         [self recover:input Exception:re];
    304         /* ASTParser rule.setErrorReturnValue */
    305         retval.tree = (ANTLRCommonTree *)[treeAdaptor errorNode:input From:retval.start To:[input LT:-1] Exception:re];
    306 
    307     }
    308 
    309     @finally {
    310         /* Terence's stuff */
    311 
    312     }
    313     return retval;
    314 }
    315 /* $ANTLR end rule */
    316 
    317 /*
    318  * $ANTLR start subrule
    319  * TreeRewrite.g:11:1: subrule : INT ;
    320  */
    321 - (TreeRewriteParser_subrule_return *) subrule
    322 {
    323     /* my ruleScopeSetUp */
    324     /* Terence's stuff */
    325 
    326     /* AST ruleDeclarations */
    327     TreeRewriteParser_subrule_return * retval = [TreeRewriteParser_subrule_return newTreeRewriteParser_subrule_return];
    328     [retval setStart:[input LT:1]];
    329 
    330 
    331     ANTLRCommonTree *root_0 = nil;
    332 
    333     @try {
    334         /* AST ruleLabelDefs */
    335         ANTLRCommonToken *INT3 = nil;
    336 
    337         ANTLRCommonTree *INT3_tree=nil;
    338 
    339         // TreeRewrite.g:12:5: ( INT ) // ruleBlockSingleAlt
    340         // TreeRewrite.g:12:9: INT // alt
    341         {
    342         root_0 = (ANTLRCommonTree *)[[[treeAdaptor class] newEmptyTree] retain];
    343 
    344 
    345         /* ASTParser tokenRef */
    346         INT3=(ANTLRCommonToken *)[self match:input TokenType:INT Follow:FOLLOW_INT_in_subrule53];
    347         INT3_tree = /* ASTParser createNodeFromToken */
    348         (ANTLRCommonTree *)[[treeAdaptor create:INT3] retain]
    349         ;
    350         [treeAdaptor addChild:INT3_tree  toTree:root_0];
    351 
    352 
    353         }
    354 
    355         /* ASTParser ruleCleanUp */
    356         /* AST ruleCleanUp */
    357         // token+rule list labels
    358         [retval setStop:[input LT:-1]];
    359 
    360 
    361 
    362             retval.tree = (ANTLRCommonTree *)[treeAdaptor rulePostProcessing:root_0];
    363             [treeAdaptor setTokenBoundaries:retval.tree From:retval.start To:retval.stopToken];
    364 
    365     }
    366     @catch (ANTLRRecognitionException *re) {
    367         [self reportError:re];
    368         [self recover:input Exception:re];
    369         /* ASTParser rule.setErrorReturnValue */
    370         retval.tree = (ANTLRCommonTree *)[treeAdaptor errorNode:input From:retval.start To:[input LT:-1] Exception:re];
    371 
    372     }
    373 
    374     @finally {
    375         /* Terence's stuff */
    376 
    377     }
    378     return retval;
    379 }
    380 /* $ANTLR end subrule */
    381 /* ObjC end rules */
    382 
    383 @end /* end of TreeRewriteParser implementation line 692 */
    384