📄 javacc.jj
字号:
{ LOOKAHEAD( ( "abstract" | "final" | "public" )* "class" ) ClassDeclaration()| InterfaceDeclaration()| ";"}/* * Declaration syntax follows. */void ClassDeclaration() :{}{ ( "abstract" | "final" | "public" )* UnmodifiedClassDeclaration()}void UnmodifiedClassDeclaration() :{}{ "class" JavaIdentifier() [ "extends" Name() ] [ "implements" NameList() ] ClassBody()}void ClassBody() :{}{ "{" ( ClassBodyDeclaration() )* "}"}void NestedClassDeclaration() :{}{ ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* UnmodifiedClassDeclaration()}void ClassBodyDeclaration() :{}{ LOOKAHEAD(2) Initializer()| LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "class" ) NestedClassDeclaration()| LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "interface" ) NestedInterfaceDeclaration()| LOOKAHEAD( [ "public" | "protected" | "private" ] Name() "(" ) ConstructorDeclaration()| LOOKAHEAD( MethodDeclarationLookahead() ) MethodDeclaration()| FieldDeclaration()}// This production is to determine lookahead only.void MethodDeclarationLookahead() :{}{ ( "public" | "protected" | "private" | "static" | "abstract" | "final" | "native" | "synchronized" )* ResultType() JavaIdentifier() "("}void InterfaceDeclaration() :{}{ ( "abstract" | "public" )* UnmodifiedInterfaceDeclaration()}void NestedInterfaceDeclaration() :{}{ ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* UnmodifiedInterfaceDeclaration()}void UnmodifiedInterfaceDeclaration() :{}{ "interface" JavaIdentifier() [ "extends" NameList() ] "{" ( InterfaceMemberDeclaration() )* "}"}void InterfaceMemberDeclaration() :{}{ LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "class" ) NestedClassDeclaration()| LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "interface" ) NestedInterfaceDeclaration()| LOOKAHEAD( MethodDeclarationLookahead() ) MethodDeclaration()| FieldDeclaration()}void FieldDeclaration() :{}{ ( "public" | "protected" | "private" | "static" | "final" | "transient" | "volatile" )* Type() VariableDeclarator() ( "," VariableDeclarator() )* ";"}void VariableDeclarator() :{}{ VariableDeclaratorId() [ "=" VariableInitializer() ]}void VariableDeclaratorId() :{}{ JavaIdentifier() ( "[" "]" )*}void VariableInitializer() :{}{ ArrayInitializer()| Expression()}void ArrayInitializer() :{}{ "{" [ VariableInitializer() ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}"}void MethodDeclaration() :{}{ ( "public" | "protected" | "private" | "static" | "abstract" | "final" | "native" | "synchronized" )* ResultType() MethodDeclarator() [ "throws" NameList() ] ( Block() | ";" )}void MethodDeclarator() :{}{ JavaIdentifier() FormalParameters() ( "[" "]" )*}void FormalParameters() :{}{ "(" [ FormalParameter() ( "," FormalParameter() )* ] ")"}void FormalParameter() :{}{ [ "final" ] Type() VariableDeclaratorId()}void ConstructorDeclaration() :{}{ [ "public" | "protected" | "private" ] JavaIdentifier() FormalParameters() [ "throws" NameList() ] "{" [ LOOKAHEAD(ExplicitConstructorInvocation()) ExplicitConstructorInvocation() ] ( BlockStatement() )* "}"}void ExplicitConstructorInvocation() :{}{ LOOKAHEAD("this" Arguments() ";") "this" Arguments() ";"| [ LOOKAHEAD(2) PrimaryExpression() "." ] "super" Arguments() ";"}void Initializer() :{}{ [ "static" ] Block()}/* * Type, name and expression syntax follows. */void Type() :{}{ ( PrimitiveType() | Name() ) ( "[" "]" )*}void PrimitiveType() :{}{ "boolean"| "char"| "byte"| "short"| "int"| "long"| "float"| "double"}void ResultType() :{}{ "void"| Type()}void Name() :/* * A lookahead of 2 is required below since "Name" can be followed * by a ".*" when used in the context of an "ImportDeclaration". */{}{ JavaIdentifier() ( LOOKAHEAD(2) "." JavaIdentifier() )*}void NameList() :{}{ Name() ( "," Name() )*}/* * Expression syntax follows. */void Expression() :/* * This expansion has been written this way instead of: * Assignment() | ConditionalExpression() * for performance reasons. * However, it is a weakening of the grammar for it allows the LHS of * assignments to be any conditional expression whereas it can only be * a primary expression. Consider adding a semantic predicate to work * around this. */{}{ ConditionalExpression() [ AssignmentOperator() Expression() ]}void AssignmentOperator() :{}{ "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "&=" | "^=" | "|="| OtherAssignmentOps()}void ConditionalExpression() :{}{ ConditionalOrExpression() [ "?" Expression() ":" ConditionalExpression() ]}void ConditionalOrExpression() :{}{ ConditionalAndExpression() ( "||" ConditionalAndExpression() )*}void ConditionalAndExpression() :{}{ InclusiveOrExpression() ( "&&" InclusiveOrExpression() )*}void InclusiveOrExpression() :{}{ ExclusiveOrExpression() ( "|" ExclusiveOrExpression() )*}void ExclusiveOrExpression() :{}{ AndExpression() ( "^" AndExpression() )*}void AndExpression() :{}{ EqualityExpression() ( "&" EqualityExpression() )*}void EqualityExpression() :{}{ InstanceOfExpression() ( ( "==" | "!=" ) InstanceOfExpression() )*}void InstanceOfExpression() :{}{ RelationalExpression() [ "instanceof" Type() ]}void RelationalExpression() :{}{ /* * The lookahead of 2 below is due to the fact that we have split * the shift and shift assignment operator into multiple tokens that * now clash with these tokens. */ ShiftExpression() ( LOOKAHEAD(2) ( "<" | ">" | "<=" | ">=" ) ShiftExpression() )*}void ShiftExpression() :{}{ /* * The lookahead of 3 below is due to the fact that we have split * the shift and shift assignment operator into multiple tokens that * now clash with these tokens and the relational operators. */ AdditiveExpression() ( LOOKAHEAD(3) ( ShiftOps() ) AdditiveExpression() )*}void AdditiveExpression() :{}{ MultiplicativeExpression() ( ( "+" | "-" ) MultiplicativeExpression() )*}void MultiplicativeExpression() :{}{ UnaryExpression() ( ( "*" | "/" | "%" ) UnaryExpression() )*}void UnaryExpression() :{}{ ( "+" | "-" ) UnaryExpression()| PreIncrementExpression()| PreDecrementExpression()| UnaryExpressionNotPlusMinus()}void PreIncrementExpression() :{}{ "++" PrimaryExpression()}void PreDecrementExpression() :{}{ "--" PrimaryExpression()}void UnaryExpressionNotPlusMinus() :{}{ ( "~" | "!" ) UnaryExpression()| LOOKAHEAD( CastLookahead() ) CastExpression()| PostfixExpression()}// This production is to determine lookahead only. The LOOKAHEAD specifications// below are not used, but they are there just to indicate that we know about// this.void CastLookahead() :{}{ LOOKAHEAD(2) "(" PrimitiveType()| LOOKAHEAD("(" Name() "[") "(" Name() "[" "]"| "(" Name() ")" ( "~" | "!" | "(" | JavaIdentifier() | "this" | "super" | "new" | Literal() )}void PostfixExpression() :{}{ PrimaryExpression() [ "++" | "--" ]}void CastExpression() :{}{ LOOKAHEAD("(" PrimitiveType()) "(" Type() ")" UnaryExpression()| LOOKAHEAD("(" Name()) "(" Type() ")" UnaryExpressionNotPlusMinus()}void PrimaryExpression() :{}{ PrimaryPrefix() ( LOOKAHEAD(2) PrimarySuffix() )*}void PrimaryPrefix() :{}{ Literal()| "this"| "super" "." JavaIdentifier()| "(" Expression() ")"| AllocationExpression()| LOOKAHEAD( ResultType() "." "class" ) ResultType() "." "class"| Name()}void PrimarySuffix() :{}{ LOOKAHEAD(2) "." "this"| LOOKAHEAD(2) "." AllocationExpression()| "[" Expression() "]"| "." JavaIdentifier()| Arguments()}void Literal() :{}{ <INTEGER_LITERAL>| <FLOATING_POINT_LITERAL>| <CHARACTER_LITERAL>| <STRING_LITERAL>| BooleanLiteral()| NullLiteral()}void IntegerLiteral() :{}{ <INTEGER_LITERAL>}void BooleanLiteral() :{}{ "true"| "false"}void StringLiteral() :{}{ <STRING_LITERAL>}void NullLiteral() :{}{ "null"}void Arguments() :{}{ "(" [ ArgumentList() ] ")"}void ArgumentList() :{}{ Expression() ( "," Expression() )*}void AllocationExpression() :{}{ LOOKAHEAD(2) "new" PrimitiveType() ArrayDimsAndInits()| "new" Name() ( ArrayDimsAndInits() | Arguments() [ ClassBody() ] )}/* * The second LOOKAHEAD specification below is to parse to PrimarySuffix * if there is an expression between the "[...]". */void ArrayDimsAndInits() :{}{ LOOKAHEAD(2) ( LOOKAHEAD(2) "[" Expression() "]" )+ ( LOOKAHEAD(2) "[" "]" )*| ( "[" "]" )+ ArrayInitializer()}/* * Statement syntax follows. */void Statement() :{}{ LOOKAHEAD(2) LabeledStatement()| Block()| EmptyStatement()| StatementExpression() ";"| SwitchStatement()| IfStatement()| WhileStatement()| DoStatement()| ForStatement()| BreakStatement()| ContinueStatement()| ReturnStatement()| ThrowStatement()| SynchronizedStatement()| TryStatement()}void LabeledStatement() :{}{ JavaIdentifier() ":" Statement()}void Block() :{}{ "{" ( BlockStatement() )* "}"}void BlockStatement() :{}{ LOOKAHEAD([ "final" ] Type() JavaIdentifier()) LocalVariableDeclaration() ";"| Statement()| UnmodifiedClassDeclaration()| UnmodifiedInterfaceDeclaration()}void LocalVariableDeclaration() :{}{ [ "final" ] Type() VariableDeclarator() ( "," VariableDeclarator() )*}void EmptyStatement() :{}{ ";"}void StatementExpression() :/* * The last expansion of this production accepts more than the legal * Java expansions for StatementExpression. This expansion does not * use PostfixExpression for performance reasons. */{}{ PreIncrementExpression()| PreDecrementExpression()| PrimaryExpression() [ "++" | "--" | AssignmentOperator() Expression() ]}void SwitchStatement() :{}{ "switch" "(" Expression() ")" "{" ( SwitchLabel() ( BlockStatement() )* )* "}"}void SwitchLabel() :{}{ "case" Expression() ":"| "default" ":"}void IfStatement() :/* * The disambiguating algorithm of JavaCC automatically binds dangling * else's to the innermost if statement. The LOOKAHEAD specification * is to tell JavaCC that we know what we are doing. */{}{ "if" "(" Expression() ")" Statement() [ LOOKAHEAD(1) "else" Statement() ]}void WhileStatement() :{}{ "while" "(" Expression() ")" Statement()}void DoStatement() :{}{ "do" Statement() "while" "(" Expression() ")" ";"}void ForStatement() :{}{ "for" "(" [ ForInit() ] ";" [ Expression() ] ";" [ ForUpdate() ] ")" Statement()}void ForInit() :{}{ LOOKAHEAD( [ "final" ] Type() JavaIdentifier() ) LocalVariableDeclaration()| StatementExpressionList()}void StatementExpressionList() :{}{ StatementExpression() ( "," StatementExpression() )*}void ForUpdate() :{}{ StatementExpressionList()}void BreakStatement() :{}{ "break" [ JavaIdentifier() ] ";"}void ContinueStatement() :{}{ "continue" [ JavaIdentifier() ] ";"}void ReturnStatement() :{}{ "return" [ Expression() ] ";"}void ThrowStatement() :{}{ "throw" Expression() ";"}void SynchronizedStatement() :{}{ "synchronized" "(" Expression() ")" Block()}void TryStatement() :/* * Semantic check required here to make sure that at least one * finally/catch is present. */{}{ "try" Block() ( "catch" "(" FormalParameter() ")" Block() )* [ "finally" Block() ]}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -