/************************************************************************* grammar.ll Version 5.01 Grammar for a java recognizer. Deterministic, so TYPENAME must not be an identifier. This is handled like TYPEDEF in C. Does not process the imports, so need a test harness to specify class/interface declarations. Forward declaration support would require a simple pre-pass. Copyright (c) 2014 DMR, all rights reserved. 10-20-14 Latest online grammar 10-22-14 Removed ambiguities *************************************************************************/ CompilationUnit : Annotation* [ package QualifiedIdentifier ; ] { ImportDeclaration } { TypeDeclaration } Annotation* :! // ambiguous with Modifiers Annotation Annotation* _epsilon_ ImportDeclaration : import [ static ] QualifiedIdentifier [ . * ] ; TypeDeclaration : ClassOrInterfaceDeclaration ; ClassOrInterfaceDeclaration : { Modifier } ClassDeclaration|InterfaceDeclaration ClassDeclaration : NormalClassDeclaration EnumDeclaration InterfaceDeclaration : NormalInterfaceDeclaration AnnotationTypeDeclaration NormalClassDeclaration : class typename_or_id [ TypeParameters ] [ extends TypeOrId ] [ implements TypeList ] ClassBody EnumDeclaration : enum typename_or_id [ implements TypeList ] EnumBody NormalInterfaceDeclaration : interface typename_or_id [ TypeParameters ] [ extends TypeList ] InterfaceBody AnnotationTypeDeclaration : @ interface typename_or_id AnnotationTypeBody []* : // much easier to read \[ \] []* _epsilon_ TypeOrId : BasicType []* ReferenceTypeOrId []* Type : BasicType []* ReferenceType []* BasicType : byte short char int long float double boolean ReferenceTypeOrId : typename_or_id [ TypeArguments ] { . typename_or_id [ TypeArguments ] } ReferenceType : TYPENAME [ TypeArguments ] { . TYPENAME [ TypeArguments ] } TypeArguments : < TypeArgument { , TypeArgument } > TypeArgument : ReferenceTypeOrId ? [ extends|super ReferenceTypeOrId ] NonWildcardTypeArguments : < TypeList > TypeList : ReferenceTypeOrId { , ReferenceTypeOrId } TypeArgumentsOrDiamond : < > TypeArguments NonWildcardTypeArgumentsOrDiamond : < > NonWildcardTypeArguments TypeParameters : < TypeParameter { , TypeParameter } > TypeParameter : id_or_typename [ extends Bound ] Bound : ReferenceTypeOrId { & ReferenceTypeOrId } Modifier : Annotation SimpleModifier SimpleModifier : final public protected private static abstract native synchronized transient volatile strictfp Annotation : @ QualifiedIdentifier [ ( [ AnnotationElement ] ) ] AnnotationElement : ElementValuePairs ElementValue ElementValuePairs : ElementValuePair { , ElementValuePair } ElementValuePair : Identifier = ElementValue ElementValue : Annotation Expression1 ElementValueArrayInitializer ElementValueArrayInitializer : \{ [ ElementValues ] [ , ] \} ElementValues : ElementValue { , ElementValue } ClassBody : \{ { ClassBodyDeclaration } \} ClassBodyDeclaration : ; { Modifier } MemberDecl [ static ] Block MemberDecl : MethodOrFieldDecl void Identifier VoidMethodDeclaratorRest TYPENAME ConstructorDeclaratorRest GenericMethodOrConstructorDecl ClassDeclaration InterfaceDeclaration MethodOrFieldDecl : Type id_or_typename MethodOrFieldRest MethodOrFieldRest : FieldDeclaratorsRest ; MethodDeclaratorRest FieldDeclaratorsRest : VariableDeclaratorRest { , VariableDeclarator } MethodDeclaratorRest : FormalParameters []* [ throws QualifiedIdentifierList ] Block|; VoidMethodDeclaratorRest : FormalParameters [ throws QualifiedIdentifierList ] Block|; ConstructorDeclaratorRest : FormalParameters [ throws QualifiedIdentifierList ] Block GenericMethodOrConstructorDecl : TypeParameters GenericMethodOrConstructorRest GenericMethodOrConstructorRest : Type|void Identifier MethodDeclaratorRest Identifier ConstructorDeclaratorRest InterfaceBody : \{ { InterfaceBodyDeclaration } \} InterfaceBodyDeclaration : ; { Modifier } InterfaceMemberDecl InterfaceMemberDecl : InterfaceMethodOrFieldDecl void Identifier VoidInterfaceMethodDeclaratorRest InterfaceGenericMethodDecl ClassDeclaration InterfaceDeclaration InterfaceMethodOrFieldDecl : Type Identifier InterfaceMethodOrFieldRest InterfaceMethodOrFieldRest : ConstantDeclaratorsRest ; InterfaceMethodDeclaratorRest ConstantDeclaratorsRest : ConstantDeclaratorRest { , ConstantDeclarator } ConstantDeclaratorRest : []* [ = VariableInitializer ] ConstantDeclarator : Identifier ConstantDeclaratorRest InterfaceMethodDeclaratorRest : FormalParameters []* [ throws QualifiedIdentifierList ] ; VoidInterfaceMethodDeclaratorRest : FormalParameters [ throws QualifiedIdentifierList ] ; InterfaceGenericMethodDecl : TypeParameters Type|void Identifier InterfaceMethodDeclaratorRest FormalParameters : ( [ FormalParameterDecls ] ) FormalParameterDecls : { VariableModifier } Type FormalParameterDeclsRest VariableModifier : final Annotation FormalParameterDeclsRest : VariableDeclaratorId [ , FormalParameterDecls ] ... VariableDeclaratorId VariableDeclaratorId : Identifier []* VariableDeclarators : VariableDeclarator { , VariableDeclarator } VariableDeclarator : Identifier VariableDeclaratorRest VariableDeclaratorRest : []* [ = VariableInitializer ] VariableInitializer : ArrayInitializer Expression ArrayInitializer : \{ [ VariableInitializer { , VariableInitializer } [ , ] ] \} Block : \{ { BlockStatement } \} BlockStatement : Statement { Modifier } MoreBlockStatement MoreBlockStatement : ClassDeclaration InterfaceDeclaration Type VariableDeclarators ; Statement : Block ; Identifier : Statement Expression ; if ( Expression ) Statement else_Statement_opt assert Expression [ : Expression ] ; switch ( Expression ) \{ SwitchBlockStatementGroups \} while ( Expression ) Statement do Statement while ( Expression ) ; for ( ForControl ) Statement break [ Identifier ] ; continue [ Identifier ] ; return [ Expression ] ; throw Expression ; synchronized ( Expression ) Block try Block more_try_Block try ResourceSpecification Block [ Catches ] [ Finally ] else_Statement_opt :! else Statement _epsilon_ more_try_Block : Catches [ Finally ] Finally Catches : { CatchClause }+ CatchClause : catch ( { VariableModifier } CatchType Identifier ) Block CatchType : QualifiedIdentifier { | QualifiedIdentifier } Finally : finally Block ResourceSpecification : ( Resources [ ; ] ) Resources : Resource { ; Resource } Resource : { VariableModifier } ReferenceType VariableDeclaratorId = Expression SwitchBlockStatementGroups : { SwitchBlockStatementGroup } SwitchBlockStatementGroup : { SwitchLabel }+ { BlockStatement }+ SwitchLabel : case Expression : case EnumConstantName : default : /*** these are ENUMCONSTANTNAME_ to differentiate from Primary/Identifier EnumConstantName : Identifier **/ ForControl : ForVarControl ForInit ; [ Expression ] ; [ ForUpdate ] ForVarControl : { VariableModifier } Type VariableDeclaratorId ForVarControlRest ForVarControlRest : ForVariableDeclaratorsRest ; [ Expression ] ; [ ForUpdate ] : Expression ForVariableDeclaratorsRest : [ = VariableInitializer ] { , VariableDeclarator } ForInit : Expression { , Expression } ForUpdate : Expression { , Expression } Expression : Expression1 [ AssignmentOperator Expression1 ] AssignmentOperator : = += -= *= /= &= |= ^= %= <<= >>= >>>= Expression1 : Expression2 [ Expression1Rest ] Expression1Rest : ? Expression : Expression1 Expression2 : Expression3 Expression2Rest Expression2Rest : { InfixOp Expression3 } instanceof Type InfixOp : || && | ^ & == != < > <= >= << >> >>> + - * / % Expression3 : PrefixOp Expression3 ( Type ) Expression3 // ( Expression ) is a Primary, so ambiguous // Expression3 Primary { Selector } [ PostfixOp ] PrefixOp : ++ -- ! ~ + - PostfixOp : ++ -- Primary : Literal ( Expression ) this // [ Arguments ] super // SuperSuffix new Creator NonWildcardTypeArguments ExplicitGenericInvocationSuffix|this_Arguments Identifier // { . Identifier } [ IdentifierSuffix ] added to Selector BasicType [ \[ \] ] . class void . class Literal : IntegerLiteral FloatingPointLiteral CharacterLiteral StringLiteral BooleanLiteral NullLiteral Arguments : ( [ Expression { , Expression } ] ) /*** ambiguous with Selector/IdentifierSuffix SuperSuffix : Arguments . Identifier [ Arguments ] */ ExplicitGenericInvocationSuffix : super // SuperSuffix Identifier Arguments Creator : NonWildcardTypeArguments CreatedName ClassCreatorRest CreatedName ClassCreatorRest|ArrayCreatorRest CreatedName : id_or_typename [ TypeArgumentsOrDiamond ] { . id_or_typename [ TypeArgumentsOrDiamond ] } ClassCreatorRest : Arguments [ ClassBody ] ArrayCreatorRest : [] []* ArrayInitializer \[ Expression \] array_selector []* array_selector :! \[ Expression \] array_selector // also in Selector _epsilon_ IdentifierSuffix : \[ []* . class \] Arguments . class // these are in Selector, so ambiguous with Primary { Selector } // . ExplicitGenericInvocation // . this // . super Arguments // . new [ NonWildcardTypeArguments ] InnerCreator // \[ Expression \] ExplicitGenericInvocation : NonWildcardTypeArguments ExplicitGenericInvocationSuffix InnerCreator : Identifier [ NonWildcardTypeArgumentsOrDiamond ] ClassCreatorRest Selector : // . Identifier // [ Arguments ] in IdentifierSuffix . id_or_typename // instead of Identifier . ExplicitGenericInvocation . this . super // SuperSuffix . new [ NonWildcardTypeArguments ] InnerCreator \[ Expression \] IdentifierSuffix EnumBody : \{ [ EnumConstants ] [ , ] [ EnumBodyDeclarations ] \} EnumConstants : EnumConstant { , EnumConstant } EnumConstant : { Annotation } Identifier _action_SetEnumConstantName [ Arguments ] [ ClassBody ] EnumBodyDeclarations : ; { ClassBodyDeclaration } AnnotationTypeBody : \{ { AnnotationTypeElementDeclaration } \} AnnotationTypeElementDeclaration : { Modifier } AnnotationTypeElementRest AnnotationTypeElementRest : Type Identifier AnnotationMethodOrConstantRest ; ClassDeclaration InterfaceDeclaration // EnumDeclaration // this is a ClassDeclaration // AnnotationTypeDeclaration // this is an InterfaceDeclaration AnnotationMethodOrConstantRest : AnnotationMethodRest ConstantDeclaratorsRest AnnotationMethodRest : ( ) [ \[ \] ] [ default ElementValue ] QualifiedIdentifier : id_or_typename { . id_or_typename } typename_or_id : // these need to be TYPENAME _action_SetTypeName Identifier TYPENAME id_or_typename : // leave these as Identifier Identifier TYPENAME QualifiedIdentifierList : QualifiedIdentifier { , QualifiedIdentifier } ClassDeclaration|InterfaceDeclaration : ClassDeclaration InterfaceDeclaration extends|super : extends super Block|; : Block ; Type|void : Type void ExplicitGenericInvocationSuffix|this_Arguments : ExplicitGenericInvocationSuffix this Arguments ClassCreatorRest|ArrayCreatorRest : ClassCreatorRest ArrayCreatorRest =================================================================== slk V4.88 (c) 2001-2014 by DMR else_Statement_opt: ambiguous: nullable can follow itself Conflict 1: parse table conflict under "@": 2: Annotation* --> Annotation Annotation* 3: Annotation* --> Conflict 2: parse table conflict under "[": 16: []* --> [ ] []* 17: []* --> Conflict 3: parse table conflict under "<": 37: TypeArgumentsOrDiamond --> < > 38: TypeArgumentsOrDiamond --> TypeArguments Conflict 4: parse table conflict under "<": 39: NonWildcardTypeArgumentsOrDiamond --> < > 40: NonWildcardTypeArgumentsOrDiamond --> NonWildcardTypeArguments Conflict 5: parse table conflict under "Identifier": 58: AnnotationElement --> ElementValuePairs 59: AnnotationElement --> ElementValue Conflict 6: parse table conflict under "static": 69: ClassBodyDeclaration --> Modifier_* MemberDecl 70: ClassBodyDeclaration --> static_opt Block Conflict 7: parse table conflict under "TYPENAME": 71: MemberDecl --> MethodOrFieldDecl 73: MemberDecl --> TYPENAME ConstructorDeclaratorRest Conflict 8: parse table conflict under "synchronized": 118: BlockStatement --> Statement 119: BlockStatement --> Modifier_* MoreBlockStatement Conflict 9: parse table conflict under "boolean": 118: BlockStatement --> Statement 119: BlockStatement --> Modifier_* MoreBlockStatement Conflict 10: parse table conflict under "double": 118: BlockStatement --> Statement 119: BlockStatement --> Modifier_* MoreBlockStatement Conflict 11: parse table conflict under "float": 118: BlockStatement --> Statement 119: BlockStatement --> Modifier_* MoreBlockStatement Conflict 12: parse table conflict under "long": 118: BlockStatement --> Statement 119: BlockStatement --> Modifier_* MoreBlockStatement Conflict 13: parse table conflict under "int": 118: BlockStatement --> Statement 119: BlockStatement --> Modifier_* MoreBlockStatement Conflict 14: parse table conflict under "char": 118: BlockStatement --> Statement 119: BlockStatement --> Modifier_* MoreBlockStatement Conflict 15: parse table conflict under "short": 118: BlockStatement --> Statement 119: BlockStatement --> Modifier_* MoreBlockStatement Conflict 16: parse table conflict under "byte": 118: BlockStatement --> Statement 119: BlockStatement --> Modifier_* MoreBlockStatement Conflict 17: parse table conflict under "Identifier": 125: Statement --> Identifier : Statement 126: Statement --> Expression ; Conflict 18: parse table conflict under "try": 138: Statement --> try Block more_try_Block 139: Statement --> try ResourceSpecification Block Catches_opt Finally_opt Conflict 19: parse table conflict under "else": 140: else_Statement_opt --> else Statement 141: else_Statement_opt --> Conflict 20: parse table conflict under "case": 153: SwitchLabel --> case Expression : 154: SwitchLabel --> case EnumConstantName : Conflict 21: parse table conflict under "boolean": 156: ForControl --> ForVarControl 157: ForControl --> ForInit ; Expression_opt ; ForUpdate_opt Conflict 22: parse table conflict under "double": 156: ForControl --> ForVarControl 157: ForControl --> ForInit ; Expression_opt ; ForUpdate_opt Conflict 23: parse table conflict under "float": 156: ForControl --> ForVarControl 157: ForControl --> ForInit ; Expression_opt ; ForUpdate_opt Conflict 24: parse table conflict under "long": 156: ForControl --> ForVarControl 157: ForControl --> ForInit ; Expression_opt ; ForUpdate_opt Conflict 25: parse table conflict under "int": 156: ForControl --> ForVarControl 157: ForControl --> ForInit ; Expression_opt ; ForUpdate_opt Conflict 26: parse table conflict under "char": 156: ForControl --> ForVarControl 157: ForControl --> ForInit ; Expression_opt ; ForUpdate_opt Conflict 27: parse table conflict under "short": 156: ForControl --> ForVarControl 157: ForControl --> ForInit ; Expression_opt ; ForUpdate_opt Conflict 28: parse table conflict under "byte": 156: ForControl --> ForVarControl 157: ForControl --> ForInit ; Expression_opt ; ForUpdate_opt Conflict 29: parse table conflict under "(": 202: Expression3 --> ( Type ) Expression3 203: Expression3 --> Primary Selector_* PostfixOp_opt Conflict 30: parse table conflict under "[": 236: array_selector --> [ Expression ] array_selector 237: array_selector --> Conflict 31: parse table conflict under ".": 243: Selector --> . id_or_typename 244: Selector --> . ExplicitGenericInvocation 245: Selector --> . this 246: Selector --> . super 247: Selector --> . new NonWildcardTypeArguments_opt InnerCreator 249: Selector --> IdentifierSuffix Conflict 32: parse table conflict under "[": 248: Selector --> [ Expression ] 249: Selector --> IdentifierSuffix Conflict 33: parse table conflict under "@": 290: Modifier_* --> Modifier Modifier_* 291: Modifier_* --> Conflict 34: parse table conflict under ",": 328: ,_ElementValue_* --> , ElementValue ,_ElementValue_* 329: ,_ElementValue_* --> Conflict 35: parse table conflict under ",": 348: ,_VariableInitializer_* --> , VariableInitializer ,_VariableInitializer_* 349: ,_VariableInitializer_* --> Conflict 36: parse table conflict under ";": 370: ;_Resource_* --> ; Resource ;_Resource_* 371: ;_Resource_* --> Conflict 37: parse table conflict under ",": 408: ,_EnumConstant_* --> , EnumConstant ,_EnumConstant_* 409: ,_EnumConstant_* --> Conflict 38: parse table conflict under ".": 418: ._id_or_typename_* --> . id_or_typename ._id_or_typename_* 419: ._id_or_typename_* --> -------------------------------------------------- Conflicts were ignored by request on 3 nonterminal(s) Conflicts were resolved at lookahead level k=5 total nonterminals = 202 total terminals = 107 total productions = 491 parse table size = 21614 ignored conflicts = 3 total base conflicts = 38 total conflicts = 94 conflict table size = 10058 generating the parser compacting parse table from 21614 to 3152 compacting conflict table from 10058 to 1023