1/** \file
2 *  This OBJC source file was generated by $ANTLR version ${project.version} ${buildNumber}
3 *
4 *     -  From the grammar source file : SimpleCTP.g
5 *     -                            On : 2011-05-06 15:09:28
6 *     -           for the tree parser : SimpleCTPTreeParser
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} SimpleCTP.g 2011-05-06 15:09:28
15
16
17/* -----------------------------------------
18 * Include the ANTLR3 generated header file.
19 */
20#import "SimpleCTP.h"
21/* ----------------------------------------- */
22
23
24/* ============================================================================= */
25/* =============================================================================
26 * Start of recognizer
27 */
28
29#pragma mark Bitsets
30static ANTLRBitSet *FOLLOW_declaration_in_program56;
31static const unsigned long long FOLLOW_declaration_in_program56_data[] = { 0x00000000020000C2LL};
32static ANTLRBitSet *FOLLOW_variable_in_declaration76;
33static const unsigned long long FOLLOW_variable_in_declaration76_data[] = { 0x0000000000000002LL};
34static ANTLRBitSet *FOLLOW_FUNC_DECL_in_declaration87;
35static const unsigned long long FOLLOW_FUNC_DECL_in_declaration87_data[] = { 0x0000000000000004LL};
36static ANTLRBitSet *FOLLOW_functionHeader_in_declaration89;
37static const unsigned long long FOLLOW_functionHeader_in_declaration89_data[] = { 0x0000000000000008LL};
38static ANTLRBitSet *FOLLOW_FUNC_DEF_in_declaration101;
39static const unsigned long long FOLLOW_FUNC_DEF_in_declaration101_data[] = { 0x0000000000000004LL};
40static ANTLRBitSet *FOLLOW_functionHeader_in_declaration103;
41static const unsigned long long FOLLOW_functionHeader_in_declaration103_data[] = { 0x0000000000000020LL};
42static ANTLRBitSet *FOLLOW_block_in_declaration105;
43static const unsigned long long FOLLOW_block_in_declaration105_data[] = { 0x0000000000000008LL};
44static ANTLRBitSet *FOLLOW_VAR_DEF_in_variable126;
45static const unsigned long long FOLLOW_VAR_DEF_in_variable126_data[] = { 0x0000000000000004LL};
46static ANTLRBitSet *FOLLOW_type_in_variable128;
47static const unsigned long long FOLLOW_type_in_variable128_data[] = { 0x0000000000004000LL};
48static ANTLRBitSet *FOLLOW_declarator_in_variable130;
49static const unsigned long long FOLLOW_declarator_in_variable130_data[] = { 0x0000000000000008LL};
50static ANTLRBitSet *FOLLOW_K_ID_in_declarator150;
51static const unsigned long long FOLLOW_K_ID_in_declarator150_data[] = { 0x0000000000000002LL};
52static ANTLRBitSet *FOLLOW_FUNC_HDR_in_functionHeader171;
53static const unsigned long long FOLLOW_FUNC_HDR_in_functionHeader171_data[] = { 0x0000000000000004LL};
54static ANTLRBitSet *FOLLOW_type_in_functionHeader173;
55static const unsigned long long FOLLOW_type_in_functionHeader173_data[] = { 0x0000000000004000LL};
56static ANTLRBitSet *FOLLOW_K_ID_in_functionHeader175;
57static const unsigned long long FOLLOW_K_ID_in_functionHeader175_data[] = { 0x0000000000000010LL};
58static ANTLRBitSet *FOLLOW_formalParameter_in_functionHeader177;
59static const unsigned long long FOLLOW_formalParameter_in_functionHeader177_data[] = { 0x0000000000000018LL};
60static ANTLRBitSet *FOLLOW_ARG_DEF_in_formalParameter199;
61static const unsigned long long FOLLOW_ARG_DEF_in_formalParameter199_data[] = { 0x0000000000000004LL};
62static ANTLRBitSet *FOLLOW_type_in_formalParameter201;
63static const unsigned long long FOLLOW_type_in_formalParameter201_data[] = { 0x0000000000004000LL};
64static ANTLRBitSet *FOLLOW_declarator_in_formalParameter203;
65static const unsigned long long FOLLOW_declarator_in_formalParameter203_data[] = { 0x0000000000000008LL};
66static ANTLRBitSet *FOLLOW_BLOCK_in_block283;
67static const unsigned long long FOLLOW_BLOCK_in_block283_data[] = { 0x0000000000000004LL};
68static ANTLRBitSet *FOLLOW_variable_in_block285;
69static const unsigned long long FOLLOW_variable_in_block285_data[] = { 0x000000000218F828LL};
70static ANTLRBitSet *FOLLOW_stat_in_block288;
71static const unsigned long long FOLLOW_stat_in_block288_data[] = { 0x000000000018F828LL};
72static ANTLRBitSet *FOLLOW_forStat_in_stat302;
73static const unsigned long long FOLLOW_forStat_in_stat302_data[] = { 0x0000000000000002LL};
74static ANTLRBitSet *FOLLOW_expr_in_stat310;
75static const unsigned long long FOLLOW_expr_in_stat310_data[] = { 0x0000000000000002LL};
76static ANTLRBitSet *FOLLOW_block_in_stat318;
77static const unsigned long long FOLLOW_block_in_stat318_data[] = { 0x0000000000000002LL};
78static ANTLRBitSet *FOLLOW_K_FOR_in_forStat338;
79static const unsigned long long FOLLOW_K_FOR_in_forStat338_data[] = { 0x0000000000000004LL};
80static ANTLRBitSet *FOLLOW_expr_in_forStat340;
81static const unsigned long long FOLLOW_expr_in_forStat340_data[] = { 0x000000000018D800LL};
82static ANTLRBitSet *FOLLOW_expr_in_forStat342;
83static const unsigned long long FOLLOW_expr_in_forStat342_data[] = { 0x000000000018D800LL};
84static ANTLRBitSet *FOLLOW_expr_in_forStat344;
85static const unsigned long long FOLLOW_expr_in_forStat344_data[] = { 0x0000000000000020LL};
86static ANTLRBitSet *FOLLOW_block_in_forStat346;
87static const unsigned long long FOLLOW_block_in_forStat346_data[] = { 0x0000000000000008LL};
88static ANTLRBitSet *FOLLOW_K_EQEQ_in_expr362;
89static const unsigned long long FOLLOW_K_EQEQ_in_expr362_data[] = { 0x0000000000000004LL};
90static ANTLRBitSet *FOLLOW_expr_in_expr364;
91static const unsigned long long FOLLOW_expr_in_expr364_data[] = { 0x000000000018D800LL};
92static ANTLRBitSet *FOLLOW_expr_in_expr366;
93static const unsigned long long FOLLOW_expr_in_expr366_data[] = { 0x0000000000000008LL};
94static ANTLRBitSet *FOLLOW_K_LT_in_expr378;
95static const unsigned long long FOLLOW_K_LT_in_expr378_data[] = { 0x0000000000000004LL};
96static ANTLRBitSet *FOLLOW_expr_in_expr380;
97static const unsigned long long FOLLOW_expr_in_expr380_data[] = { 0x000000000018D800LL};
98static ANTLRBitSet *FOLLOW_expr_in_expr382;
99static const unsigned long long FOLLOW_expr_in_expr382_data[] = { 0x0000000000000008LL};
100static ANTLRBitSet *FOLLOW_K_PLUS_in_expr394;
101static const unsigned long long FOLLOW_K_PLUS_in_expr394_data[] = { 0x0000000000000004LL};
102static ANTLRBitSet *FOLLOW_expr_in_expr396;
103static const unsigned long long FOLLOW_expr_in_expr396_data[] = { 0x000000000018D800LL};
104static ANTLRBitSet *FOLLOW_expr_in_expr398;
105static const unsigned long long FOLLOW_expr_in_expr398_data[] = { 0x0000000000000008LL};
106static ANTLRBitSet *FOLLOW_K_EQ_in_expr410;
107static const unsigned long long FOLLOW_K_EQ_in_expr410_data[] = { 0x0000000000000004LL};
108static ANTLRBitSet *FOLLOW_K_ID_in_expr412;
109static const unsigned long long FOLLOW_K_ID_in_expr412_data[] = { 0x000000000018D800LL};
110static ANTLRBitSet *FOLLOW_expr_in_expr416;
111static const unsigned long long FOLLOW_expr_in_expr416_data[] = { 0x0000000000000008LL};
112static ANTLRBitSet *FOLLOW_atom_in_expr429;
113static const unsigned long long FOLLOW_atom_in_expr429_data[] = { 0x0000000000000002LL};
114
115
116#pragma mark Dynamic Global Scopes
117@implementation Symbols_Scope  /* globalAttributeScopeImplementation */
118/* start of synthesize -- OBJC-Line 1750 */
119
120@synthesize tree;
121
122+ (Symbols_Scope *)newSymbols_Scope
123{
124    return [[[Symbols_Scope alloc] init] retain];
125}
126
127- (id) init
128{
129    self = [super init];
130    return self;
131}
132
133/* start of iterate get and set functions */
134
135- (ANTLRCommonTree *)gettree { return( tree ); }
136
137- (void)settree:(ANTLRCommonTree *)aVal { tree = aVal; }
138
139/* End of iterate get and set functions */
140
141@end /* end of Symbols_Scope implementation */
142
143
144#pragma mark Dynamic Rule Scopes
145
146#pragma mark Rule Return Scopes start
147@implementation SimpleCTP_expr_return /* returnScope */
148 /* start of synthesize -- OBJC-Line 1837 */
149+ (SimpleCTP_expr_return *)newSimpleCTP_expr_return
150{
151    return [[[SimpleCTP_expr_return alloc] init] retain];
152}
153
154- (id) init
155{
156    self = [super init];
157    return self;
158}
159
160
161
162@end /* end of returnScope implementation */
163
164
165//#pragma mark Rule return scopes start
166//
167
168#pragma mark Rule return scopes start
169
170@implementation SimpleCTP  // line 637
171
172/* ObjC start of ruleAttributeScope */
173#pragma mark Dynamic Rule Scopes
174/* ObjC end of ruleAttributeScope */
175#pragma mark global Attribute Scopes
176/* ObjC start globalAttributeScope */
177static _stack;
178
179/* ObjC end globalAttributeScope */
180/* ObjC start actions.(actionScope).synthesize */
181/* ObjC end actions.(actionScope).synthesize */
182/* ObjC start synthesize() */
183/* ObjC end synthesize() */
184
185+ (void) initialize
186{
187    #pragma mark Bitsets
188    FOLLOW_declaration_in_program56 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_declaration_in_program56_data Count:(NSUInteger)1] retain];
189    FOLLOW_variable_in_declaration76 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_variable_in_declaration76_data Count:(NSUInteger)1] retain];
190    FOLLOW_FUNC_DECL_in_declaration87 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_FUNC_DECL_in_declaration87_data Count:(NSUInteger)1] retain];
191    FOLLOW_functionHeader_in_declaration89 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_functionHeader_in_declaration89_data Count:(NSUInteger)1] retain];
192    FOLLOW_FUNC_DEF_in_declaration101 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_FUNC_DEF_in_declaration101_data Count:(NSUInteger)1] retain];
193    FOLLOW_functionHeader_in_declaration103 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_functionHeader_in_declaration103_data Count:(NSUInteger)1] retain];
194    FOLLOW_block_in_declaration105 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_block_in_declaration105_data Count:(NSUInteger)1] retain];
195    FOLLOW_VAR_DEF_in_variable126 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_VAR_DEF_in_variable126_data Count:(NSUInteger)1] retain];
196    FOLLOW_type_in_variable128 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_type_in_variable128_data Count:(NSUInteger)1] retain];
197    FOLLOW_declarator_in_variable130 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_declarator_in_variable130_data Count:(NSUInteger)1] retain];
198    FOLLOW_K_ID_in_declarator150 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_K_ID_in_declarator150_data Count:(NSUInteger)1] retain];
199    FOLLOW_FUNC_HDR_in_functionHeader171 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_FUNC_HDR_in_functionHeader171_data Count:(NSUInteger)1] retain];
200    FOLLOW_type_in_functionHeader173 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_type_in_functionHeader173_data Count:(NSUInteger)1] retain];
201    FOLLOW_K_ID_in_functionHeader175 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_K_ID_in_functionHeader175_data Count:(NSUInteger)1] retain];
202    FOLLOW_formalParameter_in_functionHeader177 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_formalParameter_in_functionHeader177_data Count:(NSUInteger)1] retain];
203    FOLLOW_ARG_DEF_in_formalParameter199 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_ARG_DEF_in_formalParameter199_data Count:(NSUInteger)1] retain];
204    FOLLOW_type_in_formalParameter201 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_type_in_formalParameter201_data Count:(NSUInteger)1] retain];
205    FOLLOW_declarator_in_formalParameter203 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_declarator_in_formalParameter203_data Count:(NSUInteger)1] retain];
206    FOLLOW_BLOCK_in_block283 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_BLOCK_in_block283_data Count:(NSUInteger)1] retain];
207    FOLLOW_variable_in_block285 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_variable_in_block285_data Count:(NSUInteger)1] retain];
208    FOLLOW_stat_in_block288 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_stat_in_block288_data Count:(NSUInteger)1] retain];
209    FOLLOW_forStat_in_stat302 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_forStat_in_stat302_data Count:(NSUInteger)1] retain];
210    FOLLOW_expr_in_stat310 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_stat310_data Count:(NSUInteger)1] retain];
211    FOLLOW_block_in_stat318 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_block_in_stat318_data Count:(NSUInteger)1] retain];
212    FOLLOW_K_FOR_in_forStat338 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_K_FOR_in_forStat338_data Count:(NSUInteger)1] retain];
213    FOLLOW_expr_in_forStat340 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_forStat340_data Count:(NSUInteger)1] retain];
214    FOLLOW_expr_in_forStat342 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_forStat342_data Count:(NSUInteger)1] retain];
215    FOLLOW_expr_in_forStat344 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_forStat344_data Count:(NSUInteger)1] retain];
216    FOLLOW_block_in_forStat346 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_block_in_forStat346_data Count:(NSUInteger)1] retain];
217    FOLLOW_K_EQEQ_in_expr362 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_K_EQEQ_in_expr362_data Count:(NSUInteger)1] retain];
218    FOLLOW_expr_in_expr364 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_expr364_data Count:(NSUInteger)1] retain];
219    FOLLOW_expr_in_expr366 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_expr366_data Count:(NSUInteger)1] retain];
220    FOLLOW_K_LT_in_expr378 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_K_LT_in_expr378_data Count:(NSUInteger)1] retain];
221    FOLLOW_expr_in_expr380 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_expr380_data Count:(NSUInteger)1] retain];
222    FOLLOW_expr_in_expr382 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_expr382_data Count:(NSUInteger)1] retain];
223    FOLLOW_K_PLUS_in_expr394 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_K_PLUS_in_expr394_data Count:(NSUInteger)1] retain];
224    FOLLOW_expr_in_expr396 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_expr396_data Count:(NSUInteger)1] retain];
225    FOLLOW_expr_in_expr398 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_expr398_data Count:(NSUInteger)1] retain];
226    FOLLOW_K_EQ_in_expr410 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_K_EQ_in_expr410_data Count:(NSUInteger)1] retain];
227    FOLLOW_K_ID_in_expr412 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_K_ID_in_expr412_data Count:(NSUInteger)1] retain];
228    FOLLOW_expr_in_expr416 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_expr_in_expr416_data Count:(NSUInteger)1] retain];
229    FOLLOW_atom_in_expr429 = [[ANTLRBitSet newANTLRBitSetWithBits:(const unsigned long long *)FOLLOW_atom_in_expr429_data Count:(NSUInteger)1] retain];
230
231    [ANTLRBaseRecognizer setTokenNames:[[AMutableArray arrayWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>",
232 @"ARG_DEF", @"BLOCK", @"FUNC_DECL", @"FUNC_DEF", @"FUNC_HDR", @"K_CHAR",
233 @"K_COMMA", @"K_EQ", @"K_EQEQ", @"K_FOR", @"K_ID", @"K_INT", @"K_INT_TYPE",
234 @"K_LCURLY", @"K_LCURVE", @"K_LT", @"K_PLUS", @"K_RCURLY", @"K_RCURVE",
235 @"K_SEMICOLON", @"K_VOID", @"VAR_DEF", @"WS", nil] retain]];
236    [ANTLRBaseRecognizer setGrammarFileName:@"SimpleCTP.g"];
237}
238
239+ (SimpleCTP *)newSimpleCTP:(id<ANTLRTreeNodeStream>)aStream
240{
241    return [[SimpleCTP alloc] initWithStream:aStream];
242
243
244}
245
246- (id) initWithStream:(id<ANTLRTreeNodeStream>)aStream
247{
248    self = [super initWithStream:aStream State:[[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:12+1] retain]];
249    if ( self != nil ) {
250
251
252        /* globalAttributeScopeInit */
253        Symbols_scope = [Symbols_Scope newSymbols_Scope];
254        Symbols_stack = [ANTLRSymbolStack newANTLRSymbolStackWithLen:30];
255        /* start of actions-actionScope-init */
256        /* start of init */
257    }
258    return self;
259}
260
261- (void) dealloc
262{
263    [Symbols_stack release];
264    [super dealloc];
265}
266
267/* ObjC start members */
268/* ObjC end members */
269/* ObjC start actions.(actionScope).methods */
270/* ObjC end actions.(actionScope).methods */
271/* ObjC start methods() */
272/* ObjC end methods() */
273/* ObjC start rules */
274/*
275 * $ANTLR start program
276 * SimpleCTP.g:13:1: program : ( declaration )+ ;
277 */
278- (void) program
279{
280    /* my ruleScopeSetUp */
281    /* Terence's stuff */
282
283    @try {
284        // SimpleCTP.g:14:5: ( ( declaration )+ ) // ruleBlockSingleAlt
285        // SimpleCTP.g:14:9: ( declaration )+ // alt
286        {
287        // SimpleCTP.g:14:9: ( declaration )+ // positiveClosureBlock
288        NSInteger cnt1 = 0;
289        do {
290            NSInteger alt1 = 2;
291            NSInteger LA1_0 = [input LA:1];
292            if ( ((LA1_0 >= FUNC_DECL && LA1_0 <= FUNC_DEF)||LA1_0==VAR_DEF) ) {
293                alt1=1;
294            }
295
296
297            switch (alt1) {
298                case 1 : ;
299                    // SimpleCTP.g:14:9: declaration // alt
300                    {
301                    /* ruleRef */
302                    [self pushFollow:FOLLOW_declaration_in_program56];
303                    [self declaration];
304
305                    [self popFollow];
306
307
308
309                    }
310                    break;
311
312                default :
313                    if ( cnt1 >= 1 )
314                        goto loop1;
315                    ANTLREarlyExitException *eee =
316                        [ANTLREarlyExitException newException:input decisionNumber:1];
317                    @throw eee;
318            }
319            cnt1++;
320        } while (YES);
321        loop1: ;
322
323
324        }
325
326        // token+rule list labels
327
328    }
329    @catch (ANTLRRecognitionException *re) {
330        [self reportError:re];
331        [self recover:input Exception:re];
332    }
333
334    @finally {
335        /* Terence's stuff */
336
337    }
338    return ;
339}
340/* $ANTLR end program */
341
342/*
343 * $ANTLR start declaration
344 * SimpleCTP.g:17:1: declaration : ( variable | ^( FUNC_DECL functionHeader ) | ^( FUNC_DEF functionHeader block ) );
345 */
346- (void) declaration
347{
348    /* my ruleScopeSetUp */
349    /* Terence's stuff */
350
351    @try {
352        // SimpleCTP.g:18:5: ( variable | ^( FUNC_DECL functionHeader ) | ^( FUNC_DEF functionHeader block ) ) //ruleblock
353        NSInteger alt2=3;
354        unichar charLA2 = [input LA:1];
355        switch (charLA2) {
356            case VAR_DEF: ;
357                {
358                alt2=1;
359                }
360                break;
361            case FUNC_DECL: ;
362                {
363                alt2=2;
364                }
365                break;
366            case FUNC_DEF: ;
367                {
368                alt2=3;
369                }
370                break;
371
372        default: ;
373            ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException newException:2 state:0 stream:input];
374            nvae.c = charLA2;
375            @throw nvae;
376
377        }
378
379        switch (alt2) {
380            case 1 : ;
381                // SimpleCTP.g:18:9: variable // alt
382                {
383                /* ruleRef */
384                [self pushFollow:FOLLOW_variable_in_declaration76];
385                [self variable];
386
387                [self popFollow];
388
389
390
391                }
392                break;
393            case 2 : ;
394                // SimpleCTP.g:19:9: ^( FUNC_DECL functionHeader ) // alt
395                {
396                [self match:input TokenType:FUNC_DECL Follow:FOLLOW_FUNC_DECL_in_declaration87];
397
398                    [self match:input TokenType:DOWN Follow:nil];
399                    /* ruleRef */
400                    [self pushFollow:FOLLOW_functionHeader_in_declaration89];
401                    [self functionHeader];
402
403                    [self popFollow];
404
405
406
407                    [self match:input TokenType:UP Follow:nil];
408
409
410                }
411                break;
412            case 3 : ;
413                // SimpleCTP.g:20:9: ^( FUNC_DEF functionHeader block ) // alt
414                {
415                [self match:input TokenType:FUNC_DEF Follow:FOLLOW_FUNC_DEF_in_declaration101];
416
417                    [self match:input TokenType:DOWN Follow:nil];
418                    /* ruleRef */
419                    [self pushFollow:FOLLOW_functionHeader_in_declaration103];
420                    [self functionHeader];
421
422                    [self popFollow];
423
424
425
426                    /* ruleRef */
427                    [self pushFollow:FOLLOW_block_in_declaration105];
428                    [self block];
429
430                    [self popFollow];
431
432
433
434                    [self match:input TokenType:UP Follow:nil];
435
436
437                }
438                break;
439
440        }
441        // token+rule list labels
442
443    }
444    @catch (ANTLRRecognitionException *re) {
445        [self reportError:re];
446        [self recover:input Exception:re];
447    }
448
449    @finally {
450        /* Terence's stuff */
451
452    }
453    return ;
454}
455/* $ANTLR end declaration */
456
457/*
458 * $ANTLR start variable
459 * SimpleCTP.g:23:1: variable : ^( VAR_DEF type declarator ) ;
460 */
461- (void) variable
462{
463    /* my ruleScopeSetUp */
464    /* Terence's stuff */
465
466    @try {
467        // SimpleCTP.g:24:5: ( ^( VAR_DEF type declarator ) ) // ruleBlockSingleAlt
468        // SimpleCTP.g:24:9: ^( VAR_DEF type declarator ) // alt
469        {
470        [self match:input TokenType:VAR_DEF Follow:FOLLOW_VAR_DEF_in_variable126];
471
472            [self match:input TokenType:DOWN Follow:nil];
473            /* ruleRef */
474            [self pushFollow:FOLLOW_type_in_variable128];
475            [self type];
476
477            [self popFollow];
478
479
480
481            /* ruleRef */
482            [self pushFollow:FOLLOW_declarator_in_variable130];
483            [self declarator];
484
485            [self popFollow];
486
487
488
489            [self match:input TokenType:UP Follow:nil];
490
491
492        }
493
494        // token+rule list labels
495
496    }
497    @catch (ANTLRRecognitionException *re) {
498        [self reportError:re];
499        [self recover:input Exception:re];
500    }
501
502    @finally {
503        /* Terence's stuff */
504
505    }
506    return ;
507}
508/* $ANTLR end variable */
509
510/*
511 * $ANTLR start declarator
512 * SimpleCTP.g:27:1: declarator : K_ID ;
513 */
514- (void) declarator
515{
516    /* my ruleScopeSetUp */
517    /* Terence's stuff */
518
519    @try {
520        // SimpleCTP.g:28:5: ( K_ID ) // ruleBlockSingleAlt
521        // SimpleCTP.g:28:9: K_ID // alt
522        {
523        [self match:input TokenType:K_ID Follow:FOLLOW_K_ID_in_declarator150];
524
525        }
526
527        // token+rule list labels
528
529    }
530    @catch (ANTLRRecognitionException *re) {
531        [self reportError:re];
532        [self recover:input Exception:re];
533    }
534
535    @finally {
536        /* Terence's stuff */
537
538    }
539    return ;
540}
541/* $ANTLR end declarator */
542
543/*
544 * $ANTLR start functionHeader
545 * SimpleCTP.g:31:1: functionHeader : ^( FUNC_HDR type K_ID ( formalParameter )+ ) ;
546 */
547- (void) functionHeader
548{
549    /* my ruleScopeSetUp */
550    /* Terence's stuff */
551
552    @try {
553        // SimpleCTP.g:32:5: ( ^( FUNC_HDR type K_ID ( formalParameter )+ ) ) // ruleBlockSingleAlt
554        // SimpleCTP.g:32:9: ^( FUNC_HDR type K_ID ( formalParameter )+ ) // alt
555        {
556        [self match:input TokenType:FUNC_HDR Follow:FOLLOW_FUNC_HDR_in_functionHeader171];
557
558            [self match:input TokenType:DOWN Follow:nil];
559            /* ruleRef */
560            [self pushFollow:FOLLOW_type_in_functionHeader173];
561            [self type];
562
563            [self popFollow];
564
565
566
567            [self match:input TokenType:K_ID Follow:FOLLOW_K_ID_in_functionHeader175];
568
569            // SimpleCTP.g:32:30: ( formalParameter )+ // positiveClosureBlock
570            NSInteger cnt3 = 0;
571            do {
572                NSInteger alt3 = 2;
573                NSInteger LA3_0 = [input LA:1];
574                if ( (LA3_0==ARG_DEF) ) {
575                    alt3=1;
576                }
577
578
579                switch (alt3) {
580                    case 1 : ;
581                        // SimpleCTP.g:32:30: formalParameter // alt
582                        {
583                        /* ruleRef */
584                        [self pushFollow:FOLLOW_formalParameter_in_functionHeader177];
585                        [self formalParameter];
586
587                        [self popFollow];
588
589
590
591                        }
592                        break;
593
594                    default :
595                        if ( cnt3 >= 1 )
596                            goto loop3;
597                        ANTLREarlyExitException *eee =
598                            [ANTLREarlyExitException newException:input decisionNumber:3];
599                        @throw eee;
600                }
601                cnt3++;
602            } while (YES);
603            loop3: ;
604
605
606            [self match:input TokenType:UP Follow:nil];
607
608
609        }
610
611        // token+rule list labels
612
613    }
614    @catch (ANTLRRecognitionException *re) {
615        [self reportError:re];
616        [self recover:input Exception:re];
617    }
618
619    @finally {
620        /* Terence's stuff */
621
622    }
623    return ;
624}
625/* $ANTLR end functionHeader */
626
627/*
628 * $ANTLR start formalParameter
629 * SimpleCTP.g:35:1: formalParameter : ^( ARG_DEF type declarator ) ;
630 */
631- (void) formalParameter
632{
633    /* my ruleScopeSetUp */
634    /* Terence's stuff */
635
636    @try {
637        // SimpleCTP.g:36:5: ( ^( ARG_DEF type declarator ) ) // ruleBlockSingleAlt
638        // SimpleCTP.g:36:9: ^( ARG_DEF type declarator ) // alt
639        {
640        [self match:input TokenType:ARG_DEF Follow:FOLLOW_ARG_DEF_in_formalParameter199];
641
642            [self match:input TokenType:DOWN Follow:nil];
643            /* ruleRef */
644            [self pushFollow:FOLLOW_type_in_formalParameter201];
645            [self type];
646
647            [self popFollow];
648
649
650
651            /* ruleRef */
652            [self pushFollow:FOLLOW_declarator_in_formalParameter203];
653            [self declarator];
654
655            [self popFollow];
656
657
658
659            [self match:input TokenType:UP Follow:nil];
660
661
662        }
663
664        // token+rule list labels
665
666    }
667    @catch (ANTLRRecognitionException *re) {
668        [self reportError:re];
669        [self recover:input Exception:re];
670    }
671
672    @finally {
673        /* Terence's stuff */
674
675    }
676    return ;
677}
678/* $ANTLR end formalParameter */
679
680/*
681 * $ANTLR start type
682 * SimpleCTP.g:39:1: type : ( K_INT_TYPE | K_CHAR | K_VOID | K_ID );
683 */
684- (void) type
685{
686    /* my ruleScopeSetUp */
687    /* Terence's stuff */
688
689    @try {
690        // SimpleCTP.g:40:5: ( K_INT_TYPE | K_CHAR | K_VOID | K_ID ) // ruleBlockSingleAlt
691        // SimpleCTP.g: // alt
692        {
693        if ([input LA:1] == K_CHAR||[input LA:1] == K_ID||[input LA:1] == K_INT_TYPE||[input LA:1] == K_VOID) {
694            [input consume];
695            [state setIsErrorRecovery:NO];
696        } else {
697            ANTLRMismatchedSetException *mse = [ANTLRMismatchedSetException newException:nil stream:input];
698            @throw mse;
699        }
700
701
702        }
703
704        // token+rule list labels
705
706    }
707    @catch (ANTLRRecognitionException *re) {
708        [self reportError:re];
709        [self recover:input Exception:re];
710    }
711
712    @finally {
713        /* Terence's stuff */
714
715    }
716    return ;
717}
718/* $ANTLR end type */
719
720/*
721 * $ANTLR start block
722 * SimpleCTP.g:46:1: block : ^( BLOCK ( variable )* ( stat )* ) ;
723 */
724- (void) block
725{
726    /* my ruleScopeSetUp */
727    /* Terence's stuff */
728
729    @try {
730        // SimpleCTP.g:47:5: ( ^( BLOCK ( variable )* ( stat )* ) ) // ruleBlockSingleAlt
731        // SimpleCTP.g:47:9: ^( BLOCK ( variable )* ( stat )* ) // alt
732        {
733        [self match:input TokenType:BLOCK Follow:FOLLOW_BLOCK_in_block283];
734
735        if ( [input LA:1] == DOWN ) {
736            [self match:input TokenType:DOWN Follow:nil];
737            do {
738                NSInteger alt4=2;
739                NSInteger LA4_0 = [input LA:1];
740                if ( (LA4_0==VAR_DEF) ) {
741                    alt4=1;
742                }
743
744
745                switch (alt4) {
746                    case 1 : ;
747                        // SimpleCTP.g:47:17: variable // alt
748                        {
749                        /* ruleRef */
750                        [self pushFollow:FOLLOW_variable_in_block285];
751                        [self variable];
752
753                        [self popFollow];
754
755
756
757                        }
758                        break;
759
760                    default :
761                        goto loop4;
762                }
763            } while (YES);
764            loop4: ;
765
766
767            do {
768                NSInteger alt5=2;
769                NSInteger LA5_0 = [input LA:1];
770                if ( (LA5_0==BLOCK||(LA5_0 >= K_EQ && LA5_0 <= K_INT)||(LA5_0 >= K_LT && LA5_0 <= K_PLUS)) ) {
771                    alt5=1;
772                }
773
774
775                switch (alt5) {
776                    case 1 : ;
777                        // SimpleCTP.g:47:27: stat // alt
778                        {
779                        /* ruleRef */
780                        [self pushFollow:FOLLOW_stat_in_block288];
781                        [self stat];
782
783                        [self popFollow];
784
785
786
787                        }
788                        break;
789
790                    default :
791                        goto loop5;
792                }
793            } while (YES);
794            loop5: ;
795
796
797            [self match:input TokenType:UP Follow:nil];
798        }
799
800
801        }
802
803        // token+rule list labels
804
805    }
806    @catch (ANTLRRecognitionException *re) {
807        [self reportError:re];
808        [self recover:input Exception:re];
809    }
810
811    @finally {
812        /* Terence's stuff */
813
814    }
815    return ;
816}
817/* $ANTLR end block */
818
819/*
820 * $ANTLR start stat
821 * SimpleCTP.g:50:1: stat : ( forStat | expr | block );
822 */
823- (void) stat
824{
825    /* my ruleScopeSetUp */
826    /* Terence's stuff */
827
828    @try {
829        // SimpleCTP.g:50:5: ( forStat | expr | block ) //ruleblock
830        NSInteger alt6=3;
831        unichar charLA6 = [input LA:1];
832        switch (charLA6) {
833            case K_FOR: ;
834                {
835                alt6=1;
836                }
837                break;
838            case K_EQ: ;
839            case K_EQEQ: ;
840            case K_ID: ;
841            case K_INT: ;
842            case K_LT: ;
843            case K_PLUS: ;
844                {
845                alt6=2;
846                }
847                break;
848            case BLOCK: ;
849                {
850                alt6=3;
851                }
852                break;
853
854        default: ;
855            ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException newException:6 state:0 stream:input];
856            nvae.c = charLA6;
857            @throw nvae;
858
859        }
860
861        switch (alt6) {
862            case 1 : ;
863                // SimpleCTP.g:50:7: forStat // alt
864                {
865                /* ruleRef */
866                [self pushFollow:FOLLOW_forStat_in_stat302];
867                [self forStat];
868
869                [self popFollow];
870
871
872
873                }
874                break;
875            case 2 : ;
876                // SimpleCTP.g:51:7: expr // alt
877                {
878                /* ruleRef */
879                [self pushFollow:FOLLOW_expr_in_stat310];
880                [self expr];
881
882                [self popFollow];
883
884
885
886                }
887                break;
888            case 3 : ;
889                // SimpleCTP.g:52:7: block // alt
890                {
891                /* ruleRef */
892                [self pushFollow:FOLLOW_block_in_stat318];
893                [self block];
894
895                [self popFollow];
896
897
898
899                }
900                break;
901
902        }
903        // token+rule list labels
904
905    }
906    @catch (ANTLRRecognitionException *re) {
907        [self reportError:re];
908        [self recover:input Exception:re];
909    }
910
911    @finally {
912        /* Terence's stuff */
913
914    }
915    return ;
916}
917/* $ANTLR end stat */
918
919/*
920 * $ANTLR start forStat
921 * SimpleCTP.g:55:1: forStat : ^( K_FOR expr expr expr block ) ;
922 */
923- (void) forStat
924{
925    /* my ruleScopeSetUp */
926    /* Terence's stuff */
927
928    @try {
929        // SimpleCTP.g:56:5: ( ^( K_FOR expr expr expr block ) ) // ruleBlockSingleAlt
930        // SimpleCTP.g:56:9: ^( K_FOR expr expr expr block ) // alt
931        {
932        [self match:input TokenType:K_FOR Follow:FOLLOW_K_FOR_in_forStat338];
933
934            [self match:input TokenType:DOWN Follow:nil];
935            /* ruleRef */
936            [self pushFollow:FOLLOW_expr_in_forStat340];
937            [self expr];
938
939            [self popFollow];
940
941
942
943            /* ruleRef */
944            [self pushFollow:FOLLOW_expr_in_forStat342];
945            [self expr];
946
947            [self popFollow];
948
949
950
951            /* ruleRef */
952            [self pushFollow:FOLLOW_expr_in_forStat344];
953            [self expr];
954
955            [self popFollow];
956
957
958
959            /* ruleRef */
960            [self pushFollow:FOLLOW_block_in_forStat346];
961            [self block];
962
963            [self popFollow];
964
965
966
967            [self match:input TokenType:UP Follow:nil];
968
969
970        }
971
972        // token+rule list labels
973
974    }
975    @catch (ANTLRRecognitionException *re) {
976        [self reportError:re];
977        [self recover:input Exception:re];
978    }
979
980    @finally {
981        /* Terence's stuff */
982
983    }
984    return ;
985}
986/* $ANTLR end forStat */
987
988/*
989 * $ANTLR start expr
990 * SimpleCTP.g:59:1: expr : ( ^( K_EQEQ expr expr ) | ^( K_LT expr expr ) | ^( K_PLUS expr expr ) | ^( K_EQ K_ID e= expr ) | atom );
991 */
992- (SimpleCTP_expr_return *) expr
993{
994    /* my ruleScopeSetUp */
995    /* Terence's stuff */
996
997    SimpleCTP_expr_return * retval = [SimpleCTP_expr_return newSimpleCTP_expr_return];
998    [retval setStart:[input LT:1]];
999
1000
1001    @try {
1002        ANTLRCommonTree *K_ID1 = nil;
1003         SimpleCTP_expr_return * e = nil ;
1004
1005
1006        // SimpleCTP.g:59:5: ( ^( K_EQEQ expr expr ) | ^( K_LT expr expr ) | ^( K_PLUS expr expr ) | ^( K_EQ K_ID e= expr ) | atom ) //ruleblock
1007        NSInteger alt7=5;
1008        unichar charLA7 = [input LA:1];
1009        switch (charLA7) {
1010            case K_EQEQ: ;
1011                {
1012                alt7=1;
1013                }
1014                break;
1015            case K_LT: ;
1016                {
1017                alt7=2;
1018                }
1019                break;
1020            case K_PLUS: ;
1021                {
1022                alt7=3;
1023                }
1024                break;
1025            case K_EQ: ;
1026                {
1027                alt7=4;
1028                }
1029                break;
1030            case K_ID: ;
1031            case K_INT: ;
1032                {
1033                alt7=5;
1034                }
1035                break;
1036
1037        default: ;
1038            ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException newException:7 state:0 stream:input];
1039            nvae.c = charLA7;
1040            @throw nvae;
1041
1042        }
1043
1044        switch (alt7) {
1045            case 1 : ;
1046                // SimpleCTP.g:59:9: ^( K_EQEQ expr expr ) // alt
1047                {
1048                [self match:input TokenType:K_EQEQ Follow:FOLLOW_K_EQEQ_in_expr362];
1049
1050                    [self match:input TokenType:DOWN Follow:nil];
1051                    /* ruleRef */
1052                    [self pushFollow:FOLLOW_expr_in_expr364];
1053                    [self expr];
1054
1055                    [self popFollow];
1056
1057
1058
1059                    /* ruleRef */
1060                    [self pushFollow:FOLLOW_expr_in_expr366];
1061                    [self expr];
1062
1063                    [self popFollow];
1064
1065
1066
1067                    [self match:input TokenType:UP Follow:nil];
1068
1069
1070                }
1071                break;
1072            case 2 : ;
1073                // SimpleCTP.g:60:9: ^( K_LT expr expr ) // alt
1074                {
1075                [self match:input TokenType:K_LT Follow:FOLLOW_K_LT_in_expr378];
1076
1077                    [self match:input TokenType:DOWN Follow:nil];
1078                    /* ruleRef */
1079                    [self pushFollow:FOLLOW_expr_in_expr380];
1080                    [self expr];
1081
1082                    [self popFollow];
1083
1084
1085
1086                    /* ruleRef */
1087                    [self pushFollow:FOLLOW_expr_in_expr382];
1088                    [self expr];
1089
1090                    [self popFollow];
1091
1092
1093
1094                    [self match:input TokenType:UP Follow:nil];
1095
1096
1097                }
1098                break;
1099            case 3 : ;
1100                // SimpleCTP.g:61:9: ^( K_PLUS expr expr ) // alt
1101                {
1102                [self match:input TokenType:K_PLUS Follow:FOLLOW_K_PLUS_in_expr394];
1103
1104                    [self match:input TokenType:DOWN Follow:nil];
1105                    /* ruleRef */
1106                    [self pushFollow:FOLLOW_expr_in_expr396];
1107                    [self expr];
1108
1109                    [self popFollow];
1110
1111
1112
1113                    /* ruleRef */
1114                    [self pushFollow:FOLLOW_expr_in_expr398];
1115                    [self expr];
1116
1117                    [self popFollow];
1118
1119
1120
1121                    [self match:input TokenType:UP Follow:nil];
1122
1123
1124                }
1125                break;
1126            case 4 : ;
1127                // SimpleCTP.g:62:9: ^( K_EQ K_ID e= expr ) // alt
1128                {
1129                [self match:input TokenType:K_EQ Follow:FOLLOW_K_EQ_in_expr410];
1130
1131                    [self match:input TokenType:DOWN Follow:nil];
1132                    K_ID1=(ANTLRCommonTree *)[self match:input TokenType:K_ID Follow:FOLLOW_K_ID_in_expr412];
1133
1134                    /* ruleRef */
1135                    [self pushFollow:FOLLOW_expr_in_expr416];
1136                    e = [self expr];
1137
1138                    [self popFollow];
1139
1140
1141
1142                    [self match:input TokenType:UP Follow:nil];
1143
1144
1145                 NSLog(@"assigning %@ to variable %@", (e!=nil?[[input getTokenStream] toStringFromStart:[[input getTreeAdaptor] getTokenStartIndex:[e getStart]]ToEnd:[[input getTreeAdaptor] getTokenStopIndex:[e getStart]]]:0), (K_ID1!=nil?K_ID1.text:nil));
1146
1147
1148                }
1149                break;
1150            case 5 : ;
1151                // SimpleCTP.g:63:9: atom // alt
1152                {
1153                /* ruleRef */
1154                [self pushFollow:FOLLOW_atom_in_expr429];
1155                [self atom];
1156
1157                [self popFollow];
1158
1159
1160
1161                }
1162                break;
1163
1164        }
1165        // token+rule list labels
1166
1167    }
1168    @catch (ANTLRRecognitionException *re) {
1169        [self reportError:re];
1170        [self recover:input Exception:re];
1171    }
1172
1173    @finally {
1174        /* Terence's stuff */
1175
1176    }
1177    return retval;
1178}
1179/* $ANTLR end expr */
1180
1181/*
1182 * $ANTLR start atom
1183 * SimpleCTP.g:66:1: atom : ( K_ID | K_INT );
1184 */
1185- (void) atom
1186{
1187    /* my ruleScopeSetUp */
1188    /* Terence's stuff */
1189
1190    @try {
1191        // SimpleCTP.g:67:5: ( K_ID | K_INT ) // ruleBlockSingleAlt
1192        // SimpleCTP.g: // alt
1193        {
1194        if ((([input LA:1] >= K_ID) && ([input LA:1] <= K_INT))) {
1195            [input consume];
1196            [state setIsErrorRecovery:NO];
1197        } else {
1198            ANTLRMismatchedSetException *mse = [ANTLRMismatchedSetException newException:nil stream:input];
1199            @throw mse;
1200        }
1201
1202
1203        }
1204
1205        // token+rule list labels
1206
1207    }
1208    @catch (ANTLRRecognitionException *re) {
1209        [self reportError:re];
1210        [self recover:input Exception:re];
1211    }
1212
1213    @finally {
1214        /* Terence's stuff */
1215
1216    }
1217    return ;
1218}
1219/* $ANTLR end atom */
1220/* ObjC end rules */
1221
1222@end /* end of SimpleCTP implementation line 692 */
1223