/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package openbook.tools.parser;
// $ANTLR 3.2 Sep 23, 2009 12:02:23 Java.g 2010-05-15 01:06:37

import java.io.IOException;
import java.util.HashMap;

import org.antlr.runtime.BaseRecognizer;
import org.antlr.runtime.BitSet;
import org.antlr.runtime.DFA;
import org.antlr.runtime.EarlyExitException;
import org.antlr.runtime.FailedPredicateException;
import org.antlr.runtime.IntStream;
import org.antlr.runtime.MismatchedSetException;
import org.antlr.runtime.NoViableAltException;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.RecognizerSharedState;
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.debug.DebugEventListener;
import org.antlr.runtime.debug.DebugEventSocketProxy;
import org.antlr.runtime.debug.DebugParser;

/** A Java 1.5 grammar for ANTLR v3 derived from the spec
 *
 *  This is a very close representation of the spec; the changes
 *  are comestic (remove left recursion) and also fixes (the spec
 *  isn't exactly perfect).  I have run this on the 1.4.2 source
 *  and some nasty looking enums from 1.5, but have not really
 *  tested for 1.5 compatibility.
 *
 *  I built this with: java -Xmx100M org.antlr.Tool java.g
 *  and got two errors that are ok (for now):
 *  java.g:691:9: Decision can match input such as
 *    "'0'..'9'{'E', 'e'}{'+', '-'}'0'..'9'{'D', 'F', 'd', 'f'}"
 *    using multiple alternatives: 3, 4
 *  As a result, alternative(s) 4 were disabled for that input
 *  java.g:734:35: Decision can match input such as "{'$', 'A'..'Z',
 *    '_', 'a'..'z', '\u00C0'..'\u00D6', '\u00D8'..'\u00F6',
 *    '\u00F8'..'\u1FFF', '\u3040'..'\u318F', '\u3300'..'\u337F',
 *    '\u3400'..'\u3D2D', '\u4E00'..'\u9FFF', '\uF900'..'\uFAFF'}"
 *    using multiple alternatives: 1, 2
 *  As a result, alternative(s) 2 were disabled for that input
 *
 *  You can turn enum on/off as a keyword :)
 *
 *  Version 1.0 -- initial release July 5, 2006 (requires 3.0b2 or higher)
 *
 *  Primary author: Terence Parr, July 2006
 *
 *  Version 1.0.1 -- corrections by Koen Vanderkimpen & Marko van Dooren,
 *      October 25, 2006;
 *      fixed normalInterfaceDeclaration: now uses typeParameters instead
 *          of typeParameter (according to JLS, 3rd edition)
 *      fixed castExpression: no longer allows expression next to type
 *          (according to semantics in JLS, in contrast with syntax in JLS)
 *
 *  Version 1.0.2 -- Terence Parr, Nov 27, 2006
 *      java spec I built this from had some bizarre for-loop control.
 *          Looked weird and so I looked elsewhere...Yep, it's messed up.
 *          simplified.
 *
 *  Version 1.0.3 -- Chris Hogue, Feb 26, 2007
 *      Factored out an annotationName rule and used it in the annotation rule.
 *          Not sure why, but typeName wasn't recognizing references to inner
 *          annotations (e.g. @InterfaceName.InnerAnnotation())
 *      Factored out the elementValue section of an annotation reference.  Created
 *          elementValuePair and elementValuePairs rules, then used them in the
 *          annotation rule.  Allows it to recognize annotation references with
 *          multiple, comma separated attributes.
 *      Updated elementValueArrayInitializer so that it allows multiple elements.
 *          (It was only allowing 0 or 1 element).
 *      Updated localVariableDeclaration to allow annotations.  Interestingly the JLS
 *          doesn't appear to indicate this is legal, but it does work as of at least
 *          JDK 1.5.0_06.
 *      Moved the Identifier portion of annotationTypeElementRest to annotationMethodRest.
 *          Because annotationConstantRest already references variableDeclarator which
 *          has the Identifier portion in it, the parser would fail on constants in
 *          annotation definitions because it expected two identifiers.
 *      Added optional trailing ';' to the alternatives in annotationTypeElementRest.
 *          Wouldn't handle an inner interface that has a trailing ';'.
 *      Swapped the expression and type rule reference order in castExpression to
 *          make it check for genericized casts first.  It was failing to recognize a
 *          statement like  "Class<Byte> TYPE = (Class<Byte>)...;" because it was seeing
 *          'Class<Byte' in the cast expression as a less than expression, then failing
 *          on the '>'.
 *      Changed createdName to use typeArguments instead of nonWildcardTypeArguments.
 *          Again, JLS doesn't seem to allow this, but java.lang.Class has an example of
 *          of this construct.
 *      Changed the 'this' alternative in primary to allow 'identifierSuffix' rather than
 *          just 'arguments'.  The case it couldn't handle was a call to an explicit
 *          generic method invocation (e.g. this.<E>doSomething()).  Using identifierSuffix
 *          may be overly aggressive--perhaps should create a more constrained thisSuffix rule?
 *
 *  Version 1.0.4 -- Hiroaki Nakamura, May 3, 2007
 *
 *  Fixed formalParameterDecls, localVariableDeclaration, forInit,
 *  and forVarControl to use variableModifier* not 'final'? (annotation)?
 *
 *  Version 1.0.5 -- Terence, June 21, 2007
 *  --a[i].foo didn't work. Fixed unaryExpression
 *
 *  Version 1.0.6 -- John Ridgway, March 17, 2008
 *      Made "assert" a switchable keyword like "enum".
 *      Fixed compilationUnit to disallow "annotation importDeclaration ...".
 *      Changed "Identifier ('.' Identifier)*" to "qualifiedName" in more
 *          places.
 *      Changed modifier* and/or variableModifier* to classOrInterfaceModifiers,
 *          modifiers or variableModifiers, as appropriate.
 *      Renamed "bound" to "typeBound" to better match language in the JLS.
 *      Added "memberDeclaration" which rewrites to methodDeclaration or
 *      fieldDeclaration and pulled type into memberDeclaration.  So we parse
 *          type and then move on to decide whether we're dealing with a field
 *          or a method.
 *      Modified "constructorDeclaration" to use "constructorBody" instead of
 *          "methodBody".  constructorBody starts with explicitConstructorInvocation,
 *          then goes on to blockStatement*.  Pulling explicitConstructorInvocation
 *          out of expressions allowed me to simplify "primary".
 *      Changed variableDeclarator to simplify it.
 *      Changed type to use classOrInterfaceType, thus simplifying it; of course
 *          I then had to add classOrInterfaceType, but it is used in several
 *          places.
 *      Fixed annotations, old version allowed "@X(y,z)", which is illegal.
 *      Added optional comma to end of "elementValueArrayInitializer"; as per JLS.
 *      Changed annotationTypeElementRest to use normalClassDeclaration and
 *          normalInterfaceDeclaration rather than classDeclaration and
 *          interfaceDeclaration, thus getting rid of a couple of grammar ambiguities.
 *      Split localVariableDeclaration into localVariableDeclarationStatement
 *          (includes the terminating semi-colon) and localVariableDeclaration.
 *          This allowed me to use localVariableDeclaration in "forInit" clauses,
 *           simplifying them.
 *      Changed switchBlockStatementGroup to use multiple labels.  This adds an
 *          ambiguity, but if one uses appropriately greedy parsing it yields the
 *           parse that is closest to the meaning of the switch statement.
 *      Renamed "forVarControl" to "enhancedForControl" -- JLS language.
 *      Added semantic predicates to test for shift operations rather than other
 *          things.  Thus, for instance, the string "< <" will never be treated
 *          as a left-shift operator.
 *      In "creator" we rule out "nonWildcardTypeArguments" on arrayCreation,
 *          which are illegal.
 *      Moved "nonWildcardTypeArguments into innerCreator.
 *      Removed 'super' superSuffix from explicitGenericInvocation, since that
 *          is only used in explicitConstructorInvocation at the beginning of a
 *           constructorBody.  (This is part of the simplification of expressions
 *           mentioned earlier.)
 *      Simplified primary (got rid of those things that are only used in
 *          explicitConstructorInvocation).
 *      Lexer -- removed "Exponent?" from FloatingPointLiteral choice 4, since it
 *          led to an ambiguity.
 *
 *      This grammar successfully parses every .java file in the JDK 1.5 source
 *          tree (excluding those whose file names include '-', which are not
 *          valid Java compilation units).
 *
 *  Known remaining problems:
 *      "Letter" and "JavaIDDigit" are wrong.  The actual specification of
 *      "Letter" should be "a character for which the method
 *      Character.isJavaIdentifierStart(int) returns true."  A "Java
 *      letter-or-digit is a character for which the method
 *      Character.isJavaIdentifierPart(int) returns true."
 */
public class JavaParser extends DebugParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "Identifier", "ENUM", "FloatingPointLiteral", "CharacterLiteral", "StringLiteral", "HexLiteral", "OctalLiteral", "DecimalLiteral", "ASSERT", "HexDigit", "IntegerTypeSuffix", "Exponent", "FloatTypeSuffix", "EscapeSequence", "UnicodeEscape", "OctalEscape", "Letter", "JavaIDDigit", "WS", "COMMENT", "LINE_COMMENT", "'package'", "';'", "'import'", "'static'", "'.'", "'*'", "'public'", "'protected'", "'private'", "'abstract'", "'final'", "'strictfp'", "'class'", "'extends'", "'implements'", "'<'", "','", "'>'", "'&'", "'{'", "'}'", "'interface'", "'void'", "'['", "']'", "'throws'", "'='", "'native'", "'synchronized'", "'transient'", "'volatile'", "'boolean'", "'char'", "'byte'", "'short'", "'int'", "'long'", "'float'", "'double'", "'?'", "'super'", "'('", "')'", "'...'", "'this'", "'null'", "'true'", "'false'", "'@'", "'default'", "':'", "'if'", "'else'", "'for'", "'while'", "'do'", "'try'", "'finally'", "'switch'", "'return'", "'throw'", "'break'", "'continue'", "'catch'", "'case'", "'+='", "'-='", "'*='", "'/='", "'&='", "'|='", "'^='", "'%='", "'||'", "'&&'", "'|'", "'^'", "'=='", "'!='", "'instanceof'", "'+'", "'-'", "'/'", "'%'", "'++'", "'--'", "'~'", "'!'", "'new'"
    };
    public static final int T__29=29;
    public static final int T__28=28;
    public static final int T__27=27;
    public static final int T__26=26;
    public static final int FloatTypeSuffix=16;
    public static final int T__25=25;
    public static final int OctalLiteral=10;
    public static final int EOF=-1;
    public static final int Identifier=4;
    public static final int T__93=93;
    public static final int T__94=94;
    public static final int T__91=91;
    public static final int T__92=92;
    public static final int T__90=90;
    public static final int COMMENT=23;
    public static final int T__99=99;
    public static final int T__98=98;
    public static final int T__97=97;
    public static final int T__96=96;
    public static final int T__95=95;
    public static final int T__80=80;
    public static final int T__81=81;
    public static final int T__82=82;
    public static final int T__83=83;
    public static final int LINE_COMMENT=24;
    public static final int IntegerTypeSuffix=14;
    public static final int T__85=85;
    public static final int T__84=84;
    public static final int ASSERT=12;
    public static final int T__87=87;
    public static final int T__86=86;
    public static final int T__89=89;
    public static final int T__88=88;
    public static final int WS=22;
    public static final int T__71=71;
    public static final int T__72=72;
    public static final int T__70=70;
    public static final int FloatingPointLiteral=6;
    public static final int JavaIDDigit=21;
    public static final int T__76=76;
    public static final int T__75=75;
    public static final int T__74=74;
    public static final int Letter=20;
    public static final int EscapeSequence=17;
    public static final int T__73=73;
    public static final int T__79=79;
    public static final int T__78=78;
    public static final int T__77=77;
    public static final int T__68=68;
    public static final int T__69=69;
    public static final int T__66=66;
    public static final int T__67=67;
    public static final int T__64=64;
    public static final int T__65=65;
    public static final int T__62=62;
    public static final int T__63=63;
    public static final int CharacterLiteral=7;
    public static final int Exponent=15;
    public static final int T__61=61;
    public static final int T__60=60;
    public static final int HexDigit=13;
    public static final int T__55=55;
    public static final int T__56=56;
    public static final int T__57=57;
    public static final int T__58=58;
    public static final int T__51=51;
    public static final int T__52=52;
    public static final int T__53=53;
    public static final int T__54=54;
    public static final int T__107=107;
    public static final int T__108=108;
    public static final int T__109=109;
    public static final int T__59=59;
    public static final int T__103=103;
    public static final int T__104=104;
    public static final int T__105=105;
    public static final int T__106=106;
    public static final int T__111=111;
    public static final int T__110=110;
    public static final int T__113=113;
    public static final int T__112=112;
    public static final int T__50=50;
    public static final int T__42=42;
    public static final int HexLiteral=9;
    public static final int T__43=43;
    public static final int T__40=40;
    public static final int T__41=41;
    public static final int T__46=46;
    public static final int T__47=47;
    public static final int T__44=44;
    public static final int T__45=45;
    public static final int T__48=48;
    public static final int T__49=49;
    public static final int T__102=102;
    public static final int T__101=101;
    public static final int T__100=100;
    public static final int DecimalLiteral=11;
    public static final int StringLiteral=8;
    public static final int T__30=30;
    public static final int T__31=31;
    public static final int T__32=32;
    public static final int T__33=33;
    public static final int ENUM=5;
    public static final int T__34=34;
    public static final int T__35=35;
    public static final int T__36=36;
    public static final int T__37=37;
    public static final int T__38=38;
    public static final int T__39=39;
    public static final int UnicodeEscape=18;
    public static final int OctalEscape=19;

    // delegates
    // delegators

    public static final String[] ruleNames = new String[] {
        "invalidRule", "synpred179_Java", "block", "synpred250_Java", "synpred137_Java",
        "synpred169_Java", "synpred154_Java", "catches", "relationalExpression",
        "synpred237_Java", "synpred105_Java", "synpred88_Java", "expression",
        "synpred242_Java", "synpred138_Java", "synpred151_Java", "typeList",
        "formalParameterDecls", "interfaceBodyDeclaration", "synpred74_Java",
        "typeName", "classDeclaration", "synpred252_Java", "selector", "synpred25_Java",
        "synpred7_Java", "modifiers", "exclusiveOrExpression", "synpred11_Java",
        "synpred164_Java", "variableModifiers", "synpred261_Java", "synpred42_Java",
        "synpred128_Java", "synpred245_Java", "synpred264_Java", "synpred100_Java",
        "synpred206_Java", "elementValuePair", "packageDeclaration", "variableModifier",
        "synpred196_Java", "synpred203_Java", "arguments", "synpred149_Java",
        "booleanLiteral", "synpred254_Java", "synpred96_Java", "synpred176_Java",
        "synpred195_Java", "innerCreator", "compilationUnit", "synpred22_Java",
        "integerLiteral", "annotationTypeDeclaration", "synpred165_Java",
        "synpred55_Java", "synpred106_Java", "synpred158_Java", "annotationMethodOrConstantRest",
        "synpred6_Java", "instanceOfExpression", "enumBody", "synpred262_Java",
        "synpred117_Java", "synpred228_Java", "synpred269_Java", "synpred97_Java",
        "synpred112_Java", "interfaceMethodOrFieldDecl", "switchBlockStatementGroups",
        "synpred210_Java", "synpred44_Java", "synpred188_Java", "statementExpression",
        "annotationTypeBody", "synpred170_Java", "synpred120_Java", "interfaceGenericMethodDecl",
        "synpred89_Java", "synpred205_Java", "synpred230_Java", "arrayCreatorRest",
        "synpred75_Java", "synpred130_Java", "annotationTypeElementRest",
        "creator", "variableDeclarator", "synpred93_Java", "synpred115_Java",
        "synpred119_Java", "synpred110_Java", "synpred186_Java", "synpred265_Java",
        "synpred202_Java", "synpred253_Java", "andExpression", "synpred32_Java",
        "synpred135_Java", "synpred148_Java", "synpred132_Java", "conditionalOrExpression",
        "relationalOp", "synpred21_Java", "qualifiedNameList", "synpred58_Java",
        "qualifiedName", "synpred51_Java", "conditionalExpression", "synpred175_Java",
        "synpred90_Java", "synpred181_Java", "synpred31_Java", "shiftExpression",
        "synpred197_Java", "fieldDeclaration", "synpred17_Java", "synpred231_Java",
        "literal", "expressionList", "classBody", "synpred3_Java", "synpred160_Java",
        "synpred190_Java", "synpred20_Java", "synpred219_Java", "synpred235_Java",
        "synpred184_Java", "synpred222_Java", "synpred94_Java", "synpred147_Java",
        "elementValue", "synpred64_Java", "synpred180_Java", "synpred82_Java",
        "synpred30_Java", "synpred26_Java", "statement", "inclusiveOrExpression",
        "multiplicativeExpression", "switchLabel", "synpred168_Java", "blockStatement",
        "synpred111_Java", "synpred270_Java", "synpred134_Java", "synpred236_Java",
        "enhancedForControl", "synpred213_Java", "synpred62_Java", "synpred227_Java",
        "classCreatorRest", "synpred54_Java", "synpred104_Java", "synpred136_Java",
        "synpred191_Java", "interfaceMemberDecl", "enumConstantName", "synpred67_Java",
        "synpred49_Java", "typeParameters", "synpred123_Java", "synpred50_Java",
        "synpred15_Java", "classOrInterfaceModifiers", "catchClause", "shiftOp",
        "synpred63_Java", "synpred86_Java", "synpred212_Java", "normalClassDeclaration",
        "methodDeclaratorRest", "conditionalAndExpression", "synpred79_Java",
        "synpred239_Java", "synpred260_Java", "equalityExpression", "synpred161_Java",
        "synpred221_Java", "annotationMethodRest", "synpred214_Java", "synpred113_Java",
        "synpred92_Java", "synpred101_Java", "synpred234_Java", "synpred272_Java",
        "synpred258_Java", "synpred95_Java", "synpred10_Java", "synpred125_Java",
        "enumBodyDeclarations", "additiveExpression", "synpred133_Java",
        "synpred14_Java", "interfaceMethodDeclaratorRest", "synpred248_Java",
        "synpred208_Java", "formalParameterDeclsRest", "primary", "synpred78_Java",
        "normalInterfaceDeclaration", "synpred145_Java", "synpred85_Java",
        "synpred33_Java", "localVariableDeclaration", "synpred211_Java",
        "synpred204_Java", "primitiveType", "switchBlockStatementGroup",
        "synpred40_Java", "interfaceDeclaration", "formalParameters", "synpred238_Java",
        "synpred99_Java", "synpred56_Java", "synpred177_Java", "synpred37_Java",
        "synpred249_Java", "synpred46_Java", "identifierSuffix", "synpred116_Java",
        "synpred69_Java", "synpred259_Java", "synpred65_Java", "synpred80_Java",
        "synpred68_Java", "synpred66_Java", "elementValuePairs", "synpred71_Java",
        "annotation", "synpred126_Java", "synpred102_Java", "synpred223_Java",
        "synpred87_Java", "synpred27_Java", "synpred34_Java", "arrayInitializer",
        "synpred77_Java", "typeArguments", "synpred187_Java", "synpred140_Java",
        "variableDeclarators", "memberDecl", "voidMethodDeclaratorRest",
        "enumConstant", "typeBound", "synpred70_Java", "synpred224_Java",
        "constructorBody", "synpred84_Java", "interfaceBody", "classOrInterfaceDeclaration",
        "synpred166_Java", "annotationName", "synpred251_Java", "synpred226_Java",
        "synpred189_Java", "synpred246_Java", "forControl", "synpred108_Java",
        "explicitConstructorInvocation", "synpred157_Java", "synpred4_Java",
        "memberDeclaration", "synpred12_Java", "synpred243_Java", "synpred201_Java",
        "parExpression", "synpred209_Java", "typeArgument", "synpred73_Java",
        "synpred167_Java", "synpred53_Java", "synpred59_Java", "classBodyDeclaration",
        "synpred233_Java", "explicitGenericInvocation", "synpred244_Java",
        "synpred215_Java", "synpred139_Java", "synpred122_Java", "synpred266_Java",
        "classOrInterfaceModifier", "synpred267_Java", "genericMethodOrConstructorDecl",
        "synpred271_Java", "synpred183_Java", "synpred216_Java", "nonWildcardTypeArguments",
        "variableDeclaratorId", "synpred131_Java", "constructorDeclaratorRest",
        "synpred268_Java", "typeDeclaration", "annotationTypeElementDeclaration",
        "synpred103_Java", "synpred127_Java", "synpred263_Java", "synpred23_Java",
        "synpred150_Java", "defaultValue", "constantDeclarator", "genericMethodOrConstructorRest",
        "synpred72_Java", "synpred217_Java", "synpred8_Java", "constantExpression",
        "synpred52_Java", "synpred152_Java", "createdName", "synpred178_Java",
        "synpred156_Java", "synpred162_Java", "synpred232_Java", "synpred118_Java",
        "synpred91_Java", "synpred19_Java", "synpred29_Java", "elementValueArrayInitializer",
        "synpred61_Java", "synpred141_Java", "synpred114_Java", "unaryExpression",
        "synpred45_Java", "synpred16_Java", "synpred229_Java", "synpred2_Java",
        "enumConstants", "synpred194_Java", "synpred43_Java", "importDeclaration",
        "localVariableDeclarationStatement", "synpred121_Java", "forUpdate",
        "synpred60_Java", "synpred143_Java", "forInit", "constantDeclaratorsRest",
        "annotationConstantRest", "synpred36_Java", "superSuffix", "synpred39_Java",
        "enumDeclaration", "synpred192_Java", "castExpression", "synpred1_Java",
        "formalParameter", "synpred107_Java", "synpred155_Java", "synpred163_Java",
        "synpred83_Java", "synpred129_Java", "synpred146_Java", "synpred207_Java",
        "synpred13_Java", "synpred218_Java", "classOrInterfaceType", "synpred109_Java",
        "synpred9_Java", "assignmentOperator", "synpred255_Java", "constantDeclaratorRest",
        "variableInitializer", "synpred256_Java", "synpred28_Java", "synpred35_Java",
        "synpred193_Java", "synpred174_Java", "synpred124_Java", "modifier",
        "synpred81_Java", "synpred159_Java", "synpred185_Java", "synpred38_Java",
        "synpred144_Java", "synpred199_Java", "typeParameter", "annotations",
        "synpred173_Java", "synpred172_Java", "synpred18_Java", "packageOrTypeName",
        "synpred241_Java", "synpred153_Java", "synpred247_Java", "synpred48_Java",
        "synpred47_Java", "synpred98_Java", "synpred5_Java", "interfaceMethodOrFieldRest",
        "synpred57_Java", "methodDeclaration", "synpred76_Java", "methodBody",
        "synpred41_Java", "synpred142_Java", "synpred198_Java", "synpred225_Java",
        "unaryExpressionNotPlusMinus", "synpred240_Java", "synpred200_Java",
        "voidInterfaceMethodDeclaratorRest", "synpred182_Java", "synpred24_Java",
        "synpred257_Java", "type", "synpred220_Java", "synpred171_Java"
    };

        public int ruleLevel = 0;
        public int getRuleLevel() { return ruleLevel; }
        public void incRuleLevel() { ruleLevel++; }
        public void decRuleLevel() { ruleLevel--; }
        public JavaParser(TokenStream input) {
            this(input, DebugEventSocketProxy.DEFAULT_DEBUGGER_PORT, new RecognizerSharedState());
        }
        public JavaParser(TokenStream input, int port, RecognizerSharedState state) {
            super(input, state);
            this.state.ruleMemo = new HashMap[407+1];

            DebugEventSocketProxy proxy =
                new DebugEventSocketProxy(this, port, null);
            setDebugListener(proxy);
            try {
                proxy.handshake();
            }
            catch (IOException ioe) {
                reportError(ioe);
            }
        }
    public JavaParser(TokenStream input, DebugEventListener dbg) {
        super(input, dbg, new RecognizerSharedState());
        this.state.ruleMemo = new HashMap[407+1];

    }
    protected boolean evalPredicate(boolean result, String predicate) {
        dbg.semanticPredicate(result, predicate);
        return result;
    }


    @Override
    public String[] getTokenNames() { return JavaParser.tokenNames; }
    @Override
    public String getGrammarFileName() { return "Java.g"; }



    // $ANTLR start "compilationUnit"
    // Java.g:177:1: compilationUnit : ( annotations ( packageDeclaration ( importDeclaration )* ( typeDeclaration )* | classOrInterfaceDeclaration ( typeDeclaration )* ) | ( packageDeclaration )? ( importDeclaration )* ( typeDeclaration )* );
    public final void compilationUnit() throws RecognitionException {
        int compilationUnit_StartIndex = input.index();
        try { dbg.enterRule(getGrammarFileName(), "compilationUnit");
        if ( getRuleLevel()==0 ) {dbg.commence();}
        incRuleLevel();
        dbg.location(177, 1);

        try {
            if ( state.backtracking>0 && alreadyParsedRule(input, 1) ) { return ; }
            // Java.g:178:5: ( annotations ( packageDeclaration ( importDeclaration )* ( typeDeclaration )* | classOrInterfaceDeclaration ( typeDeclaration )* ) | ( packageDeclaration )? ( importDeclaration )* ( typeDeclaration )* )
            int alt8=2;
            try { dbg.enterDecision(8);

            try {
                isCyclicDecision = true;
                alt8 = dfa8.predict(input);
            }
            catch (NoViableAltException nvae) {
                dbg.recognitionException(nvae);
                throw nvae;
            }
            } finally {dbg.exitDecision(8);}

            switch (alt8) {
                case 1 :
                    dbg.enterAlt(1);

                    // Java.g:178:9: annotations ( packageDeclaration ( importDeclaration )* ( typeDeclaration )* | classOrInterfaceDeclaration ( typeDeclaration )* )
                    {
                    dbg.location(178,9);
                    pushFollow(FOLLOW_annotations_in_compilationUnit44);
                    annotations();

                    state._fsp--;
                    if (state.failed) return ;
                    dbg.location(179,9);
                    // Java.g:179:9: ( packageDeclaration ( importDeclaration )* ( typeDeclaration )* | classOrInterfaceDeclaration ( typeDeclaration )* )
                    int alt4=2;
                    try { dbg.enterSubRule(4);
                    try { dbg.enterDecision(4);

                    int LA4_0 = input.LA(1);

                    if ( (LA4_0==25) ) {
                        alt4=1;
                    }
                    else if ( (LA4_0==ENUM||LA4_0==28||(LA4_0>=31 && LA4_0<=37)||LA4_0==46||LA4_0==73) ) {
                        alt4=2;
                    }
                    else {
                        if (state.backtracking>0) {state.failed=true; return ;}
                        NoViableAltException nvae =
                            new NoViableAltException("", 4, 0, input);

                        dbg.recognitionException(nvae);
                        throw nvae;
                    }
                    } finally {dbg.exitDecision(4);}

                    switch (alt4) {
                        case 1 :
                            dbg.enterAlt(1);

                            // Java.g:179:13: packageDeclaration ( importDeclaration )* ( typeDeclaration )*
                            {
                            dbg.location(179,13);
                            pushFollow(FOLLOW_packageDeclaration_in_compilationUnit58);
                            packageDeclaration();

                            state._fsp--;
                            if (state.failed) return ;
                            dbg.location(179,32);
                            // Java.g:179:32: ( importDeclaration )*
                            try { dbg.enterSubRule(1);

                            loop1:
                            do {
                                int alt1=2;
                                try { dbg.enterDecision(1);

                                int LA1_0 = input.LA(1);

                                if ( (LA1_0==27) ) {
                                    alt1=1;
                                }


                                } finally {dbg.exitDecision(1);}

                                switch (alt1) {
                            	case 1 :
                            	    dbg.enterAlt(1);

                            	    // Java.g:0:0: importDeclaration
                            	    {
                            	    dbg.location(179,32);
                            	    pushFollow(FOLLOW_importDeclaration_in_compilationUnit60);
                            	    importDeclaration();

                            	    state._fsp--;
                            	    if (state.failed) return ;

                            	    }
                            	    break;

                            	default :
                            	    break loop1;
                                }
                            } while (true);
                            } finally {dbg.exitSubRule(1);}

                            dbg.location(179,51);
                            // Java.g:179:51: ( typeDeclaration )*
                            try { dbg.enterSubRule(2);

                            loop2:
                            do {
                                int alt2=2;
                                try { dbg.enterDecision(2);

                                int LA2_0 = input.LA(1);

                                if ( (LA2_0==ENUM||LA2_0==26||LA2_0==28||(LA2_0>=31 && LA2_0<=37)||LA2_0==46||LA2_0==73) ) {
                                    alt2=1;
                                }


                                } finally {dbg.exitDecision(2);}

                                switch (alt2) {
                            	case 1 :
                            	    dbg.enterAlt(1);

                            	    // Java.g:0:0: typeDeclaration
                            	    {
                            	    dbg.location(179,51);
                            	    pushFollow(FOLLOW_typeDeclaration_in_compilationUnit63);
                            	    typeDeclaration();

                            	    state._fsp--;
                            	    if (state.failed) return ;

                            	    }
                            	    break;

                            	default :
                            	    break loop2;
                                }
                            } while (true);
                            } finally {dbg.exitSubRule(2);}


                            }
                            break;
                        case 2 :
                            dbg.enterAlt(2);

                            // Java.g:180:13: classOrInterfaceDeclaration ( typeDeclaration )*
                            {
                            dbg.location(180,13);
                            pushFollow(FOLLOW_classOrInterfaceDeclaration_in_compilationUnit78);
                            classOrInterfaceDeclaration();

                            state._fsp--;
                            if (state.failed) return ;
                            dbg.location(180,41);
                            // Java.g:180:41: ( typeDeclaration )*
                            try { dbg.enterSubRule(3);

