1/** \file
2 *  This OBJC source file was generated by $ANTLR version ${project.version} ${buildNumber}
3 *
4 *     -  From the grammar source file : T.g
5 *     -                            On : 2011-05-06 19:14:23
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 ${project.version} ${buildNumber} T.g 2011-05-06 19:14:23
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
38static ANTLRBitSet *FOLLOW_identifier_in_stat34;
39static const unsigned long long FOLLOW_identifier_in_stat34_data[] = { 0x0000000000000002LL};
40static ANTLRBitSet *FOLLOW_enumAsKeyword_in_stat47;
41static const unsigned long long FOLLOW_enumAsKeyword_in_stat47_data[] = { 0x0000000000000002LL};
42static ANTLRBitSet *FOLLOW_ID_in_identifier66;
43static const unsigned long long FOLLOW_ID_in_identifier66_data[] = { 0x0000000000000002LL};
44static ANTLRBitSet *FOLLOW_enumAsID_in_identifier74;
45static const unsigned long long FOLLOW_enumAsID_in_identifier74_data[] = { 0x0000000000000002LL};
46static ANTLRBitSet *FOLLOW_7_in_enumAsKeyword89;
47static const unsigned long long FOLLOW_7_in_enumAsKeyword89_data[] = { 0x0000000000000002LL};
48static ANTLRBitSet *FOLLOW_7_in_enumAsID100;
49static const unsigned long long FOLLOW_7_in_enumAsID100_data[] = { 0x0000000000000002LL};
50
51
52#pragma mark Dynamic Global Scopes
53
54#pragma mark Dynamic Rule Scopes
55
56#pragma mark Rule Return Scopes start
57//#pragma mark Rule return scopes start
58//
59
60#pragma mark Rule return scopes start
61
62@implementation TParser  // line 637
63
64/* ObjC start of ruleAttributeScope */
65#pragma mark Dynamic Rule Scopes
66/* ObjC end of ruleAttributeScope */
67#pragma mark global Attribute Scopes
68/* ObjC start globalAttributeScope */
69/* ObjC end globalAttributeScope */
70/* ObjC start actions.(actionScope).synthesize */
71/* ObjC end actions.(actionScope).synthesize */
72/* ObjC start synthesize() */
73/* ObjC end synthesize() */
74
75+ (void) initialize
76{
77    #pragma mark Bitsets
78    FOLLOW_identifier_in_stat34 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_identifier_in_stat34_data Count:(NSUInteger)1] retain];
79    FOLLOW_enumAsKeyword_in_stat47 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_enumAsKeyword_in_stat47_data Count:(NSUInteger)1] retain];
80    FOLLOW_ID_in_identifier66 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_ID_in_identifier66_data Count:(NSUInteger)1] retain];
81    FOLLOW_enumAsID_in_identifier74 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_enumAsID_in_identifier74_data Count:(NSUInteger)1] retain];
82    FOLLOW_7_in_enumAsKeyword89 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_7_in_enumAsKeyword89_data Count:(NSUInteger)1] retain];
83    FOLLOW_7_in_enumAsID100 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_7_in_enumAsID100_data Count:(NSUInteger)1] retain];
84
85    [ANTLRBaseRecognizer setTokenNames:[[AMutableArray arrayWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>",
86 @"ID", @"INT", @"WS", @"'enum'", nil] retain]];
87    [ANTLRBaseRecognizer setGrammarFileName:@"T.g"];
88}
89
90+ (TParser *)newTParser:(id<ANTLRTokenStream>)aStream
91{
92    return [[TParser alloc] initWithTokenStream:aStream];
93
94
95}
96
97- (id) initWithTokenStream:(id<ANTLRTokenStream>)aStream
98{
99    self = [super initWithTokenStream:aStream State:[[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:4+1] retain]];
100    if ( self != nil ) {
101
102
103        /* start of actions-actionScope-init */
104
105        enableEnum = NO;
106
107        /* start of init */
108    }
109    return self;
110}
111
112- (void) dealloc
113{
114    [super dealloc];
115}
116
117/* ObjC start members */
118/* ObjC end members */
119/* ObjC start actions.(actionScope).methods */
120/* ObjC end actions.(actionScope).methods */
121/* ObjC start methods() */
122/* ObjC end methods() */
123/* ObjC start rules */
124/*
125 * $ANTLR start stat
126 * T.g:24:1: stat : ( identifier | enumAsKeyword );
127 */
128- (void) stat
129{
130    /* my ruleScopeSetUp */
131    /* Terence's stuff */
132
133    @try {
134        // T.g:24:5: ( identifier | enumAsKeyword ) //ruleblock
135        NSInteger alt1=2;
136        NSInteger LA1_0 = [input LA:1];
137
138        if ( (LA1_0==ID) ) {
139            alt1=1;
140        }
141        else if ( (LA1_0==7) ) {
142            NSInteger LA1_2 = [input LA:2];
143
144            if ( ((!enableEnum)) ) {
145                alt1=1;
146            }
147            else if ( ((enableEnum)) ) {
148                alt1=2;
149            }
150            else {
151                ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException newException:1 state:2 stream:input];
152                nvae.c = LA1_2;
153                @throw nvae;
154
155            }
156        }
157        else {
158            ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException newException:1 state:0 stream:input];
159            nvae.c = LA1_0;
160            @throw nvae;
161
162        }
163        switch (alt1) {
164            case 1 : ;
165                // T.g:24:7: identifier // alt
166                {
167                /* ruleRef */
168                [self pushFollow:FOLLOW_identifier_in_stat34];
169                [self identifier];
170
171                [self popFollow];
172
173
174
175                NSLog(@"enum is an ID");
176
177
178                }
179                break;
180            case 2 : ;
181                // T.g:25:7: enumAsKeyword // alt
182                {
183                /* ruleRef */
184                [self pushFollow:FOLLOW_enumAsKeyword_in_stat47];
185                [self enumAsKeyword];
186
187                [self popFollow];
188
189
190
191                NSLog(@"enum is a keyword");
192
193
194                }
195                break;
196
197        }
198        // token+rule list labels
199
200    }
201    @catch (ANTLRRecognitionException *re) {
202        [self reportError:re];
203        [self recover:input Exception:re];
204    }
205
206    @finally {
207        /* Terence's stuff */
208
209    }
210    return ;
211}
212/* $ANTLR end stat */
213
214/*
215 * $ANTLR start identifier
216 * T.g:28:1: identifier : ( ID | enumAsID );
217 */
218- (void) identifier
219{
220    /* my ruleScopeSetUp */
221    /* Terence's stuff */
222
223    @try {
224        // 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            ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException newException:2 state:0 stream:input];
236            nvae.c = LA2_0;
237            @throw nvae;
238
239        }
240        switch (alt2) {
241            case 1 : ;
242                // T.g:29:7: ID // alt
243                {
244                [self match:input TokenType:ID Follow:FOLLOW_ID_in_identifier66];
245
246                }
247                break;
248            case 2 : ;
249                // T.g:30:7: enumAsID // alt
250                {
251                /* ruleRef */
252                [self pushFollow:FOLLOW_enumAsID_in_identifier74];
253                [self enumAsID];
254
255                [self popFollow];
256
257
258
259                }
260                break;
261
262        }
263        // token+rule list labels
264
265    }
266    @catch (ANTLRRecognitionException *re) {
267        [self reportError:re];
268        [self recover:input Exception:re];
269    }
270
271    @finally {
272        /* Terence's stuff */
273
274    }
275    return ;
276}
277/* $ANTLR end identifier */
278
279/*
280 * $ANTLR start enumAsKeyword
281 * T.g:33:1: enumAsKeyword :{...}? 'enum' ;
282 */
283- (void) enumAsKeyword
284{
285    /* my ruleScopeSetUp */
286    /* Terence's stuff */
287
288    @try {
289        // T.g:33:15: ({...}? 'enum' ) // ruleBlockSingleAlt
290        // T.g:33:17: {...}? 'enum' // alt
291        {
292        if ( !((enableEnum)) ) {
293            @throw [ANTLRFailedPredicateException newException:@"enumAsKeyword" predicate:@"enableEnum" stream:input];
294        }
295
296        [self match:input TokenType:7 Follow:FOLLOW_7_in_enumAsKeyword89];
297
298        }
299
300        // token+rule list labels
301
302    }
303    @catch (ANTLRRecognitionException *re) {
304        [self reportError:re];
305        [self recover:input Exception:re];
306    }
307
308    @finally {
309        /* Terence's stuff */
310
311    }
312    return ;
313}
314/* $ANTLR end enumAsKeyword */
315
316/*
317 * $ANTLR start enumAsID
318 * T.g:35:1: enumAsID :{...}? 'enum' ;
319 */
320- (void) enumAsID
321{
322    /* my ruleScopeSetUp */
323    /* Terence's stuff */
324
325    @try {
326        // T.g:35:10: ({...}? 'enum' ) // ruleBlockSingleAlt
327        // T.g:35:12: {...}? 'enum' // alt
328        {
329        if ( !((!enableEnum)) ) {
330            @throw [ANTLRFailedPredicateException newException:@"enumAsID" predicate:@"!enableEnum" stream:input];
331        }
332
333        [self match:input TokenType:7 Follow:FOLLOW_7_in_enumAsID100];
334
335        }
336
337        // token+rule list labels
338
339    }
340    @catch (ANTLRRecognitionException *re) {
341        [self reportError:re];
342        [self recover:input Exception:re];
343    }
344
345    @finally {
346        /* Terence's stuff */
347
348    }
349    return ;
350}
351/* $ANTLR end enumAsID */
352/* ObjC end rules */
353
354@end /* end of TParser implementation line 692 */
355