public class Parser
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Parser.ClassDeclarationContext |
static class |
Parser.InterfaceDeclarationContext |
| Modifier and Type | Method and Description |
|---|---|
protected CompileException |
compileException(java.lang.String message)
Convenience method for throwing a CompileException.
|
Scanner |
getScanner() |
Location |
location() |
Java.Atom |
parseAdditiveExpression()
AdditiveExpression :=
MultiplicativeExpression { ( '+' | '-' ) MultiplicativeExpression }
|
Java.Atom |
parseAndExpression()
AndExpression :=
EqualityExpression { '&' EqualityExpression }
|
Java.Rvalue[] |
parseArgumentList()
ArgumentList := Expression { ',' Expression }
|
Java.Rvalue[] |
parseArguments()
Arguments := '(' [ ArgumentList ] ')'
|
Java.ArrayInitializer |
parseArrayInitializer()
ArrayInitializer :=
'{' [ VariableInitializer { ',' VariableInitializer } [ ',' ] '}'
|
Java.Statement |
parseAssertStatement()
AssertStatement := 'assert' Expression [ ':' Expression ] ';'
|
Java.Atom |
parseAssignmentExpression()
AssignmentExpression :=
ConditionalExpression [ AssignmentOperator AssignmentExpression ]
AssignmentOperator :=
'=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' |
'>>=' | '>>>=' | '&=' | '^=' | '|='
|
Java.Block |
parseBlock()
'{' BlockStatements '}'
|
Java.BlockStatement |
parseBlockStatement()
BlockStatement := { Identifier ':' } (
( Modifiers Type | ModifiersOpt BasicType ) LocalVariableDeclarators ';' |
'class' ...
|
java.util.List |
parseBlockStatements()
BlockStatements := { BlockStatement }
|
Java.Statement |
parseBreakStatement()
BreakStatement := 'break' [ Identifier ] ';'
|
void |
parseClassBody(Java.ClassDeclaration classDeclaration)
ClassBody := '{' { ClassBodyDeclaration } '}'
|
void |
parseClassBodyDeclaration(Java.ClassDeclaration classDeclaration)
ClassBodyDeclaration :=
';' |
ModifiersOpt (
Block | // Instance (JLS2 8.6) or static initializer (JLS2 8.7)
'void' Identifier MethodDeclarationRest |
'class' ClassDeclarationRest |
'interface' InterfaceDeclarationRest |
ConstructorDeclarator |
Type Identifier (
MethodDeclarationRest |
FieldDeclarationRest ';'
)
)
|
Java.NamedClassDeclaration |
parseClassDeclarationRest(java.lang.String optionalDocComment,
Java.ModifiersAndAnnotations modifiersAndAnnotations,
Parser.ClassDeclarationContext context)
ClassDeclarationRest :=
Identifier
[ 'extends' ReferenceType ]
[ 'implements' ReferenceTypeList ]
ClassBody
|
Java.CompilationUnit |
parseCompilationUnit()
CompilationUnit := [ PackageDeclaration ]
{ ImportDeclaration }
{ TypeDeclaration }
|
Java.Atom |
parseConditionalAndExpression()
ConditionalAndExpression :=
InclusiveOrExpression { '&&' InclusiveOrExpression }
|
Java.Atom |
parseConditionalExpression()
ConditionalExpression :=
ConditionalOrExpression [ '?' Expression ':' ConditionalExpression ]
|
Java.Atom |
parseConditionalOrExpression()
ConditionalOrExpression :=
ConditionalAndExpression { '||' ConditionalAndExpression ]
|
Java.ConstructorDeclarator |
parseConstructorDeclarator(java.lang.String optionalDocComment,
Java.ModifiersAndAnnotations modifiersAndAnnotations)
ConstructorDeclarator :=
Identifier
FormalParameters
[ 'throws' ReferenceTypeList ]
'{'
[ 'this' Arguments ';' | 'super' Arguments ';' | Primary '.' 'super' Arguments ';' ]
BlockStatements
'}'
|
Java.Statement |
parseContinueStatement()
ContinueStatement := 'continue' [ Identifier ] ';'
|
Java.Rvalue |
parseDimExpr()
DimExpr := '[' Expression ']'
|
Java.Rvalue[] |
parseDimExprs()
DimExprs := DimExpr { DimExpr }
|
Java.Statement |
parseDoStatement()
DoStatement := 'do' Statement 'while' '(' Expression ')' ';'
|
Java.Statement |
parseEmptyStatement()
EmptyStatement := ';'
|
Java.Atom |
parseEqualityExpression()
EqualityExpression :=
RelationalExpression { ( '==' | '!=' ) RelationalExpression }
|
Java.Atom |
parseExclusiveOrExpression()
ExclusiveOrExpression :=
AndExpression { '^' AndExpression }
|
Java.Atom |
parseExpression()
Expression := AssignmentExpression
|
Java.Rvalue[] |
parseExpressionList()
ExpressionList := Expression { ',' Expression }
|
Java.Statement |
parseExpressionStatement()
ExpressionStatement := Expression ';'
|
Java.VariableDeclarator[] |
parseFieldDeclarationRest(java.lang.String name)
FieldDeclarationRest :=
VariableDeclaratorRest
{ ',' VariableDeclarator }
|
Java.FunctionDeclarator.FormalParameter |
parseFormalParameter()
FormalParameter := [ 'final' ] Type Identifier BracketsOpt
|
Java.FunctionDeclarator.FormalParameter[] |
parseFormalParameters()
FormalParameters := '(' [ FormalParameter { ',' FormalParameter } ] ')'
|
Java.Statement |
parseForStatement()
ForStatement :=
'for' '('
[ ForInit ] ';'
[ Expression ] ';'
[ ExpressionList ]
')' Statement
|
Java.Statement |
parseIfStatement()
IfStatement := 'if' '(' Expression ')' Statement [ 'else' Statement ]
|
Java.CompilationUnit.ImportDeclaration |
parseImportDeclaration()
ImportDeclaration := 'import' ImportDeclarationBody ';'
|
Java.CompilationUnit.ImportDeclaration |
parseImportDeclarationBody()
ImportDeclarationBody := [ 'static' ] Identifier { '.' Identifier } [ '.' '*' ]
|
Java.Atom |
parseInclusiveOrExpression()
InclusiveOrExpression :=
ExclusiveOrExpression { '|' ExclusiveOrExpression }
|
void |
parseInterfaceBody(Java.InterfaceDeclaration interfaceDeclaration)
InterfaceBody := '{' {
';' |
ModifiersOpt (
'void' Identifier MethodDeclarationRest |
'class' ClassDeclarationRest |
'interface' InterfaceDeclarationRest |
Type Identifier (
MethodDeclarationRest |
FieldDeclarationRest
)
)
} '}'
|
Java.InterfaceDeclaration |
parseInterfaceDeclarationRest(java.lang.String optionalDocComment,
Java.ModifiersAndAnnotations modifiersAndAnnotations,
Parser.InterfaceDeclarationContext context)
InterfaceDeclarationRest :=
Identifier
[ 'extends' ReferenceTypeList ]
InterfaceBody
|
Java.Statement |
parseLabeledStatement()
LabeledStatement := Identifier ':' Statement
|
Java.Rvalue |
parseLiteral() |
Java.VariableDeclarator[] |
parseLocalVariableDeclarators()
LocalVariableDeclarators := VariableDeclarator { ',' VariableDeclarator }
|
Java.Block |
parseMethodBody()
MethodBody := Block
|
Java.MethodDeclarator |
parseMethodDeclarationRest(java.lang.String optionalDocComment,
Java.ModifiersAndAnnotations modifiersAndAnnotations,
Java.Type type,
java.lang.String name)
MethodDeclarationRest :=
FormalParameters
{ '[' ']' }
[ 'throws' ReferenceTypeList ]
( ';' | MethodBody )
|
Java.ModifiersAndAnnotations |
parseModifiersAndAnnotations()
ModifiersAndAnnotations := { 'public' | 'protected' | 'private' | 'static' | 'abstract' | 'final' | 'native'
| 'synchronized' | 'transient' | 'volatile' | 'strictfp' | Annotation }
|
Java.Atom |
parseMultiplicativeExpression()
MultiplicativeExpression :=
UnaryExpression { ( '*' | '/' | '%' ) UnaryExpression }
|
Java.PackageDeclaration |
parsePackageDeclaration()
PackageDeclaration := 'package' QualifiedIdentifier ';'
|
Java.PackageMemberTypeDeclaration |
parsePackageMemberTypeDeclaration()
PackageMemberTypeDeclaration :=
ModifiersOpt 'class' ClassDeclarationRest |
ModifiersOpt 'interface' InterfaceDeclarationRest
|
Java.Atom |
parsePrimary()
Primary :=
CastExpression | // CastExpression 15.16
'(' Expression ')' | // ParenthesizedExpression 15.8.5
Literal | // Literal 15.8.1
Name | // AmbiguousName
Name Arguments | // MethodInvocation
Name '[]' { '[]' } | // ArrayType 10.1
Name '[]' { '[]' } '.' 'class' | // ClassLiteral 15.8.2
'this' | // This 15.8.3
'this' Arguments | // Alternate constructor invocation 8.8.5.1
'super' Arguments | // Unqualified superclass constructor invocation 8.8.5.1
'super' '.' Identifier | // SuperclassFieldAccess 15.11.2
'super' '.' Identifier Arguments | // SuperclassMethodInvocation 15.12.4.9
NewClassInstance |
NewAnonymousClassInstance | // ClassInstanceCreationExpression 15.9
NewArray | // ArrayCreationExpression 15.10
NewInitializedArray | // ArrayInitializer 10.6
BasicType { '[]' } | // Type
BasicType { '[]' } '.' 'class' | // ClassLiteral 15.8.2
'void' '.' 'class' // ClassLiteral 15.8.2
CastExpression :=
'(' PrimitiveType { '[]' } ')' UnaryExpression |
'(' Expression ')' UnaryExpression
NewClassInstance := 'new' ReferenceType Arguments
NewAnonymousClassInstance := 'new' ReferenceType Arguments [ ClassBody ]
NewArray := 'new' Type DimExprs { '[]' }
NewInitializedArray := 'new' ArrayType ArrayInitializer
|
java.lang.String[] |
parseQualifiedIdentifier()
QualifiedIdentifier := Identifier { '.' Identifier }
|
Java.ReferenceType |
parseReferenceType()
ReferenceType := QualifiedIdentifier
|
Java.ReferenceType[] |
parseReferenceTypeList()
ReferenceTypeList := ReferenceType { ',' ReferenceType }
|
Java.Atom |
parseRelationalExpression()
RelationalExpression :=
ShiftExpression {
( ( '<' | '>' | '<=' | '>=' ) ShiftExpression ) |
( 'instanceof' ReferenceType )
}
|
Java.Statement |
parseReturnStatement()
ReturnStatement := 'return' [ Expression ] ';'
|
Java.Atom |
parseSelector(Java.Atom atom)
Selector :=
'.' Identifier | // FieldAccess 15.11.1
'.' Identifier Arguments | // MethodInvocation
'.' 'this' // QualifiedThis 15.8.4
'.' 'super' Arguments // Qualified superclass constructor invocation (JLS 8.8.5.1)
'.' 'super' '.' Identifier | // SuperclassFieldReference (JLS 15.11.2)
'.' 'super' '.' Identifier Arguments | // SuperclassMethodInvocation (JLS 15.12.4.9)
'.' 'new' Identifier Arguments [ ClassBody ] | // QualifiedClassInstanceCreationExpression 15.9
'.' 'class'
'[' Expression ']' // ArrayAccessExpression 15.13
|
Java.Atom |
parseShiftExpression()
ShiftExpression :=
AdditiveExpression { ( '<<' | '>>' | '>>>' ) AdditiveExpression }
|
Java.Statement |
parseStatement()
Statement :=
LabeledStatement |
Block |
IfStatement |
ForStatement |
WhileStatement |
DoStatement |
TryStatement |
'switch' ...
|
Java.Statement |
parseSwitchStatement()
SwitchStatement :=
'switch' '(' Expression ')' '{' { SwitchLabels BlockStatements } '}'
SwitchLabels := SwitchLabels { SwitchLabels }
SwitchLabel := 'case' Expression ':' | 'default' ':'
|
Java.Statement |
parseSynchronizedStatement()
SynchronizedStatement :=
'synchronized' '(' expression ')' Block
|
Java.Statement |
parseThrowStatement()
ThrowStatement := 'throw' Expression ';'
|
Java.Statement |
parseTryStatement()
TryStatement :=
'try' Block Catches [ Finally ] |
'try' Block Finally
Catches := CatchClause { CatchClause }
CatchClause := 'catch' '(' FormalParameter ')' Block
Finally := 'finally' Block
|
Java.Type |
parseType()
Type := (
'byte' | 'short' | 'char' | 'int' | 'long' |
'float' | 'double' | 'boolean' |
ReferenceType
) { '[' ']' }
|
Java.Atom |
parseUnaryExpression()
UnaryExpression :=
{ PrefixOperator } Primary { Selector } { PostfixOperator }
PrefixOperator := '++' | '--' | '+' | '-' | '~' | '!'
PostfixOperator := '++' | '--'
|
Java.VariableDeclarator |
parseVariableDeclarator()
VariableDeclarator := Identifier VariableDeclaratorRest
|
Java.VariableDeclarator |
parseVariableDeclaratorRest(java.lang.String name)
VariableDeclaratorRest := { '[' ']' } [ '=' VariableInitializer ]
|
Java.ArrayInitializerOrRvalue |
parseVariableInitializer()
VariableInitializer :=
ArrayInitializer |
Expression
|
Java.Statement |
parseWhileStatement()
WhileStatement := 'while' '(' Expression ')' Statement
|
Scanner.Token |
peek() |
int |
peek(int[] types) |
boolean |
peek(java.lang.String value) |
int |
peek(java.lang.String[] values) |
boolean |
peekEof() |
java.lang.String |
peekIdentifier() |
boolean |
peekLiteral() |
Scanner.Token |
peekNextButOne() |
boolean |
peekNextButOne(java.lang.String value) |
boolean |
peekRead(java.lang.String value) |
int |
peekRead(java.lang.String[] values) |
Scanner.Token |
read() |
void |
read(java.lang.String value) |
int |
read(java.lang.String[] values) |
java.lang.String |
readIdentifier() |
java.lang.String |
readOperator() |
void |
setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a
WarningHandler. |
public Parser(Scanner scanner)
public Scanner getScanner()
public Java.CompilationUnit parseCompilationUnit() throws CompileException, java.io.IOException
CompilationUnit := [ PackageDeclaration ]
{ ImportDeclaration }
{ TypeDeclaration }
CompileExceptionjava.io.IOExceptionpublic Java.PackageDeclaration parsePackageDeclaration() throws CompileException, java.io.IOException
PackageDeclaration := 'package' QualifiedIdentifier ';'
CompileExceptionjava.io.IOExceptionpublic Java.CompilationUnit.ImportDeclaration parseImportDeclaration() throws CompileException, java.io.IOException
ImportDeclaration := 'import' ImportDeclarationBody ';'
CompileExceptionjava.io.IOExceptionpublic Java.CompilationUnit.ImportDeclaration parseImportDeclarationBody() throws CompileException, java.io.IOException
ImportDeclarationBody := [ 'static' ] Identifier { '.' Identifier } [ '.' '*' ]
CompileExceptionjava.io.IOExceptionpublic java.lang.String[] parseQualifiedIdentifier()
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic Java.PackageMemberTypeDeclaration parsePackageMemberTypeDeclaration() throws CompileException, java.io.IOException
PackageMemberTypeDeclaration :=
ModifiersOpt 'class' ClassDeclarationRest |
ModifiersOpt 'interface' InterfaceDeclarationRest
CompileExceptionjava.io.IOExceptionpublic Java.ModifiersAndAnnotations parseModifiersAndAnnotations() throws CompileException, java.io.IOException
ModifiersAndAnnotations := { 'public' | 'protected' | 'private' | 'static' | 'abstract' | 'final' | 'native'
| 'synchronized' | 'transient' | 'volatile' | 'strictfp' | Annotation }
CompileExceptionjava.io.IOExceptionpublic Java.NamedClassDeclaration parseClassDeclarationRest(java.lang.String optionalDocComment, Java.ModifiersAndAnnotations modifiersAndAnnotations, Parser.ClassDeclarationContext context) throws CompileException, java.io.IOException
ClassDeclarationRest :=
Identifier
[ 'extends' ReferenceType ]
[ 'implements' ReferenceTypeList ]
ClassBody
CompileExceptionjava.io.IOExceptionpublic void parseClassBody(Java.ClassDeclaration classDeclaration) throws CompileException, java.io.IOException
ClassBody := '{' { ClassBodyDeclaration } '}'
CompileExceptionjava.io.IOExceptionpublic void parseClassBodyDeclaration(Java.ClassDeclaration classDeclaration) throws CompileException, java.io.IOException
ClassBodyDeclaration :=
';' |
ModifiersOpt (
Block | // Instance (JLS2 8.6) or static initializer (JLS2 8.7)
'void' Identifier MethodDeclarationRest |
'class' ClassDeclarationRest |
'interface' InterfaceDeclarationRest |
ConstructorDeclarator |
Type Identifier (
MethodDeclarationRest |
FieldDeclarationRest ';'
)
)
CompileExceptionjava.io.IOExceptionpublic Java.InterfaceDeclaration parseInterfaceDeclarationRest(java.lang.String optionalDocComment, Java.ModifiersAndAnnotations modifiersAndAnnotations, Parser.InterfaceDeclarationContext context) throws CompileException, java.io.IOException
InterfaceDeclarationRest :=
Identifier
[ 'extends' ReferenceTypeList ]
InterfaceBody
CompileExceptionjava.io.IOExceptionpublic void parseInterfaceBody(Java.InterfaceDeclaration interfaceDeclaration) throws CompileException, java.io.IOException
InterfaceBody := '{' {
';' |
ModifiersOpt (
'void' Identifier MethodDeclarationRest |
'class' ClassDeclarationRest |
'interface' InterfaceDeclarationRest |
Type Identifier (
MethodDeclarationRest |
FieldDeclarationRest
)
)
} '}'
CompileExceptionjava.io.IOExceptionpublic Java.ConstructorDeclarator parseConstructorDeclarator(java.lang.String optionalDocComment, Java.ModifiersAndAnnotations modifiersAndAnnotations) throws CompileException, java.io.IOException
ConstructorDeclarator :=
Identifier
FormalParameters
[ 'throws' ReferenceTypeList ]
'{'
[ 'this' Arguments ';' | 'super' Arguments ';' | Primary '.' 'super' Arguments ';' ]
BlockStatements
'}'
CompileExceptionjava.io.IOExceptionpublic Java.MethodDeclarator parseMethodDeclarationRest(java.lang.String optionalDocComment, Java.ModifiersAndAnnotations modifiersAndAnnotations, Java.Type type, java.lang.String name) throws CompileException, java.io.IOException
MethodDeclarationRest :=
FormalParameters
{ '[' ']' }
[ 'throws' ReferenceTypeList ]
( ';' | MethodBody )
CompileExceptionjava.io.IOExceptionpublic Java.ArrayInitializerOrRvalue parseVariableInitializer() throws CompileException, java.io.IOException
VariableInitializer :=
ArrayInitializer |
Expression
CompileExceptionjava.io.IOExceptionpublic Java.ArrayInitializer parseArrayInitializer() throws CompileException, java.io.IOException
ArrayInitializer :=
'{' [ VariableInitializer { ',' VariableInitializer } [ ',' ] '}'
CompileExceptionjava.io.IOExceptionpublic Java.FunctionDeclarator.FormalParameter[] parseFormalParameters() throws CompileException, java.io.IOException
FormalParameters := '(' [ FormalParameter { ',' FormalParameter } ] ')'
CompileExceptionjava.io.IOExceptionpublic Java.FunctionDeclarator.FormalParameter parseFormalParameter() throws CompileException, java.io.IOException
FormalParameter := [ 'final' ] Type Identifier BracketsOpt
CompileExceptionjava.io.IOExceptionpublic Java.Block parseMethodBody() throws CompileException, java.io.IOException
MethodBody := Block
CompileExceptionjava.io.IOExceptionpublic Java.Block parseBlock() throws CompileException, java.io.IOException
'{' BlockStatements '}'
CompileExceptionjava.io.IOExceptionpublic java.util.List parseBlockStatements()
throws CompileException,
java.io.IOException
BlockStatements := { BlockStatement }
CompileExceptionjava.io.IOExceptionpublic Java.BlockStatement parseBlockStatement() throws CompileException, java.io.IOException
BlockStatement := { Identifier ':' } (
( Modifiers Type | ModifiersOpt BasicType ) LocalVariableDeclarators ';' |
'class' ... |
Statement |
'final' Type LocalVariableDeclarators ';' |
Expression ';' |
Expression LocalVariableDeclarators ';' (1)
)
(1) "Expression" must pose a type, and has optional trailing brackets.CompileExceptionjava.io.IOExceptionpublic Java.VariableDeclarator[] parseLocalVariableDeclarators() throws CompileException, java.io.IOException
LocalVariableDeclarators := VariableDeclarator { ',' VariableDeclarator }
CompileExceptionjava.io.IOExceptionpublic Java.VariableDeclarator[] parseFieldDeclarationRest(java.lang.String name) throws CompileException, java.io.IOException
FieldDeclarationRest :=
VariableDeclaratorRest
{ ',' VariableDeclarator }
CompileExceptionjava.io.IOExceptionpublic Java.VariableDeclarator parseVariableDeclarator() throws CompileException, java.io.IOException
VariableDeclarator := Identifier VariableDeclaratorRest
CompileExceptionjava.io.IOExceptionpublic Java.VariableDeclarator parseVariableDeclaratorRest(java.lang.String name) throws CompileException, java.io.IOException
VariableDeclaratorRest := { '[' ']' } [ '=' VariableInitializer ]
Used by field declarations and local variable declarations.CompileExceptionjava.io.IOExceptionpublic Java.Statement parseStatement() throws CompileException, java.io.IOException
Statement :=
LabeledStatement |
Block |
IfStatement |
ForStatement |
WhileStatement |
DoStatement |
TryStatement |
'switch' ... |
'synchronized' ... |
ReturnStatement |
ThrowStatement |
BreakStatement |
ContinueStatement |
EmptyStatement |
ExpressionStatement
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseLabeledStatement() throws CompileException, java.io.IOException
LabeledStatement := Identifier ':' Statement
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseIfStatement() throws CompileException, java.io.IOException
IfStatement := 'if' '(' Expression ')' Statement [ 'else' Statement ]
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseForStatement() throws CompileException, java.io.IOException
ForStatement :=
'for' '('
[ ForInit ] ';'
[ Expression ] ';'
[ ExpressionList ]
')' Statement
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseWhileStatement() throws CompileException, java.io.IOException
WhileStatement := 'while' '(' Expression ')' Statement
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseDoStatement() throws CompileException, java.io.IOException
DoStatement := 'do' Statement 'while' '(' Expression ')' ';'
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseTryStatement() throws CompileException, java.io.IOException
TryStatement :=
'try' Block Catches [ Finally ] |
'try' Block Finally
Catches := CatchClause { CatchClause }
CatchClause := 'catch' '(' FormalParameter ')' Block
Finally := 'finally' Block
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseSwitchStatement() throws CompileException, java.io.IOException
SwitchStatement :=
'switch' '(' Expression ')' '{' { SwitchLabels BlockStatements } '}'
SwitchLabels := SwitchLabels { SwitchLabels }
SwitchLabel := 'case' Expression ':' | 'default' ':'
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseSynchronizedStatement() throws CompileException, java.io.IOException
SynchronizedStatement :=
'synchronized' '(' expression ')' Block
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseReturnStatement() throws CompileException, java.io.IOException
ReturnStatement := 'return' [ Expression ] ';'
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseThrowStatement() throws CompileException, java.io.IOException
ThrowStatement := 'throw' Expression ';'
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseBreakStatement() throws CompileException, java.io.IOException
BreakStatement := 'break' [ Identifier ] ';'
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseContinueStatement() throws CompileException, java.io.IOException
ContinueStatement := 'continue' [ Identifier ] ';'
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseAssertStatement() throws CompileException, java.io.IOException
AssertStatement := 'assert' Expression [ ':' Expression ] ';'
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseEmptyStatement() throws CompileException, java.io.IOException
EmptyStatement := ';'
CompileExceptionjava.io.IOExceptionpublic Java.Rvalue[] parseExpressionList() throws CompileException, java.io.IOException
ExpressionList := Expression { ',' Expression }
CompileExceptionjava.io.IOExceptionpublic Java.Type parseType() throws CompileException, java.io.IOException
Type := (
'byte' | 'short' | 'char' | 'int' | 'long' |
'float' | 'double' | 'boolean' |
ReferenceType
) { '[' ']' }
CompileExceptionjava.io.IOExceptionpublic Java.ReferenceType parseReferenceType() throws CompileException, java.io.IOException
ReferenceType := QualifiedIdentifier
CompileExceptionjava.io.IOExceptionpublic Java.ReferenceType[] parseReferenceTypeList() throws CompileException, java.io.IOException
ReferenceTypeList := ReferenceType { ',' ReferenceType }
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseExpression() throws CompileException, java.io.IOException
Expression := AssignmentExpression
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseAssignmentExpression() throws CompileException, java.io.IOException
AssignmentExpression :=
ConditionalExpression [ AssignmentOperator AssignmentExpression ]
AssignmentOperator :=
'=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' |
'>>=' | '>>>=' | '&=' | '^=' | '|='
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseConditionalExpression() throws CompileException, java.io.IOException
ConditionalExpression :=
ConditionalOrExpression [ '?' Expression ':' ConditionalExpression ]
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseConditionalOrExpression() throws CompileException, java.io.IOException
ConditionalOrExpression :=
ConditionalAndExpression { '||' ConditionalAndExpression ]
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseConditionalAndExpression() throws CompileException, java.io.IOException
ConditionalAndExpression :=
InclusiveOrExpression { '&&' InclusiveOrExpression }
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseInclusiveOrExpression() throws CompileException, java.io.IOException
InclusiveOrExpression :=
ExclusiveOrExpression { '|' ExclusiveOrExpression }
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseExclusiveOrExpression() throws CompileException, java.io.IOException
ExclusiveOrExpression :=
AndExpression { '^' AndExpression }
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseAndExpression() throws CompileException, java.io.IOException
AndExpression :=
EqualityExpression { '&' EqualityExpression }
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseEqualityExpression() throws CompileException, java.io.IOException
EqualityExpression :=
RelationalExpression { ( '==' | '!=' ) RelationalExpression }
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseRelationalExpression() throws CompileException, java.io.IOException
RelationalExpression :=
ShiftExpression {
( ( '<' | '>' | '<=' | '>=' ) ShiftExpression ) |
( 'instanceof' ReferenceType )
}
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseShiftExpression() throws CompileException, java.io.IOException
ShiftExpression :=
AdditiveExpression { ( '<<' | '>>' | '>>>' ) AdditiveExpression }
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseAdditiveExpression() throws CompileException, java.io.IOException
AdditiveExpression :=
MultiplicativeExpression { ( '+' | '-' ) MultiplicativeExpression }
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseMultiplicativeExpression() throws CompileException, java.io.IOException
MultiplicativeExpression :=
UnaryExpression { ( '*' | '/' | '%' ) UnaryExpression }
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseUnaryExpression() throws CompileException, java.io.IOException
UnaryExpression :=
{ PrefixOperator } Primary { Selector } { PostfixOperator }
PrefixOperator := '++' | '--' | '+' | '-' | '~' | '!'
PostfixOperator := '++' | '--'
CompileExceptionjava.io.IOExceptionpublic Java.Atom parsePrimary() throws CompileException, java.io.IOException
Primary :=
CastExpression | // CastExpression 15.16
'(' Expression ')' | // ParenthesizedExpression 15.8.5
Literal | // Literal 15.8.1
Name | // AmbiguousName
Name Arguments | // MethodInvocation
Name '[]' { '[]' } | // ArrayType 10.1
Name '[]' { '[]' } '.' 'class' | // ClassLiteral 15.8.2
'this' | // This 15.8.3
'this' Arguments | // Alternate constructor invocation 8.8.5.1
'super' Arguments | // Unqualified superclass constructor invocation 8.8.5.1
'super' '.' Identifier | // SuperclassFieldAccess 15.11.2
'super' '.' Identifier Arguments | // SuperclassMethodInvocation 15.12.4.9
NewClassInstance |
NewAnonymousClassInstance | // ClassInstanceCreationExpression 15.9
NewArray | // ArrayCreationExpression 15.10
NewInitializedArray | // ArrayInitializer 10.6
BasicType { '[]' } | // Type
BasicType { '[]' } '.' 'class' | // ClassLiteral 15.8.2
'void' '.' 'class' // ClassLiteral 15.8.2
CastExpression :=
'(' PrimitiveType { '[]' } ')' UnaryExpression |
'(' Expression ')' UnaryExpression
NewClassInstance := 'new' ReferenceType Arguments
NewAnonymousClassInstance := 'new' ReferenceType Arguments [ ClassBody ]
NewArray := 'new' Type DimExprs { '[]' }
NewInitializedArray := 'new' ArrayType ArrayInitializer
CompileExceptionjava.io.IOExceptionpublic Java.Atom parseSelector(Java.Atom atom) throws CompileException, java.io.IOException
Selector :=
'.' Identifier | // FieldAccess 15.11.1
'.' Identifier Arguments | // MethodInvocation
'.' 'this' // QualifiedThis 15.8.4
'.' 'super' Arguments // Qualified superclass constructor invocation (JLS 8.8.5.1)
'.' 'super' '.' Identifier | // SuperclassFieldReference (JLS 15.11.2)
'.' 'super' '.' Identifier Arguments | // SuperclassMethodInvocation (JLS 15.12.4.9)
'.' 'new' Identifier Arguments [ ClassBody ] | // QualifiedClassInstanceCreationExpression 15.9
'.' 'class'
'[' Expression ']' // ArrayAccessExpression 15.13
CompileExceptionjava.io.IOExceptionpublic Java.Rvalue[] parseDimExprs() throws CompileException, java.io.IOException
DimExprs := DimExpr { DimExpr }
CompileExceptionjava.io.IOExceptionpublic Java.Rvalue parseDimExpr() throws CompileException, java.io.IOException
DimExpr := '[' Expression ']'
CompileExceptionjava.io.IOExceptionpublic Java.Rvalue[] parseArguments() throws CompileException, java.io.IOException
Arguments := '(' [ ArgumentList ] ')'
CompileExceptionjava.io.IOExceptionpublic Java.Rvalue[] parseArgumentList() throws CompileException, java.io.IOException
ArgumentList := Expression { ',' Expression }
CompileExceptionjava.io.IOExceptionpublic Java.Rvalue parseLiteral() throws CompileException, java.io.IOException
CompileExceptionjava.io.IOExceptionpublic Java.Statement parseExpressionStatement() throws CompileException, java.io.IOException
ExpressionStatement := Expression ';'
CompileExceptionjava.io.IOExceptionpublic Location location()
public Scanner.Token peek() throws CompileException, java.io.IOException
CompileExceptionjava.io.IOExceptionpublic Scanner.Token peekNextButOne() throws CompileException, java.io.IOException
CompileExceptionjava.io.IOExceptionpublic Scanner.Token read() throws CompileException, java.io.IOException
CompileExceptionjava.io.IOExceptionpublic boolean peek(java.lang.String value)
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic int peek(java.lang.String[] values)
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic int peek(int[] types)
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic boolean peekNextButOne(java.lang.String value)
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic void read(java.lang.String value)
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic int read(java.lang.String[] values)
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic boolean peekRead(java.lang.String value)
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic int peekRead(java.lang.String[] values)
throws CompileException,
java.io.IOException
valuesCompileExceptionjava.io.IOExceptionpublic boolean peekEof()
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic java.lang.String peekIdentifier()
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic boolean peekLiteral()
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic java.lang.String readIdentifier()
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic java.lang.String readOperator()
throws CompileException,
java.io.IOException
CompileExceptionjava.io.IOExceptionpublic void setWarningHandler(WarningHandler optionalWarningHandler)
WarningHandler.
Notice that there is no Parser.setErrorHandler() method, but parse errors always throw a CompileException. The reason being is that there is no reasonable way to recover from parse errors and continue
parsing, so there is no need to install a custom parse error handler.
optionalWarningHandler - null to indicate that no warnings be issuedprotected final CompileException compileException(java.lang.String message)