📄 jjtree.jjt
字号:
SimpleNode expansion_choices(ASTProduction p) #BNFChoice(>1) : { }{ expansion(p) ( "|" expansion(p) )* { return (SimpleNode)jjtree.peekNode(); }}void expansion(ASTProduction p) #BNFSequence(>1) : { SimpleNode eu; ASTNodeDescriptor nd = null; }{ ( LOOKAHEAD(1) ( "LOOKAHEAD" "(" local_lookahead(p) ")" ) #BNFLookahead )? ( LOOKAHEAD(0, { notTailOfExpansionUnit() } ) ( eu=expansion_unit(p) [ nd=node_descriptor() ] { if (jjtree.nodeCreated()) { jjtThis.node_scope = new NodeScope(p, nd); jjtThis.expansion_unit = eu; } } ) #ExpansionNodeScope(>1) )+}void local_lookahead(ASTProduction p) : { boolean commaAtEnd = false, emptyLA = true; }{ [ /* * The lookahead of 1 is to turn off the warning message that lets * us know that an expansion choice can also start with an integer * literal because a primary expression can do the same. But we * know that this is what we want. */ LOOKAHEAD(1) IntegerLiteral() { emptyLA = false; } ] [ LOOKAHEAD(0, { !emptyLA && (getToken(1).kind != RPAREN) } ) "," { commaAtEnd = true; } ] [ LOOKAHEAD(0, { getToken(1).kind != RPAREN && getToken(1).kind != LBRACE } ) expansion_choices(p) { emptyLA = false; commaAtEnd = false; } ] [ LOOKAHEAD(0, { !emptyLA && !commaAtEnd && (getToken(1).kind != RPAREN) } ) "," { commaAtEnd = true; } ] [ LOOKAHEAD(0, { emptyLA || commaAtEnd } ) "{" Expression() "}" ]}SimpleNode expansion_unit(ASTProduction p) : { Token t; }{( LOOKAHEAD(1) /* * We give this priority over primary expressions which use LOOKAHEAD as the * name of its identifier. */ ( "LOOKAHEAD" "(" local_lookahead(p) ")" ) #BNFLookahead| Block() #BNFAction| ( "[" expansion_choices(p) "]" ) #BNFZeroOrOne| ( "try" "{" expansion_choices(p) "}" ( "catch" "(" Name() <IDENTIFIER> ")" Block() )* [ "finally" Block() ] ) #BNFTryBlock| LOOKAHEAD( identifier() | StringLiteral() | "<" | PrimaryExpression() "=" )( [ LOOKAHEAD(PrimaryExpression() "=") PrimaryExpression() "=" ] ( regular_expression() | ( identifier() Arguments() ) #BNFNonTerminal )) #BNFAssignment(>1)| t="(" expansion_choices(p) ")" ( "+" #BNFOneOrMore(1) | "*" #BNFZeroOrMore(1) | "?" #BNFZeroOrOne(1) | {} #BNFParenthesized(1) ) { ((SimpleNode)jjtree.peekNode()).setFirstToken(t); }) { return (SimpleNode)jjtree.peekNode(); }}void regular_expression() : { }{ StringLiteral() #REStringLiteral| LOOKAHEAD(3) ( "<" [ [ "#" ] identifier() ":" ] complex_regular_expression_choices() ">" ) #RENamed| LOOKAHEAD(2) ( "<" identifier() ">" ) #REReference| ( "<" "EOF" ">" ) #REEOF}void complex_regular_expression_choices() #REChoice(>1) :{}{ complex_regular_expression() ( "|" complex_regular_expression() )*}void complex_regular_expression() #RESequence(>1) :{}{ ( complex_regular_expression_unit() )+}void complex_regular_expression_unit() : { Token t; }{ StringLiteral() #REStringLiteral| ( "<" identifier() ">" ) #REReference| character_list()| t="(" complex_regular_expression_choices() ")" ( "+" #REOneOrMore(1) | "*" #REZeroOrMore(1) | "?" #REZeroOrOne(1) | {} #REParenthesized(1) ) { ((SimpleNode)jjtree.peekNode()).setFirstToken(t); }}void character_list() #RECharList :{}{ [ "~" ] "[" [ character_descriptor() ( "," character_descriptor() )* ] "]"}void character_descriptor() #CharDescriptor :{}{ StringLiteral() [ "-" StringLiteral() ]}Token identifier() :{ Token t;}{ t=<IDENTIFIER> { return t; }}/********************************************** * THE JJTREE PRODUCTIONS START HERE * **********************************************/ASTNodeDescriptor node_descriptor() #NodeDescriptor :{ Token t, n = null;}{ "#" ( t=identifier() | t=<VOID> ) { jjtThis.name = t.image; } [ LOOKAHEAD(1) "(" [ ">" { jjtThis.isGT = true; } ] node_descriptor_expression() { jjtThis.expression = (ASTNodeDescriptorExpression)jjtree.peekNode(); } ")" ] { jjtThis.setNodeIdValue(); return jjtThis; }}JAVACODEvoid node_descriptor_expression() #NodeDescriptorExpression{ Token tok; int nesting = 1; while (true) { tok = getToken(1); if (tok.kind == 0) { throw new ParseException(); } if (tok.kind == LPAREN) nesting++; if (tok.kind == RPAREN) { nesting--; if (nesting == 0) break; } tok = getNextToken(); }}/********************************************** * THE JAVA GRAMMAR SPECIFICATION STARTS HERE * **********************************************//* * The Java grammar is modified to use sequences of tokens * for the missing tokens - those that include "<<" and ">>". *//* * The following production defines Java identifiers - it * includes the reserved words of JavaCC also. */String JavaIdentifier() :{}{( <IDENTIFIER>| "options"| "LOOKAHEAD"| "IGNORE_CASE"| "PARSER_BEGIN"| "PARSER_END"| "JAVACODE"| "TOKEN"| "SPECIAL_TOKEN"| "MORE"| "SKIP"| "TOKEN_MGR_DECLS"| "EOF") { return token.image; }}/* * The productions for the missing code follows. Obviously * these productions accept more than what is legal in Java, * but that is OK for our purposes. */void ShiftOps() :{}{ "<" "<"| ">" ">" [ ">" ]}void OtherAssignmentOps() :{}{ "<" "<="| ">" [ ">" ] ">="}/* * Program structuring syntax follows. */void CompilationUnit() :/* * The <EOF> is deleted since the compilation unit is embedded * within grammar code. To parse to CompilationUnit, we use * a special production JavaCompilationUnit below. */{}{ [ PackageDeclaration() ] ( ImportDeclaration() )* ( TypeDeclaration() )*}void JavaCompilationUnit() :/* * Use this to parse a Java compilation unit. */{}{ CompilationUnit() <EOF>}void PackageDeclaration() :{ String s;}{ "package" s=Name() ";" { JJTreeGlobals.packageName = s; }}void ImportDeclaration() :{}{ "import" Name() [ "." "*" ] ";"}void TypeDeclaration() :{}{ LOOKAHEAD( ( "abstract" | "final" | "public" )* "class" ) ClassDeclaration()| InterfaceDeclaration()| ";"}/* * Declaration syntax follows. */void ClassDeclaration() :{}{ ( "abstract" | "final" | "public" )* UnmodifiedClassDeclaration()}void UnmodifiedClassDeclaration() :{ Token t = null; String s;}{ "class" s=JavaIdentifier() [ "extends" Name() ] [ t="implements" NameList() ] { if (s.equals(JJTreeGlobals.parserName)) { if (t != null) { JJTreeGlobals.parserImplements = t; } else { JJTreeGlobals.parserImplements = getToken(1); } JJTreeGlobals.parserClassBodyStart = getToken(1); } } 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()}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -