Home | History | Annotate | Download | only in hoistedPredicates
      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/hoistedPredicates/T.g
      5  *     -                            On : 2012-02-16 17:34:26
      6  *     -                for the parser : TParserParser
      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/hoistedPredicates/T.g 2012-02-16 17:34:26
     15 
     16 
     17 /* -----------------------------------------
     18  * Include the ANTLR3 generated header file.
     19  */
     20 #import "TParser.h"
     21 /* ----------------------------------------- */
     22 
     23 /** Demonstrates how semantic predicates get hoisted out of the rule in
     24  *  which they are found and used in other decisions.  This grammar illustrates
     25  *  how predicates can be used to distinguish between enum as a keyword and
     26  *  an ID *dynamically*. :)
     27 
     28  * Run "java org.antlr.Tool -dfa t.g" to generate DOT (graphviz) files.  See
     29  * the T_dec-1.dot file to see the predicates in action.
     30  */
     31 
     32 /* ============================================================================= */
     33 /* =============================================================================
     34  * Start of recognizer
     35  */
     36 
     37 #pragma mark Bitsets
     38 static ANTLRBitSet *FOLLOW_identifier_in_stat34;
     39 static const unsigned long long FOLLOW_identifier_in_stat34_data[] = { 0x0000000000000002LL};
     40 static ANTLRBitSet *FOLLOW_enumAsKeyword_in_stat47;
     41 static const unsigned long long FOLLOW_enumAsKeyword_in_stat47_data[] = { 0x0000000000000002LL};
     42 static ANTLRBitSet *FOLLOW_ID_in_identifier66;
     43 static const unsigned long long FOLLOW_ID_in_identifier66_data[] = { 0x0000000000000002LL};
     44 static ANTLRBitSet *FOLLOW_enumAsID_in_identifier74;
     45 static const unsigned long long FOLLOW_enumAsID_in_identifier74_data[] = { 0x0000000000000002LL};
     46 static ANTLRBitSet *FOLLOW_7_in_enumAsKeyword89;
     47 static const unsigned long long FOLLOW_7_in_enumAsKeyword89_data[] = { 0x0000000000000002LL};
     48 static ANTLRBitSet *FOLLOW_7_in_enumAsID100;
     49 static const unsigned long long FOLLOW_7_in_enumAsID100_data[] = { 0x0000000000000002LL};
     50 
     51 
     52 #pragma mark Dynamic Global globalAttributeScopeImplementation
     53 
     54 #pragma mark Dynamic Rule Scopes ruleAttributeScopeImplementation
     55 
     56 #pragma mark Rule Return Scopes returnScopeImplementation
     57 
     58 @implementation TParser  // line 637
     59 
     60 /* ObjC start of ruleAttributeScope */
     61 #pragma mark Dynamic Rule Scopes ruleAttributeScope
     62 /* ObjC end of ruleAttributeScope */
     63 #pragma mark global Attribute Scopes globalAttributeScope
     64 /* ObjC start globalAttributeScope */
     65 /* ObjC end globalAttributeScope */
     66 /* ObjC start actions.(actionScope).synthesize */
     67 /* ObjC start synthesize() */
     68 
     69 + (void) initialize
     70 {
     71     #pragma mark Bitsets
     72     FOLLOW_identifier_in_stat34 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_identifier_in_stat34_data Count:(NSUInteger)1] retain];
     73     FOLLOW_enumAsKeyword_in_stat47 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_enumAsKeyword_in_stat47_data Count:(NSUInteger)1] retain];
     74     FOLLOW_ID_in_identifier66 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_ID_in_identifier66_data Count:(NSUInteger)1] retain];
     75     FOLLOW_enumAsID_in_identifier74 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_enumAsID_in_identifier74_data Count:(NSUInteger)1] retain];
     76     FOLLOW_7_in_enumAsKeyword89 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_7_in_enumAsKeyword89_data Count:(NSUInteger)1] retain];
     77     FOLLOW_7_in_enumAsID100 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_7_in_enumAsID100_data Count:(NSUInteger)1] retain];
     78 
     79     [BaseRecognizer setTokenNames:[[AMutableArray arrayWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>",
     80  @"ID", @"INT", @"WS", @"'enum'", nil] retain]];
     81     [BaseRecognizer setGrammarFileName:@"/Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g"];
     82 }
     83 
     84 + (TParser *)newTParser:(id<TokenStream>)aStream
     85 {
     86     return [[TParser alloc] initWithTokenStream:aStream];
     87 }
     88 
     89 - (id) initWithTokenStream:(id<TokenStream>)aStream
     90 {
     91     self = [super initWithTokenStream:aStream State:[[RecognizerSharedState newRecognizerSharedStateWithRuleLen:4+1] retain]];
     92     if ( self != nil ) {
     93         /* start of actions-actionScope-init */
     94 
     95         enableEnum = NO;
     96 
     97         /* start of init */
     98     }
     99     return self;
    100 }
    101 
    102 - (void) dealloc
    103 {
    104     [super dealloc];
    105 }
    106 
    107 /* ObjC start actions.(actionScope).methods */
    108 /* ObjC end actions.(actionScope).methods */
    109 /* ObjC start methods() */
    110 /* ObjC end methods() */
    111 /* ObjC start rules */
    112 /*
    113  * $ANTLR start stat
    114  * /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:24:1: stat : ( identifier | enumAsKeyword );
    115  */
    116 - (void) stat
    117 {
    118     /* ruleScopeSetUp */
    119 
    120     /* ruleDeclarations */
    121 
    122     @try {
    123         /* ruleLabelDefs entry */
    124 
    125 
    126         // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:24:5: ( identifier | enumAsKeyword ) //ruleblock
    127         NSInteger alt1=2;
    128         NSInteger LA1_0 = [input LA:1];
    129 
    130         if ( (LA1_0==ID) ) {
    131             alt1=1;
    132         }
    133         else if ( (LA1_0==7) ) {
    134             NSInteger LA1_2 = [input LA:2];
    135 
    136             if ( ((!enableEnum)) ) {
    137                 alt1=1;
    138             }
    139             else if ( ((enableEnum)) ) {
    140                 alt1=2;
    141             }
    142             else {
    143                 NoViableAltException *nvae = [NoViableAltException newException:1 state:2 stream:input];
    144                 nvae.c = LA1_2;
    145                 @throw nvae;
    146 
    147             }
    148         }
    149         else {
    150             NoViableAltException *nvae = [NoViableAltException newException:1 state:0 stream:input];
    151             nvae.c = LA1_0;
    152             @throw nvae;
    153 
    154         }
    155         switch (alt1) {
    156             case 1 : ;
    157                 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:24:7: identifier // alt
    158                 {
    159 
    160                 /* ruleRef */
    161                 [self pushFollow:FOLLOW_identifier_in_stat34];
    162                 [self identifier];
    163 
    164                 [self popFollow];
    165 
    166 
    167 
    168 
    169                 NSLog(@"enum is an ID");
    170 
    171 
    172                 }
    173                 break;
    174             case 2 : ;
    175                 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:25:7: enumAsKeyword // alt
    176                 {
    177 
    178                 /* ruleRef */
    179                 [self pushFollow:FOLLOW_enumAsKeyword_in_stat47];
    180                 [self enumAsKeyword];
    181 
    182                 [self popFollow];
    183 
    184 
    185 
    186 
    187                 NSLog(@"enum is a keyword");
    188 
    189 
    190                 }
    191                 break;
    192 
    193         }
    194         /* token+rule list labels */
    195 
    196     }
    197     @catch (RecognitionException *re) {
    198         [self reportError:re];
    199         [self recover:input Exception:re];
    200     }
    201 
    202     @finally {
    203         /* ruleScopeCleanUp */
    204 
    205     }
    206     return ;
    207 }
    208 /* $ANTLR end stat */
    209 
    210 /*
    211  * $ANTLR start identifier
    212  * /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:28:1: identifier : ( ID | enumAsID );
    213  */
    214 - (void) identifier
    215 {
    216     /* ruleScopeSetUp */
    217 
    218     /* ruleDeclarations */
    219 
    220     @try {
    221         /* ruleLabelDefs entry */
    222 
    223 
    224         // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:29:5: ( ID | enumAsID ) //ruleblock
    225         NSInteger alt2=2;
    226         NSInteger LA2_0 = [input LA:1];
    227 
    228         if ( (LA2_0==ID) ) {
    229             alt2=1;
    230         }
    231         else if ( (LA2_0==7) ) {
    232             alt2=2;
    233         }
    234         else {
    235             NoViableAltException *nvae = [NoViableAltException newException:2 state:0 stream:input];
    236             nvae.c = LA2_0;
    237             @throw nvae;
    238 
    239         }
    240         switch (alt2) {
    241             case 1 : ;
    242                 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:29:7: ID // alt
    243                 {
    244 
    245                 [self match:input TokenType:ID Follow:FOLLOW_ID_in_identifier66];
    246 
    247                 }
    248                 break;
    249             case 2 : ;
    250                 // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:30:7: enumAsID // alt
    251                 {
    252 
    253                 /* ruleRef */
    254                 [self pushFollow:FOLLOW_enumAsID_in_identifier74];
    255                 [self enumAsID];
    256 
    257                 [self popFollow];
    258 
    259 
    260 
    261                 }
    262                 break;
    263 
    264         }
    265         /* token+rule list labels */
    266 
    267     }
    268     @catch (RecognitionException *re) {
    269         [self reportError:re];
    270         [self recover:input Exception:re];
    271     }
    272 
    273     @finally {
    274         /* ruleScopeCleanUp */
    275 
    276     }
    277     return ;
    278 }
    279 /* $ANTLR end identifier */
    280 
    281 /*
    282  * $ANTLR start enumAsKeyword
    283  * /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:33:1: enumAsKeyword :{...}? 'enum' ;
    284  */
    285 - (void) enumAsKeyword
    286 {
    287     /* ruleScopeSetUp */
    288 
    289     /* ruleDeclarations */
    290 
    291     @try {
    292         /* ruleLabelDefs entry */
    293 
    294 
    295         // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:33:15: ({...}? 'enum' ) // ruleBlockSingleAlt
    296         // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:33:17: {...}? 'enum' // alt
    297         {
    298 
    299         if ( !((enableEnum)) ) {
    300             @throw [FailedPredicateException newException:@"enumAsKeyword" predicate:@"enableEnum" stream:input];
    301         }
    302 
    303         [self match:input TokenType:7 Follow:FOLLOW_7_in_enumAsKeyword89];
    304 
    305         }
    306 
    307         /* token+rule list labels */
    308 
    309     }
    310     @catch (RecognitionException *re) {
    311         [self reportError:re];
    312         [self recover:input Exception:re];
    313     }
    314 
    315     @finally {
    316         /* ruleScopeCleanUp */
    317 
    318     }
    319     return ;
    320 }
    321 /* $ANTLR end enumAsKeyword */
    322 
    323 /*
    324  * $ANTLR start enumAsID
    325  * /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:35:1: enumAsID :{...}? 'enum' ;
    326  */
    327 - (void) enumAsID
    328 {
    329     /* ruleScopeSetUp */
    330 
    331     /* ruleDeclarations */
    332 
    333     @try {
    334         /* ruleLabelDefs entry */
    335 
    336 
    337         // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:35:10: ({...}? 'enum' ) // ruleBlockSingleAlt
    338         // /Users/acondit/source/antlr/code/antlr3/runtime/ObjC/Framework/examples/hoistedPredicates/T.g:35:12: {...}? 'enum' // alt
    339         {
    340 
    341         if ( !((!enableEnum)) ) {
    342             @throw [FailedPredicateException newException:@"enumAsID" predicate:@"!enableEnum" stream:input];
    343         }
    344 
    345         [self match:input TokenType:7 Follow:FOLLOW_7_in_enumAsID100];
    346 
    347         }
    348 
    349         /* token+rule list labels */
    350 
    351     }
    352     @catch (RecognitionException *re) {
    353         [self reportError:re];
    354         [self recover:input Exception:re];
    355     }
    356 
    357     @finally {
    358         /* ruleScopeCleanUp */
    359 
    360     }
    361     return ;
    362 }
    363 /* $ANTLR end enumAsID */
    364 /* ObjC end rules */
    365 
    366 @end /* end of TParser implementation line 692 */
    367