aboutsummaryrefslogtreecommitdiff
path: root/runtime/ObjC/Framework/examples/hoistedPredicates/TParser.m
blob: e4402906fed8b294360e1071ebdcc1bb139b20d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/** \file
 *  This OBJC source file was generated by $ANTLR version ${project.version} ${buildNumber}
 *
 *     -  From the grammar source file : T.g
 *     -                            On : 2011-05-06 19:14:23
 *     -                for the parser : TParserParser
 *
 * Editing it, at least manually, is not wise.
 *
 * ObjC language generator and runtime by Alan Condit, acondit|hereisanat|ipns|dotgoeshere|com.
 *
 *
*/
// $ANTLR ${project.version} ${buildNumber} T.g 2011-05-06 19:14:23


/* -----------------------------------------
 * Include the ANTLR3 generated header file.
 */
#import "TParser.h"
/* ----------------------------------------- */

/** Demonstrates how semantic predicates get hoisted out of the rule in 
 *  which they are found and used in other decisions.  This grammar illustrates
 *  how predicates can be used to distinguish between enum as a keyword and
 *  an ID *dynamically*. :)

 * Run "java org.antlr.Tool -dfa t.g" to generate DOT (graphviz) files.  See
 * the T_dec-1.dot file to see the predicates in action.
 */

/* ============================================================================= */
/* =============================================================================
 * Start of recognizer
 */

#pragma mark Bitsets
static ANTLRBitSet *FOLLOW_identifier_in_stat34;
static const unsigned long long FOLLOW_identifier_in_stat34_data[] = { 0x0000000000000002LL};
static ANTLRBitSet *FOLLOW_enumAsKeyword_in_stat47;
static const unsigned long long FOLLOW_enumAsKeyword_in_stat47_data[] = { 0x0000000000000002LL};
static ANTLRBitSet *FOLLOW_ID_in_identifier66;
static const unsigned long long FOLLOW_ID_in_identifier66_data[] = { 0x0000000000000002LL};
static ANTLRBitSet *FOLLOW_enumAsID_in_identifier74;
static const unsigned long long FOLLOW_enumAsID_in_identifier74_data[] = { 0x0000000000000002LL};
static ANTLRBitSet *FOLLOW_7_in_enumAsKeyword89;
static const unsigned long long FOLLOW_7_in_enumAsKeyword89_data[] = { 0x0000000000000002LL};
static ANTLRBitSet *FOLLOW_7_in_enumAsID100;
static const unsigned long long FOLLOW_7_in_enumAsID100_data[] = { 0x0000000000000002LL};


#pragma mark Dynamic Global Scopes

#pragma mark Dynamic Rule Scopes

#pragma mark Rule Return Scopes start
//#pragma mark Rule return scopes start
//

#pragma mark Rule return scopes start

@implementation TParser  // line 637

/* ObjC start of ruleAttributeScope */
#pragma mark Dynamic Rule Scopes
/* ObjC end of ruleAttributeScope */
#pragma mark global Attribute Scopes
/* ObjC start globalAttributeScope */
/* ObjC end globalAttributeScope */
/* ObjC start actions.(actionScope).synthesize */
/* ObjC end actions.(actionScope).synthesize */
/* ObjC start synthesize() */
/* ObjC end synthesize() */

+ (void) initialize
{
    #pragma mark Bitsets
    FOLLOW_identifier_in_stat34 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_identifier_in_stat34_data Count:(NSUInteger)1] retain];
    FOLLOW_enumAsKeyword_in_stat47 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_enumAsKeyword_in_stat47_data Count:(NSUInteger)1] retain];
    FOLLOW_ID_in_identifier66 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_ID_in_identifier66_data Count:(NSUInteger)1] retain];
    FOLLOW_enumAsID_in_identifier74 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_enumAsID_in_identifier74_data Count:(NSUInteger)1] retain];
    FOLLOW_7_in_enumAsKeyword89 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_7_in_enumAsKeyword89_data Count:(NSUInteger)1] retain];
    FOLLOW_7_in_enumAsID100 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_7_in_enumAsID100_data Count:(NSUInteger)1] retain];

    [ANTLRBaseRecognizer setTokenNames:[[AMutableArray arrayWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>", 
 @"ID", @"INT", @"WS", @"'enum'", nil] retain]];
    [ANTLRBaseRecognizer setGrammarFileName:@"T.g"];
}

+ (TParser *)newTParser:(id<ANTLRTokenStream>)aStream
{
    return [[TParser alloc] initWithTokenStream:aStream];


}

- (id) initWithTokenStream:(id<ANTLRTokenStream>)aStream
{
    self = [super initWithTokenStream:aStream State:[[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:4+1] retain]];
    if ( self != nil ) {


        /* start of actions-actionScope-init */

        enableEnum = NO;

        /* start of init */
    }
    return self;
}

- (void) dealloc
{
    [super dealloc];
}

/* ObjC start members */
/* ObjC end members */
/* ObjC start actions.(actionScope).methods */
/* ObjC end actions.(actionScope).methods */
/* ObjC start methods() */
/* ObjC end methods() */
/* ObjC start rules */
/*
 * $ANTLR start stat
 * T.g:24:1: stat : ( identifier | enumAsKeyword );
 */
- (void) stat
{
    /* my ruleScopeSetUp */
    /* Terence's stuff */

    @try {
        // T.g:24:5: ( identifier | enumAsKeyword ) //ruleblock
        NSInteger alt1=2;
        NSInteger LA1_0 = [input LA:1];

        if ( (LA1_0==ID) ) {
            alt1=1;
        }
        else if ( (LA1_0==7) ) {
            NSInteger LA1_2 = [input LA:2];

            if ( ((!enableEnum)) ) {
                alt1=1;
            }
            else if ( ((enableEnum)) ) {
                alt1=2;
            }
            else {
                ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException newException:1 state:2 stream:input];
                nvae.c = LA1_2;
                @throw nvae;

            }
        }
        else {
            ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException newException:1 state:0 stream:input];
            nvae.c = LA1_0;
            @throw nvae;

        }
        switch (alt1) {
            case 1 : ;
                // T.g:24:7: identifier // alt
                {
                /* ruleRef */
                [self pushFollow:FOLLOW_identifier_in_stat34];
                [self identifier];

                [self popFollow];



                NSLog(@"enum is an ID");


                }
                break;
            case 2 : ;
                // T.g:25:7: enumAsKeyword // alt
                {
                /* ruleRef */
                [self pushFollow:FOLLOW_enumAsKeyword_in_stat47];
                [self enumAsKeyword];

                [self popFollow];



                NSLog(@"enum is a keyword");


                }
                break;

        }
        // token+rule list labels

    }
    @catch (ANTLRRecognitionException *re) {
        [self reportError:re];
        [self recover:input Exception:re];
    }

    @finally {
        /* Terence's stuff */

    }
    return ;
}
/* $ANTLR end stat */

/*
 * $ANTLR start identifier
 * T.g:28:1: identifier : ( ID | enumAsID );
 */
- (void) identifier
{
    /* my ruleScopeSetUp */
    /* Terence's stuff */

    @try {
        // T.g:29:5: ( ID | enumAsID ) //ruleblock
        NSInteger alt2=2;
        NSInteger LA2_0 = [input LA:1];

        if ( (LA2_0==ID) ) {
            alt2=1;
        }
        else if ( (LA2_0==7) ) {
            alt2=2;
        }
        else {
            ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException newException:2 state:0 stream:input];
            nvae.c = LA2_0;
            @throw nvae;

        }
        switch (alt2) {
            case 1 : ;
                // T.g:29:7: ID // alt
                {
                [self match:input TokenType:ID Follow:FOLLOW_ID_in_identifier66]; 

                }
                break;
            case 2 : ;
                // T.g:30:7: enumAsID // alt
                {
                /* ruleRef */
                [self pushFollow:FOLLOW_enumAsID_in_identifier74];
                [self enumAsID];

                [self popFollow];



                }
                break;

        }
        // token+rule list labels

    }
    @catch (ANTLRRecognitionException *re) {
        [self reportError:re];
        [self recover:input Exception:re];
    }

    @finally {
        /* Terence's stuff */

    }
    return ;
}
/* $ANTLR end identifier */

/*
 * $ANTLR start enumAsKeyword
 * T.g:33:1: enumAsKeyword :{...}? 'enum' ;
 */
- (void) enumAsKeyword
{
    /* my ruleScopeSetUp */
    /* Terence's stuff */

    @try {
        // T.g:33:15: ({...}? 'enum' ) // ruleBlockSingleAlt
        // T.g:33:17: {...}? 'enum' // alt
        {
        if ( !((enableEnum)) ) {
            @throw [ANTLRFailedPredicateException newException:@"enumAsKeyword" predicate:@"enableEnum" stream:input];
        }

        [self match:input TokenType:7 Follow:FOLLOW_7_in_enumAsKeyword89]; 

        }

        // token+rule list labels

    }
    @catch (ANTLRRecognitionException *re) {
        [self reportError:re];
        [self recover:input Exception:re];
    }

    @finally {
        /* Terence's stuff */

    }
    return ;
}
/* $ANTLR end enumAsKeyword */

/*
 * $ANTLR start enumAsID
 * T.g:35:1: enumAsID :{...}? 'enum' ;
 */
- (void) enumAsID
{
    /* my ruleScopeSetUp */
    /* Terence's stuff */

    @try {
        // T.g:35:10: ({...}? 'enum' ) // ruleBlockSingleAlt
        // T.g:35:12: {...}? 'enum' // alt
        {
        if ( !((!enableEnum)) ) {
            @throw [ANTLRFailedPredicateException newException:@"enumAsID" predicate:@"!enableEnum" stream:input];
        }

        [self match:input TokenType:7 Follow:FOLLOW_7_in_enumAsID100]; 

        }

        // token+rule list labels

    }
    @catch (ANTLRRecognitionException *re) {
        [self reportError:re];
        [self recover:input Exception:re];
    }

    @finally {
        /* Terence's stuff */

    }
    return ;
}
/* $ANTLR end enumAsID */
/* ObjC end rules */

@end /* end of TParser implementation line 692 */