KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > antlr > parser > GroovyRecognizer


1 // $ANTLR 2.7.2: "groovy.g" -> "GroovyRecognizer.java"$
2

3 package org.codehaus.groovy.antlr.parser;
4 import org.codehaus.groovy.antlr.*;
5 import java.util.*;
6 import java.io.InputStream JavaDoc;
7 import java.io.Reader JavaDoc;
8 import antlr.InputBuffer;
9 import antlr.LexerSharedInputState;
10
11 import antlr.TokenBuffer;
12 import antlr.TokenStreamException;
13 import antlr.TokenStreamIOException;
14 import antlr.ANTLRException;
15 import antlr.LLkParser;
16 import antlr.Token;
17 import antlr.TokenStream;
18 import antlr.RecognitionException;
19 import antlr.NoViableAltException;
20 import antlr.MismatchedTokenException;
21 import antlr.SemanticException;
22 import antlr.ParserSharedInputState;
23 import antlr.collections.impl.BitSet;
24 import antlr.collections.AST;
25 import java.util.Hashtable JavaDoc;
26 import antlr.ASTFactory;
27 import antlr.ASTPair;
28 import antlr.collections.impl.ASTArray;
29
30 /** JSR-241 Groovy Recognizer
31  *
32  * Run 'java Main [-showtree] directory-full-of-groovy-files'
33  *
34  * [The -showtree option pops up a Swing frame that shows
35  * the AST constructed from the parser.]
36  *
37  * Contributing authors:
38  * John Mitchell johnm@non.net
39  * Terence Parr parrt@magelang.com
40  * John Lilley jlilley@empathy.com
41  * Scott Stanchfield thetick@magelang.com
42  * Markus Mohnen mohnen@informatik.rwth-aachen.de
43  * Peter Williams pete.williams@sun.com
44  * Allan Jacobs Allan.Jacobs@eng.sun.com
45  * Steve Messick messick@redhills.com
46  * James Strachan jstrachan@protique.com
47  * John Pybus john@pybus.org
48  * John Rose rose00@mac.com
49  * Jeremy Rayner groovy@ross-rayner.com
50  *
51  * Version 1.00 December 9, 1997 -- initial release
52  * Version 1.01 December 10, 1997
53  * fixed bug in octal def (0..7 not 0..8)
54  * Version 1.10 August 1998 (parrt)
55  * added tree construction
56  * fixed definition of WS,comments for mac,pc,unix newlines
57  * added unary plus
58  * Version 1.11 (Nov 20, 1998)
59  * Added "shutup" option to turn off last ambig warning.
60  * Fixed inner class def to allow named class defs as statements
61  * synchronized requires compound not simple statement
62  * add [] after builtInType DOT class in primaryExpression
63  * "const" is reserved but not valid..removed from modifiers
64  * Version 1.12 (Feb 2, 1999)
65  * Changed LITERAL_xxx to xxx in tree grammar.
66  * Updated java.g to use tokens {...} now for 2.6.0 (new feature).
67  *
68  * Version 1.13 (Apr 23, 1999)
69  * Didn't have (stat)? for else clause in tree parser.
70  * Didn't gen ASTs for interface extends. Updated tree parser too.
71  * Updated to 2.6.0.
72  * Version 1.14 (Jun 20, 1999)
73  * Allowed final/abstract on local classes.
74  * Removed local interfaces from methods
75  * Put instanceof precedence where it belongs...in relationalExpr
76  * It also had expr not type as arg; fixed it.
77  * Missing ! on SEMI in classBlock
78  * fixed: (expr) + "string" was parsed incorrectly (+ as unary plus).
79  * fixed: didn't like Object[].class in parser or tree parser
80  * Version 1.15 (Jun 26, 1999)
81  * Screwed up rule with instanceof in it. :( Fixed.
82  * Tree parser didn't like (expr).something; fixed.
83  * Allowed multiple inheritance in tree grammar. oops.
84  * Version 1.16 (August 22, 1999)
85  * Extending an interface built a wacky tree: had extra EXTENDS.
86  * Tree grammar didn't allow multiple superinterfaces.
87  * Tree grammar didn't allow empty var initializer: {}
88  * Version 1.17 (October 12, 1999)
89  * ESC lexer rule allowed 399 max not 377 max.
90  * java.tree.g didn't handle the expression of synchronized
91  * statements.
92  * Version 1.18 (August 12, 2001)
93  * Terence updated to Java 2 Version 1.3 by
94  * observing/combining work of Allan Jacobs and Steve
95  * Messick. Handles 1.3 src. Summary:
96  * o primary didn't include boolean.class kind of thing
97  * o constructor calls parsed explicitly now:
98  * see explicitConstructorInvocation
99  * o add strictfp modifier
100  * o missing objBlock after new expression in tree grammar
101  * o merged local class definition alternatives, moved after declaration
102  * o fixed problem with ClassName.super.field
103  * o reordered some alternatives to make things more efficient
104  * o long and double constants were not differentiated from int/float
105  * o whitespace rule was inefficient: matched only one char
106  * o add an examples directory with some nasty 1.3 cases
107  * o made Main.java use buffered IO and a Reader for Unicode support
108  * o supports UNICODE?
109  * Using Unicode charVocabulay makes code file big, but only
110  * in the bitsets at the end. I need to make ANTLR generate
111  * unicode bitsets more efficiently.
112  * Version 1.19 (April 25, 2002)
113  * Terence added in nice fixes by John Pybus concerning floating
114  * constants and problems with super() calls. John did a nice
115  * reorg of the primary/postfix expression stuff to read better
116  * and makes f.g.super() parse properly (it was METHOD_CALL not
117  * a SUPER_CTOR_CALL). Also:
118  *
119  * o "finally" clause was a root...made it a child of "try"
120  * o Added stuff for asserts too for Java 1.4, but *commented out*
121  * as it is not backward compatible.
122  *
123  * Version 1.20 (October 27, 2002)
124  *
125  * Terence ended up reorging John Pybus' stuff to
126  * remove some nondeterminisms and some syntactic predicates.
127  * Note that the grammar is stricter now; e.g., this(...) must
128  * be the first statement.
129  *
130  * Trinary ?: operator wasn't working as array name:
131  * (isBig ? bigDigits : digits)[i];
132  *
133  * Checked parser/tree parser on source for
134  * Resin-2.0.5, jive-2.1.1, jdk 1.3.1, Lucene, antlr 2.7.2a4,
135  * and the 110k-line jGuru server source.
136  *
137  * Version 1.21 (October 17, 2003)
138  * Fixed lots of problems including:
139  * Ray Waldin: add typeDefinition to interfaceBlock in java.tree.g
140  * He found a problem/fix with floating point that start with 0
141  * Ray also fixed problem that (int.class) was not recognized.
142  * Thorsten van Ellen noticed that \n are allowed incorrectly in strings.
143  * TJP fixed CHAR_LITERAL analogously.
144  *
145  * Version 1.21.2 (March, 2003)
146  * Changes by Matt Quail to support generics (as per JDK1.5/JSR14)
147  * Notes:
148  * o We only allow the "extends" keyword and not the "implements"
149  * keyword, since thats what JSR14 seems to imply.
150  * o Thanks to Monty Zukowski for his help on the antlr-interest
151  * mail list.
152  * o Thanks to Alan Eliasen for testing the grammar over his
153  * Fink source base
154  *
155  * Version 1.22 (July, 2004)
156  * Changes by Michael Studman to support Java 1.5 language extensions
157  * Notes:
158  * o Added support for annotations types
159  * o Finished off Matt Quail's generics enhancements to support bound type arguments
160  * o Added support for new for statement syntax
161  * o Added support for static import syntax
162  * o Added support for enum types
163  * o Tested against JDK 1.5 source base and source base of jdigraph project
164  * o Thanks to Matt Quail for doing the hard part by doing most of the generics work
165  *
166  * Version 1.22.1 (July 28, 2004)
167  * Bug/omission fixes for Java 1.5 language support
168  * o Fixed tree structure bug with classOrInterface - thanks to Pieter Vangorpto for
169  * spotting this
170  * o Fixed bug where incorrect handling of SR and BSR tokens would cause type
171  * parameters to be recognised as type arguments.
172  * o Enabled type parameters on constructors, annotations on enum constants
173  * and package definitions
174  * o Fixed problems when parsing if ((char.class.equals(c))) {} - solution by Matt Quail at Cenqua
175  *
176  * Version 1.22.2 (July 28, 2004)
177  * Slight refactoring of Java 1.5 language support
178  * o Refactored for/"foreach" productions so that original literal "for" literal
179  * is still used but the for sub-clauses vary by token type
180  * o Fixed bug where type parameter was not included in generic constructor's branch of AST
181  *
182  * Version 1.22.3 (August 26, 2004)
183  * Bug fixes as identified by Michael Stahl; clean up of tabs/spaces
184  * and other refactorings
185  * o Fixed typeParameters omission in identPrimary and newStatement
186  * o Replaced GT reconcilliation code with simple semantic predicate
187  * o Adapted enum/assert keyword checking support from Michael Stahl's java15 grammar
188  * o Refactored typeDefinition production and field productions to reduce duplication
189  *
190  * Version 1.22.4 (October 21, 2004)
191  * Small bux fixes
192  * o Added typeArguments to explicitConstructorInvocation, e.g. new <String>MyParameterised()
193  * o Added typeArguments to postfixExpression productions for anonymous inner class super
194  * constructor invocation, e.g. new Outer().<String>super()
195  * o Fixed bug in array declarations identified by Geoff Roy
196  *
197  * Version 1.22.4.g.1
198  * o I have taken java.g for Java1.5 from Michael Studman (1.22.4)
199  * and have applied the groovy.diff from java.g (1.22) by John Rose
200  * back onto the new root (1.22.4) - Jeremy Rayner (Jan 2005)
201  * o for a map of the task see...
202  * http://groovy.javanicus.com/java-g.png
203  *
204  * This grammar is in the PUBLIC DOMAIN
205  */

206 public class GroovyRecognizer extends antlr.LLkParser implements GroovyTokenTypes
207  {
208
209         /** This factory is the correct way to wire together a Groovy parser and lexer. */
210     public static GroovyRecognizer make(GroovyLexer lexer) {
211         GroovyRecognizer parser = new GroovyRecognizer(lexer.plumb());
212         // TODO: set up a common error-handling control block, to avoid excessive tangle between these guys
213
parser.lexer = lexer;
214         lexer.parser = parser;
215         parser.setASTNodeClass("org.codehaus.groovy.antlr.GroovySourceAST");
216         parser.warningList = new ArrayList();
217         return parser;
218     }
219     // Create a scanner that reads from the input stream passed to us...
220
public static GroovyRecognizer make(InputStream JavaDoc in) { return make(new GroovyLexer(in)); }
221     public static GroovyRecognizer make(Reader JavaDoc in) { return make(new GroovyLexer(in)); }
222     public static GroovyRecognizer make(InputBuffer in) { return make(new GroovyLexer(in)); }
223     public static GroovyRecognizer make(LexerSharedInputState in) { return make(new GroovyLexer(in)); }
224     
225     private static GroovySourceAST dummyVariableToforceClassLoaderToFindASTClass = new GroovySourceAST();
226
227     List warningList;
228     public List getWarningList() { return warningList; }
229     
230     boolean compatibilityMode = true; // for now
231
public boolean isCompatibilityMode() { return compatibilityMode; }
232     public void setCompatibilityMode(boolean z) { compatibilityMode = z; }
233
234     GroovyLexer lexer;
235     public GroovyLexer getLexer() { return lexer; }
236     public void setFilename(String JavaDoc f) { super.setFilename(f); lexer.setFilename(f); }
237     private SourceBuffer sourceBuffer;
238     public void setSourceBuffer(SourceBuffer sourceBuffer) {
239         this.sourceBuffer = sourceBuffer;
240     }
241
242     /** Create an AST node with the token type and text passed in, but
243      * with the same background information as another supplied Token (e.g. line numbers)
244      * to be used in place of antlr tree construction syntax,
245      * i.e. #[TOKEN,"text"] becomes create(TOKEN,"text",anotherToken)
246      *
247      * todo - change antlr.ASTFactory to do this instead...
248      */

249     public AST create(int type, String JavaDoc txt, Token first, Token last) {
250         AST t = astFactory.create(type,txt);
251         if ( t != null && first != null) {
252             // first copy details from first token
253
t.initialize(first);
254             // then ensure that type and txt are specific to this new node
255
t.initialize(type,txt);
256         }
257
258         if ((t instanceof GroovySourceAST) && last != null) {
259             GroovySourceAST node = (GroovySourceAST)t;
260             node.setLast(last);
261
262             // todo - we can populate AST snippets on the fly, but this may be better done as a post-parse decoration
263
if (sourceBuffer != null) {
264                 String JavaDoc snippet = sourceBuffer.getSnippet(
265                                         new LineColumn(first.getLine(),first.getColumn()),
266                                         new LineColumn(last.getLine(),last.getColumn())
267                 );
268                 node.setSnippet(snippet);
269             }
270         }
271         return t;
272     }
273
274
275     // stuff to adjust ANTLR's tracing machinery
276
public static boolean tracing = false; // only effective if antlr.Tool is run with -traceParser
277
public void traceIn(String JavaDoc rname) throws TokenStreamException {
278         if (!GroovyRecognizer.tracing) return;
279         super.traceIn(rname);
280     }
281     public void traceOut(String JavaDoc rname) throws TokenStreamException {
282         if (!GroovyRecognizer.tracing) return;
283         if (returnAST != null) rname += returnAST.toStringList();
284         super.traceOut(rname);
285     }
286         
287     // Error handling. This is a funnel through which parser errors go, when the parser can suggest a solution.
288
public void requireFailed(String JavaDoc problem, String JavaDoc solution) throws SemanticException {
289         // TODO: Needs more work.
290
Token lt = null;
291         try { lt = LT(1); }
292         catch (TokenStreamException ee) { }
293         if (lt == null) lt = Token.badToken;
294         throw new SemanticException(problem + ";\n solution: " + solution,
295                                     getFilename(), lt.getLine(), lt.getColumn());
296     }
297
298     public void addWarning(String JavaDoc warning, String JavaDoc solution) {
299         Token lt = null;
300         try { lt = LT(1); }
301         catch (TokenStreamException ee) { }
302         if (lt == null) lt = Token.badToken;
303
304         Map row = new HashMap();
305         row.put("warning" ,warning);
306         row.put("solution",solution);
307         row.put("filename",getFilename());
308         row.put("line" ,new Integer JavaDoc(lt.getLine()));
309         row.put("column" ,new Integer JavaDoc(lt.getColumn()));
310         // System.out.println(row);
311
warningList.add(row);
312     }
313
314     // Convenience method for checking of expected error syndromes.
315
private void require(boolean z, String JavaDoc problem, String JavaDoc solution) throws SemanticException {
316         if (!z) requireFailed(problem, solution);
317     }
318
319
320     // Query a name token to see if it begins with a capital letter.
321
// This is used to tell the difference (w/o symbol table access) between {String x} and {println x}.
322
private boolean isUpperCase(Token x) {
323         if (x == null || x.getType() != IDENT) return false; // cannot happen?
324
String JavaDoc xtext = x.getText();
325         return (xtext.length() > 0 && Character.isUpperCase(xtext.charAt(0)));
326     }
327
328     private AST currentClass = null; // current enclosing class (for constructor recognition)
329
// Query a name token to see if it is identical with the current class name.
330
// This is used to distinguish constructors from other methods.
331
private boolean isConstructorIdent(Token x) {
332         if (currentClass == null) return false;
333         if (currentClass.getType() != IDENT) return false; // cannot happen?
334
String JavaDoc cname = currentClass.getText();
335
336         if (x == null || x.getType() != IDENT) return false; // cannot happen?
337
return cname.equals(x.getText());
338     }
339
340     // Scratch variable for last 'sep' token.
341
// Written by the 'sep' rule, read only by immediate callers of 'sep'.
342
// (Not entirely clean, but better than a million xx=sep occurrences.)
343
private int sepToken = EOF;
344
345     // Scratch variable for last argument list; tells whether there was a label.
346
// Written by 'argList' rule, read only by immediate callers of 'argList'.
347
private boolean argListHasLabels = false;
348
349     // Scratch variable, holds most recently completed pathExpression.
350
// Read only by immediate callers of 'pathExpression' and 'expression'.
351
private AST lastPathExpression = null;
352
353     // Inherited attribute pushed into most expression rules.
354
// If not zero, it means that the left context of the expression
355
// being parsed is a statement boundary or an initializer sign '='.
356
// Only such expressions are allowed to reach across newlines
357
// to pull in an LCURLY and appended block.
358
private final int LC_STMT = 1, LC_INIT = 2;
359
360     /**
361      * Counts the number of LT seen in the typeArguments production.
362      * It is used in semantic predicates to ensure we have seen
363      * enough closing '>' characters; which actually may have been
364      * either GT, SR or BSR tokens.
365      */

366     private int ltCounter = 0;
367     
368     /* This symbol is used to work around a known ANTLR limitation.
369      * In a loop with syntactic predicate, ANTLR needs help knowing
370      * that the loop exit is a second alternative.
371      * Example usage: ( (LCURLY)=> block | {ANTLR_LOOP_EXIT}? )*
372      * Probably should be an ANTLR RFE.
373      */

374     ////// Original comment in Java grammar:
375
// Unfortunately a syntactic predicate can only select one of
376
// multiple alternatives on the same level, not break out of
377
// an enclosing loop, which is why this ugly hack (a fake
378
// empty alternative with always-false semantic predicate)
379
// is necessary.
380
private static final boolean ANTLR_LOOP_EXIT = false;
381
382 protected GroovyRecognizer(TokenBuffer tokenBuf, int k) {
383   super(tokenBuf,k);
384   tokenNames = _tokenNames;
385   buildTokenTypeASTClassMap();
386   astFactory = new ASTFactory(getTokenTypeToASTClassMap());
387 }
388
389 public GroovyRecognizer(TokenBuffer tokenBuf) {
390   this(tokenBuf,3);
391 }
392
393 protected GroovyRecognizer(TokenStream lexer, int k) {
394   super(lexer,k);
395   tokenNames = _tokenNames;
396   buildTokenTypeASTClassMap();
397   astFactory = new ASTFactory(getTokenTypeToASTClassMap());
398 }
399
400 public GroovyRecognizer(TokenStream lexer) {
401   this(lexer,3);
402 }
403
404 public GroovyRecognizer(ParserSharedInputState state) {
405   super(state,3);
406   tokenNames = _tokenNames;
407   buildTokenTypeASTClassMap();
408   astFactory = new ASTFactory(getTokenTypeToASTClassMap());
409 }
410
411     public final void compilationUnit() throws RecognitionException, TokenStreamException {
412         
413         returnAST = null;
414         ASTPair currentAST = new ASTPair();
415         AST compilationUnit_AST = null;
416         
417         {
418         switch ( LA(1)) {
419         case SH_COMMENT:
420         {
421             match(SH_COMMENT);
422             break;
423         }
424         case EOF:
425         case FINAL:
426         case ABSTRACT:
427         case STRICTFP:
428         case LITERAL_package:
429         case LITERAL_import:
430         case LITERAL_static:
431         case LITERAL_def:
432         case AT:
433         case IDENT:
434         case LBRACK:
435         case LPAREN:
436         case LITERAL_class:
437         case LITERAL_interface:
438         case LITERAL_enum:
439         case LITERAL_super:
440         case LITERAL_void:
441         case LITERAL_boolean:
442         case LITERAL_byte:
443         case LITERAL_char:
444         case LITERAL_short:
445         case LITERAL_int:
446         case LITERAL_float:
447         case LITERAL_long:
448         case LITERAL_double:
449         case LITERAL_any:
450         case STAR:
451         case LITERAL_private:
452         case LITERAL_public:
453         case LITERAL_protected:
454         case LITERAL_transient:
455         case LITERAL_native:
456         case LITERAL_threadsafe:
457         case LITERAL_synchronized:
458         case LITERAL_volatile:
459         case LCURLY:
460         case SEMI:
461         case NLS:
462         case LITERAL_this:
463         case STRING_LITERAL:
464         case LITERAL_if:
465         case LITERAL_while:
466         case LITERAL_with:
467         case LITERAL_switch:
468         case LITERAL_for:
469         case LITERAL_return:
470         case LITERAL_break:
471         case LITERAL_continue:
472         case LITERAL_throw:
473         case LITERAL_assert:
474         case PLUS:
475         case MINUS:
476         case LITERAL_try:
477         case INC:
478         case DEC:
479         case BNOT:
480         case LNOT:
481         case DOLLAR:
482         case STRING_CTOR_START:
483         case LITERAL_new:
484         case LITERAL_true:
485         case LITERAL_false:
486         case LITERAL_null:
487         case NUM_INT:
488         case NUM_FLOAT:
489         case NUM_LONG:
490         case NUM_DOUBLE:
491         case NUM_BIG_INT:
492         case NUM_BIG_DECIMAL:
493         {
494             break;
495         }
496         default:
497         {
498             throw new NoViableAltException(LT(1), getFilename());
499         }
500         }
501         }
502         nls();
503         {
504         boolean synPredMatched5 = false;
505         if (((LA(1)==LITERAL_package||LA(1)==AT) && (LA(2)==IDENT) && (_tokenSet_0.member(LA(3))))) {
506             int _m5 = mark();
507             synPredMatched5 = true;
508             inputState.guessing++;
509             try {
510                 {
511                 annotationsOpt();
512                 match(LITERAL_package);
513                 }
514             }
515             catch (RecognitionException pe) {
516                 synPredMatched5 = false;
517             }
518             rewind(_m5);
519             inputState.guessing--;
520         }
521         if ( synPredMatched5 ) {
522             packageDefinition();
523             astFactory.addASTChild(currentAST, returnAST);
524         }
525         else if ((_tokenSet_1.member(LA(1))) && (_tokenSet_2.member(LA(2))) && (_tokenSet_3.member(LA(3)))) {
526             {
527             switch ( LA(1)) {
528             case FINAL:
529             case ABSTRACT:
530             case STRICTFP:
531             case LITERAL_import:
532             case LITERAL_static:
533             case LITERAL_def:
534             case AT:
535             case IDENT:
536             case LBRACK:
537             case LPAREN:
538             case LITERAL_class:
539             case LITERAL_interface:
540             case LITERAL_enum:
541             case LITERAL_super:
542             case LITERAL_void:
543             case LITERAL_boolean:
544             case LITERAL_byte:
545             case LITERAL_char:
546             case LITERAL_short:
547             case LITERAL_int:
548             case LITERAL_float:
549             case LITERAL_long:
550             case LITERAL_double:
551             case LITERAL_any:
552             case STAR:
553             case LITERAL_private:
554             case LITERAL_public:
555             case LITERAL_protected:
556             case LITERAL_transient:
557             case LITERAL_native:
558             case LITERAL_threadsafe:
559             case LITERAL_synchronized:
560             case LITERAL_volatile:
561             case LCURLY:
562             case LITERAL_this:
563             case STRING_LITERAL:
564             case LITERAL_if:
565             case LITERAL_while:
566             case LITERAL_with:
567             case LITERAL_switch:
568             case LITERAL_for:
569             case LITERAL_return:
570             case LITERAL_break:
571             case LITERAL_continue:
572             case LITERAL_throw:
573             case LITERAL_assert:
574             case PLUS:
575             case MINUS:
576             case LITERAL_try:
577             case INC:
578             case DEC:
579             case BNOT:
580             case LNOT:
581             case DOLLAR:
582             case STRING_CTOR_START:
583             case LITERAL_new:
584             case LITERAL_true:
585             case LITERAL_false:
586             case LITERAL_null:
587             case NUM_INT:
588             case NUM_FLOAT:
589             case NUM_LONG:
590             case NUM_DOUBLE:
591             case NUM_BIG_INT:
592             case NUM_BIG_DECIMAL:
593             {
594                 statement(EOF);
595                 astFactory.addASTChild(currentAST, returnAST);
596                 break;
597             }
598             case EOF:
599             case SEMI:
600             case NLS:
601             {
602                 break;
603             }
604             default:
605             {
606                 throw new NoViableAltException(LT(1), getFilename());
607             }
608             }
609             }
610         }
611         else {
612             throw new NoViableAltException(LT(1), getFilename());
613         }
614         
615         }
616         {
617         _loop9:
618         do {
619             if ((LA(1)==SEMI||LA(1)==NLS)) {
620                 sep();
621                 {
622                 switch ( LA(1)) {
623                 case FINAL:
624                 case ABSTRACT:
625                 case STRICTFP:
626                 case LITERAL_import:
627                 case LITERAL_static:
628                 case LITERAL_def:
629                 case AT:
630                 case IDENT:
631                 case LBRACK:
632                 case LPAREN:
633                 case LITERAL_class:
634                 case LITERAL_interface:
635                 case LITERAL_enum:
636                 case LITERAL_super:
637                 case LITERAL_void:
638                 case LITERAL_boolean:
639                 case LITERAL_byte:
640                 case LITERAL_char:
641                 case LITERAL_short:
642                 case LITERAL_int:
643                 case LITERAL_float:
644                 case LITERAL_long:
645                 case LITERAL_double:
646                 case LITERAL_any:
647                 case STAR:
648                 case LITERAL_private:
649                 case LITERAL_public:
650                 case LITERAL_protected:
651                 case LITERAL_transient:
652                 case LITERAL_native:
653                 case LITERAL_threadsafe:
654                 case LITERAL_synchronized:
655                 case LITERAL_volatile:
656                 case LCURLY:
657                 case LITERAL_this:
658                 case STRING_LITERAL:
659                 case LITERAL_if:
660                 case LITERAL_while:
661                 case LITERAL_with:
662                 case LITERAL_switch:
663                 case LITERAL_for:
664                 case LITERAL_return:
665                 case LITERAL_break:
666                 case LITERAL_continue:
667                 case LITERAL_throw:
668                 case LITERAL_assert:
669                 case PLUS:
670                 case MINUS:
671                 case LITERAL_try:
672                 case INC:
673                 case DEC:
674                 case BNOT:
675                 case LNOT:
676                 case DOLLAR:
677                 case STRING_CTOR_START:
678                 case LITERAL_new:
679                 case LITERAL_true:
680                 case LITERAL_false:
681                 case LITERAL_null:
682                 case NUM_INT:
683                 case NUM_FLOAT:
684                 case NUM_LONG:
685                 case NUM_DOUBLE:
686                 case NUM_BIG_INT:
687                 case NUM_BIG_DECIMAL:
688                 {
689                     statement(sepToken);
690                     astFactory.addASTChild(currentAST, returnAST);
691                     break;
692                 }
693                 case EOF:
694                 case SEMI:
695                 case NLS:
696                 {
697                     break;
698                 }
699                 default:
700                 {
701                     throw new NoViableAltException(LT(1), getFilename());
702                 }
703                 }
704                 }
705             }
706             else {
707                 break _loop9;
708             }
709             
710         } while (true);
711         }
712         match(Token.EOF_TYPE);
713         compilationUnit_AST = (AST)currentAST.root;
714         returnAST = compilationUnit_AST;
715     }
716     
717 /** Zero or more insignificant newlines, all gobbled up and thrown away. */
718     public final void nls() throws RecognitionException, TokenStreamException {
719         
720         returnAST = null;
721         ASTPair currentAST = new ASTPair();
722         AST nls_AST = null;
723         
724         {
725         if ((LA(1)==NLS) && (_tokenSet_4.member(LA(2))) && (_tokenSet_5.member(LA(3)))) {
726             match(NLS);
727         }
728         else if ((_tokenSet_4.member(LA(1))) && (_tokenSet_5.member(LA(2))) && (_tokenSet_5.member(LA(3)))) {
729         }
730         else {
731             throw new NoViableAltException(LT(1), getFilename());
732         }
733         
734         }
735         returnAST = nls_AST;
736     }
737     
738     public final void annotationsOpt() throws RecognitionException, TokenStreamException {
739         
740         returnAST = null;
741         ASTPair currentAST = new ASTPair();
742         AST annotationsOpt_AST = null;
743         Token first = LT(1);
744         
745         {
746         _loop79:
747         do {
748             if ((LA(1)==AT)) {
749                 annotation();
750                 astFactory.addASTChild(currentAST, returnAST);
751                 nls();
752             }
753             else {
754                 break _loop79;
755             }
756             
757         } while (true);
758         }
759         if ( inputState.guessing==0 ) {
760             annotationsOpt_AST = (AST)currentAST.root;
761             annotationsOpt_AST = (AST)astFactory.make( (new ASTArray(2)).add(create(ANNOTATIONS,"ANNOTATIONS",first,LT(1))).add(annotationsOpt_AST));
762             currentAST.root = annotationsOpt_AST;
763             currentAST.child = annotationsOpt_AST!=null &&annotationsOpt_AST.getFirstChild()!=null ?
764                 annotationsOpt_AST.getFirstChild() : annotationsOpt_AST;
765             currentAST.advanceChildToEnd();
766         }
767         annotationsOpt_AST = (AST)currentAST.root;
768         returnAST = annotationsOpt_AST;
769     }
770     
771     public final void packageDefinition() throws RecognitionException, TokenStreamException {
772         
773         returnAST = null;
774         ASTPair currentAST = new ASTPair();
775         AST packageDefinition_AST = null;
776         Token p = null;
777         AST p_AST = null;
778         
779         annotationsOpt();
780         astFactory.addASTChild(currentAST, returnAST);
781         p = LT(1);
782         p_AST = astFactory.create(p);
783         astFactory.makeASTRoot(currentAST, p_AST);
784         match(LITERAL_package);
785         if ( inputState.guessing==0 ) {
786             p_AST.setType(PACKAGE_DEF);
787         }
788         identifier();
789         astFactory.addASTChild(currentAST, returnAST);
790         packageDefinition_AST = (AST)currentAST.root;
791         returnAST = packageDefinition_AST;
792     }
793     
794 /** A statement is an element of a block.
795  * Typical statements are declarations (which are scoped to the block)
796  * and expressions.
797  */

798     public final void statement(
799         int prevToken
800     ) throws RecognitionException, TokenStreamException {
801         
802         returnAST = null;
803         ASTPair currentAST = new ASTPair();
804         AST statement_AST = null;
805         AST pfx_AST = null;
806         AST m_AST = null;
807         Token sp = null;
808         AST sp_AST = null;
809         
810         switch ( LA(1)) {
811         case LITERAL_if:
812         {
813             AST tmp4_AST = null;
814             tmp4_AST = astFactory.create(LT(1));
815             astFactory.makeASTRoot(currentAST, tmp4_AST);
816             match(LITERAL_if);
817             match(LPAREN);
818             strictContextExpression();
819             astFactory.addASTChild(currentAST, returnAST);
820             match(RPAREN);
821             nlsWarn();
822             compatibleBodyStatement();
823             astFactory.addASTChild(currentAST, returnAST);
824             {
825             boolean synPredMatched263 = false;
826             if (((_tokenSet_6.member(LA(1))) && (_tokenSet_7.member(LA(2))) && (_tokenSet_8.member(LA(3))))) {
827                 int _m263 = mark();
828                 synPredMatched263 = true;
829                 inputState.guessing++;
830                 try {
831                     {
832                     {
833                     switch ( LA(1)) {
834                     case SEMI:
835                     case NLS:
836                     {
837                         sep();
838                         break;
839                     }
840                     case LITERAL_else:
841                     {
842                         break;
843                     }
844                     default:
845                     {
846                         throw new NoViableAltException(LT(1), getFilename());
847         &n