Package org.codehaus.janino
Class Parser
- java.lang.Object
-
- org.codehaus.janino.Parser
-
public class Parser extends Object
A parser for the Java™ programming language.'JLS7' refers to the Java Language Specification, Java SE 7 Edition.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classParser.ClassDeclarationContextEnumerator for the kinds of context where a class declaration can occur.static classParser.InterfaceDeclarationContextEnumerator for the kinds of context where an interface declaration can occur.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CompileExceptioncompileException(String message)Convenience method for throwing aCompileException.ScannergetScanner()Locationlocation()Java.AtomparseAdditiveExpression()AdditiveExpression := MultiplicativeExpression { ( '+' | '-' ) MultiplicativeExpression }Java.AtomparseAndExpression()AndExpression := EqualityExpression { '&' EqualityExpression }Java.Rvalue[]parseArgumentList()ArgumentList := Expression { ',' Expression }Java.Rvalue[]parseArguments()Arguments := '(' [ ArgumentList ] ')'Java.ArrayInitializerparseArrayInitializer()ArrayInitializer := '{' [ VariableInitializer { ',' VariableInitializer } [ ',' ] '}'Java.StatementparseAssertStatement()AssertStatement := 'assert' Expression [ ':' Expression ] ';'Java.AtomparseAssignmentExpression()AssignmentExpression := ConditionalExpression [ AssignmentOperator AssignmentExpression ] AssignmentOperator := '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|='Java.BlockparseBlock()'{' BlockStatements '}'Java.BlockStatementparseBlockStatement()BlockStatement := { Identifier ':' } ( ( Modifiers Type | ModifiersOpt BasicType ) VariableDeclarators ';' | 'class' ...List<Java.BlockStatement>parseBlockStatements()BlockStatements := { BlockStatement }Java.StatementparseBreakStatement()BreakStatement := 'break' [ Identifier ] ';'voidparseClassBody(Java.ClassDeclaration classDeclaration)ClassBody := '{' { ClassBodyDeclaration } '}'voidparseClassBodyDeclaration(Java.ClassDeclaration classDeclaration)ClassBodyDeclaration := ';' | ModifiersOpt ( Block | // Instance (JLS7 8.6) or static initializer (JLS7 8.7) 'void' Identifier MethodDeclarationRest | 'class' ClassDeclarationRest | 'interface' InterfaceDeclarationRest | ConstructorDeclarator | Type Identifier ( MethodDeclarationRest | FieldDeclarationRest ';' ) )Java.NamedClassDeclarationparseClassDeclarationRest(String optionalDocComment, Java.Modifiers modifiers, Parser.ClassDeclarationContext context)ClassDeclarationRest := Identifier [ typeParameters ] [ 'extends' ReferenceType ] [ 'implements' ReferenceTypeList ] ClassBodyJava.CompilationUnitparseCompilationUnit()CompilationUnit := [ PackageDeclaration ] { ImportDeclaration } { TypeDeclaration }Java.AtomparseConditionalAndExpression()ConditionalAndExpression := InclusiveOrExpression { '&&' InclusiveOrExpression }Java.AtomparseConditionalExpression()ConditionalExpression := ConditionalOrExpression [ '?' Expression ':' ConditionalExpression ]Java.AtomparseConditionalOrExpression()ConditionalOrExpression := ConditionalAndExpression { '||' ConditionalAndExpression ]Java.ConstructorDeclaratorparseConstructorDeclarator(String optionalDocComment, Java.Modifiers modifiers)ConstructorDeclarator := Identifier FormalParameters [ 'throws' ReferenceTypeList ] '{' [ 'this' Arguments ';' | 'super' Arguments ';' | Primary '.' 'super' Arguments ';' ] BlockStatements '}'Java.StatementparseContinueStatement()ContinueStatement := 'continue' [ Identifier ] ';'Java.RvalueparseDimExpr()DimExpr := '[' Expression ']'Java.Rvalue[]parseDimExprs()DimExprs := DimExpr { DimExpr }Java.StatementparseDoStatement()DoStatement := 'do' Statement 'while' '(' Expression ')' ';'Java.StatementparseEmptyStatement()EmptyStatement := ';'Java.AtomparseEqualityExpression()EqualityExpression := RelationalExpression { ( '==' | '!=' ) RelationalExpression }Java.AtomparseExclusiveOrExpression()ExclusiveOrExpression := AndExpression { '^' AndExpression }Java.AtomparseExpression()Expression := AssignmentExpressionJava.Rvalue[]parseExpressionList()ExpressionList := Expression { ',' Expression }Java.StatementparseExpressionStatement()ExpressionStatement := Expression ';'Java.VariableDeclarator[]parseFieldDeclarationRest(String name)FieldDeclarationRest := VariableDeclaratorRest { ',' VariableDeclarator }Java.FunctionDeclarator.FormalParameterparseFormalParameter(boolean[] hasEllipsis)FormalParameter := [ 'final' ] Type [ '.' '.' '.' ] Identifier BracketsOptJava.FunctionDeclarator.FormalParametersparseFormalParameters()FormalParameters := '(' [ FormalParameter { ',' FormalParameter } ] ')'Java.StatementparseForStatement()ForStatement := 'for' '(' [ ForInit ] ';' [ Expression ] ';' [ ExpressionList ] ')' Statement | 'for' '(' FormalParameter ':' Expression ')' Statement ForInit := Modifiers Type VariableDeclarators | ModifiersOpt BasicType VariableDeclarators | Expression VariableDeclarators (1) | Expression { ',' Expression }Java.StatementparseIfStatement()IfStatement := 'if' '(' Expression ')' Statement [ 'else' Statement ]Java.CompilationUnit.ImportDeclarationparseImportDeclaration()ImportDeclaration := 'import' ImportDeclarationBody ';'Java.CompilationUnit.ImportDeclarationparseImportDeclarationBody()ImportDeclarationBody := [ 'static' ] Identifier { '.' Identifier } [ '.' '*' ]Java.AtomparseInclusiveOrExpression()InclusiveOrExpression := ExclusiveOrExpression { '|' ExclusiveOrExpression }voidparseInterfaceBody(Java.InterfaceDeclaration interfaceDeclaration)InterfaceBody := '{' { ';' | ModifiersOpt ( 'void' Identifier MethodDeclarationRest | 'class' ClassDeclarationRest | 'interface' InterfaceDeclarationRest | Type Identifier ( MethodDeclarationRest | FieldDeclarationRest ) ) } '}'Java.InterfaceDeclarationparseInterfaceDeclarationRest(String optionalDocComment, Java.Modifiers modifiers, Parser.InterfaceDeclarationContext context)InterfaceDeclarationRest := Identifier [ typeParameters ] [ 'extends' ReferenceTypeList ] InterfaceBodyJava.StatementparseLabeledStatement()LabeledStatement := Identifier ':' StatementJava.RvalueparseLiteral()Literal := IntegerLiteral | FloatingPointLiteral | BooleanLiteral | CharacterLiteral | StringLiteral | NullLiteralJava.BlockparseMethodBody()MethodBody := BlockJava.MethodDeclaratorparseMethodDeclarationRest(String optionalDocComment, Java.Modifiers modifiers, Java.Type type, String name)MethodDeclarationRest := FormalParameters { '[' ']' } [ 'throws' ReferenceTypeList ] ( ';' | MethodBody )Java.ModifiersparseModifiers()ModifiersAndAnnotations := { 'public' | 'protected' | 'private' | 'static' | 'abstract' | 'final' | 'native' | 'synchronized' | 'transient' | 'volatile' | 'strictfp' | Annotation }Java.AtomparseMultiplicativeExpression()MultiplicativeExpression := UnaryExpression { ( '*' | '/' | '%' ) UnaryExpression }Java.PackageDeclarationparsePackageDeclaration()PackageDeclaration := 'package' QualifiedIdentifier ';'Java.PackageMemberTypeDeclarationparsePackageMemberTypeDeclaration()PackageMemberTypeDeclaration := ModifiersOpt 'class' ClassDeclarationRest | ModifiersOpt 'interface' InterfaceDeclarationRestJava.AtomparsePrimary()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 ArrayInitializerString[]parseQualifiedIdentifier()QualifiedIdentifier := Identifier { '.' Identifier }Java.ReferenceTypeparseReferenceType()ReferenceType := QualifiedIdentifier [ TypeArguments ]Java.ReferenceType[]parseReferenceTypeList()ReferenceTypeList := ReferenceType { ',' ReferenceType }Java.AtomparseRelationalExpression()RelationalExpression := ShiftExpression { 'instanceof' ReferenceType | '<' ShiftExpression [ { ',' TypeArgument } '>' ] | '<' TypeArgument [ { ',' TypeArgument } '>' ] | ( '>' | '<=' | '>=' ) ShiftExpression }Java.StatementparseReturnStatement()ReturnStatement := 'return' [ Expression ] ';'Java.AtomparseSelector(Java.Atom atom)Selector := '.' Identifier | // FieldAccess 15.11.1 '.' Identifier Arguments | // MethodInvocation '.' 'this' // QualifiedThis 15.8.4 '.' 'super' Arguments // Qualified superclass constructor invocation (JLS7 8.8.7.1) '.' 'super' '.' Identifier | // SuperclassFieldReference (JLS7 15.11.2) '.' 'super' '.' Identifier Arguments | // SuperclassMethodInvocation (JLS7 15.12.3) '.' 'new' Identifier Arguments [ ClassBody ] | // QualifiedClassInstanceCreationExpression 15.9 '.' 'class' '[' Expression ']' // ArrayAccessExpression 15.13Java.AtomparseShiftExpression()ShiftExpression := AdditiveExpression { ( '<<' | '>>' | '>>>' ) AdditiveExpression }Java.StatementparseStatement()Statement := LabeledStatement | Block | IfStatement | ForStatement | WhileStatement | DoStatement | TryStatement | 'switch' ...Java.StatementparseSwitchStatement()SwitchStatement := 'switch' '(' Expression ')' '{' { SwitchLabels BlockStatements } '}' SwitchLabels := SwitchLabels { SwitchLabels } SwitchLabel := 'case' Expression ':' | 'default' ':'Java.StatementparseSynchronizedStatement()SynchronizedStatement := 'synchronized' '(' expression ')' BlockJava.StatementparseThrowStatement()ThrowStatement := 'throw' Expression ';'Java.StatementparseTryStatement()TryStatement := 'try' Block Catches [ Finally ] | 'try' Block Finally Catches := CatchClause { CatchClause } CatchClause := 'catch' '(' FormalParameter ')' Block Finally := 'finally' BlockJava.TypeparseType()Type := ( 'byte' | 'short' | 'char' | 'int' | 'long' | 'float' | 'double' | 'boolean' | ReferenceType ) { '[' ']' }Java.AtomparseUnaryExpression()UnaryExpression := { PrefixOperator } Primary { Selector } { PostfixOperator } PrefixOperator := '++' | '--' | '+' | '-' | '~' | '!' PostfixOperator := '++' | '--'Java.VariableDeclaratorparseVariableDeclarator()VariableDeclarator := Identifier VariableDeclaratorRestJava.VariableDeclaratorparseVariableDeclaratorRest(String name)VariableDeclaratorRest := { '[' ']' } [ '=' VariableInitializer ]Java.VariableDeclarator[]parseVariableDeclarators()VariableDeclarators := VariableDeclarator { ',' VariableDeclarator }Java.ArrayInitializerOrRvalueparseVariableInitializer()VariableInitializer := ArrayInitializer | ExpressionJava.StatementparseWhileStatement()WhileStatement := 'while' '(' Expression ')' StatementScanner.Tokenpeek()intpeek(int[] suspected)Checks whether the type of the next token is any of thesuspected; does not consume the next token.booleanpeek(String suspected)intpeek(String[] suspected)Checks whether the value of the next token equals any of thesuspected; does not consume the next token.booleanpeekEof()StringpeekIdentifier()booleanpeekLiteral()Scanner.TokenpeekNextButOne()booleanpeekNextButOne(String suspected)booleanpeekRead(String suspected)intpeekRead(String[] values)Scanner.Tokenread()voidread(String expected)Verifies that the value of the next token equalsexpected, and consumes the token.intread(String[] expected)Verifies that the value of the next token equals one of theexpected, and consumes the token.StringreadIdentifier()StringreadOperator()voidsetWarningHandler(WarningHandler optionalWarningHandler)By default, warnings are discarded, but an application my install aWarningHandler.
-
-
-
Constructor Detail
-
Parser
public Parser(Scanner scanner)
-
-
Method Detail
-
getScanner
public Scanner getScanner()
- Returns:
- The scanner that produces the tokens for this parser.
-
parseCompilationUnit
public Java.CompilationUnit parseCompilationUnit() throws CompileException, IOException
CompilationUnit := [ PackageDeclaration ] { ImportDeclaration } { TypeDeclaration }- Throws:
CompileExceptionIOException
-
parsePackageDeclaration
public Java.PackageDeclaration parsePackageDeclaration() throws CompileException, IOException
PackageDeclaration := 'package' QualifiedIdentifier ';'
- Throws:
CompileExceptionIOException
-
parseImportDeclaration
public Java.CompilationUnit.ImportDeclaration parseImportDeclaration() throws CompileException, IOException
ImportDeclaration := 'import' ImportDeclarationBody ';'
- Throws:
CompileExceptionIOException
-
parseImportDeclarationBody
public Java.CompilationUnit.ImportDeclaration parseImportDeclarationBody() throws CompileException, IOException
ImportDeclarationBody := [ 'static' ] Identifier { '.' Identifier } [ '.' '*' ]- Throws:
CompileExceptionIOException
-
parseQualifiedIdentifier
public String[] parseQualifiedIdentifier() throws CompileException, IOException
QualifiedIdentifier := Identifier { '.' Identifier }- Throws:
CompileExceptionIOException
-
parsePackageMemberTypeDeclaration
public Java.PackageMemberTypeDeclaration parsePackageMemberTypeDeclaration() throws CompileException, IOException
PackageMemberTypeDeclaration := ModifiersOpt 'class' ClassDeclarationRest | ModifiersOpt 'interface' InterfaceDeclarationRest- Throws:
CompileExceptionIOException
-
parseModifiers
public Java.Modifiers parseModifiers() throws CompileException, IOException
ModifiersAndAnnotations := { 'public' | 'protected' | 'private' | 'static' | 'abstract' | 'final' | 'native' | 'synchronized' | 'transient' | 'volatile' | 'strictfp' | Annotation }- Throws:
CompileExceptionIOException
-
parseClassDeclarationRest
public Java.NamedClassDeclaration parseClassDeclarationRest(String optionalDocComment, Java.Modifiers modifiers, Parser.ClassDeclarationContext context) throws CompileException, IOException
ClassDeclarationRest := Identifier [ typeParameters ] [ 'extends' ReferenceType ] [ 'implements' ReferenceTypeList ] ClassBody- Throws:
CompileExceptionIOException
-
parseClassBody
public void parseClassBody(Java.ClassDeclaration classDeclaration) throws CompileException, IOException
ClassBody := '{' { ClassBodyDeclaration } '}'- Throws:
CompileExceptionIOException
-
parseClassBodyDeclaration
public void parseClassBodyDeclaration(Java.ClassDeclaration classDeclaration) throws CompileException, IOException
ClassBodyDeclaration := ';' | ModifiersOpt ( Block | // Instance (JLS7 8.6) or static initializer (JLS7 8.7) 'void' Identifier MethodDeclarationRest | 'class' ClassDeclarationRest | 'interface' InterfaceDeclarationRest | ConstructorDeclarator | Type Identifier ( MethodDeclarationRest | FieldDeclarationRest ';' ) )- Throws:
CompileExceptionIOException
-
parseInterfaceDeclarationRest
public Java.InterfaceDeclaration parseInterfaceDeclarationRest(String optionalDocComment, Java.Modifiers modifiers, Parser.InterfaceDeclarationContext context) throws CompileException, IOException
InterfaceDeclarationRest := Identifier [ typeParameters ] [ 'extends' ReferenceTypeList ] InterfaceBody- Throws:
CompileExceptionIOException
-
parseInterfaceBody
public void parseInterfaceBody(Java.InterfaceDeclaration interfaceDeclaration) throws CompileException, IOException
InterfaceBody := '{' { ';' | ModifiersOpt ( 'void' Identifier MethodDeclarationRest | 'class' ClassDeclarationRest | 'interface' InterfaceDeclarationRest | Type Identifier ( MethodDeclarationRest | FieldDeclarationRest ) ) } '}'- Throws:
CompileExceptionIOException
-
parseConstructorDeclarator
public Java.ConstructorDeclarator parseConstructorDeclarator(String optionalDocComment, Java.Modifiers modifiers) throws CompileException, IOException
ConstructorDeclarator := Identifier FormalParameters [ 'throws' ReferenceTypeList ] '{' [ 'this' Arguments ';' | 'super' Arguments ';' | Primary '.' 'super' Arguments ';' ] BlockStatements '}'- Throws:
CompileExceptionIOException
-
parseMethodDeclarationRest
public Java.MethodDeclarator parseMethodDeclarationRest(String optionalDocComment, Java.Modifiers modifiers, Java.Type type, String name) throws CompileException, IOException
MethodDeclarationRest := FormalParameters { '[' ']' } [ 'throws' ReferenceTypeList ] ( ';' | MethodBody )- Throws:
CompileExceptionIOException
-
parseVariableInitializer
public Java.ArrayInitializerOrRvalue parseVariableInitializer() throws CompileException, IOException
VariableInitializer := ArrayInitializer | Expression- Throws:
CompileExceptionIOException
-
parseArrayInitializer
public Java.ArrayInitializer parseArrayInitializer() throws CompileException, IOException
ArrayInitializer := '{' [ VariableInitializer { ',' VariableInitializer } [ ',' ] '}'- Throws:
CompileExceptionIOException
-
parseFormalParameters
public Java.FunctionDeclarator.FormalParameters parseFormalParameters() throws CompileException, IOException
FormalParameters := '(' [ FormalParameter { ',' FormalParameter } ] ')'- Throws:
CompileExceptionIOException
-
parseFormalParameter
public Java.FunctionDeclarator.FormalParameter parseFormalParameter(boolean[] hasEllipsis) throws CompileException, IOException
FormalParameter := [ 'final' ] Type [ '.' '.' '.' ] Identifier BracketsOpt
- Throws:
CompileExceptionIOException
-
parseMethodBody
public Java.Block parseMethodBody() throws CompileException, IOException
MethodBody := Block
- Throws:
CompileExceptionIOException
-
parseBlock
public Java.Block parseBlock() throws CompileException, IOException
'{' BlockStatements '}'- Throws:
CompileExceptionIOException
-
parseBlockStatements
public List<Java.BlockStatement> parseBlockStatements() throws CompileException, IOException
BlockStatements := { BlockStatement }- Throws:
CompileExceptionIOException
-
parseBlockStatement
public Java.BlockStatement parseBlockStatement() throws CompileException, IOException
BlockStatement := { Identifier ':' } ( ( Modifiers Type | ModifiersOpt BasicType ) VariableDeclarators ';' | 'class' ... | Statement | 'final' Type VariableDeclarators ';' | Expression ';' | Expression VariableDeclarators ';' (1) )(1) "Expression" must pose a type, and has optional trailing brackets.- Throws:
CompileExceptionIOException
-
parseVariableDeclarators
public Java.VariableDeclarator[] parseVariableDeclarators() throws CompileException, IOException
VariableDeclarators := VariableDeclarator { ',' VariableDeclarator }- Throws:
CompileExceptionIOException
-
parseFieldDeclarationRest
public Java.VariableDeclarator[] parseFieldDeclarationRest(String name) throws CompileException, IOException
FieldDeclarationRest := VariableDeclaratorRest { ',' VariableDeclarator }- Throws:
CompileExceptionIOException
-
parseVariableDeclarator
public Java.VariableDeclarator parseVariableDeclarator() throws CompileException, IOException
VariableDeclarator := Identifier VariableDeclaratorRest
- Throws:
CompileExceptionIOException
-
parseVariableDeclaratorRest
public Java.VariableDeclarator parseVariableDeclaratorRest(String name) throws CompileException, IOException
VariableDeclaratorRest := { '[' ']' } [ '=' VariableInitializer ]Used by field declarations and local variable declarations.- Throws:
CompileExceptionIOException
-
parseStatement
public Java.Statement parseStatement() throws CompileException, IOException
Statement := LabeledStatement | Block | IfStatement | ForStatement | WhileStatement | DoStatement | TryStatement | 'switch' ... | 'synchronized' ... | ReturnStatement | ThrowStatement | BreakStatement | ContinueStatement | EmptyStatement | ExpressionStatement- Throws:
CompileExceptionIOException
-
parseLabeledStatement
public Java.Statement parseLabeledStatement() throws CompileException, IOException
LabeledStatement := Identifier ':' Statement
- Throws:
CompileExceptionIOException
-
parseIfStatement
public Java.Statement parseIfStatement() throws CompileException, IOException
IfStatement := 'if' '(' Expression ')' Statement [ 'else' Statement ]- Throws:
CompileExceptionIOException
-
parseForStatement
public Java.Statement parseForStatement() throws CompileException, IOException
ForStatement := 'for' '(' [ ForInit ] ';' [ Expression ] ';' [ ExpressionList ] ')' Statement | 'for' '(' FormalParameter ':' Expression ')' Statement ForInit := Modifiers Type VariableDeclarators | ModifiersOpt BasicType VariableDeclarators | Expression VariableDeclarators (1) | Expression { ',' Expression }(1) "Expression" must pose a type.- Throws:
CompileExceptionIOException
-
parseWhileStatement
public Java.Statement parseWhileStatement() throws CompileException, IOException
WhileStatement := 'while' '(' Expression ')' Statement- Throws:
CompileExceptionIOException
-
parseDoStatement
public Java.Statement parseDoStatement() throws CompileException, IOException
DoStatement := 'do' Statement 'while' '(' Expression ')' ';'- Throws:
CompileExceptionIOException
-
parseTryStatement
public Java.Statement parseTryStatement() throws CompileException, IOException
TryStatement := 'try' Block Catches [ Finally ] | 'try' Block Finally Catches := CatchClause { CatchClause } CatchClause := 'catch' '(' FormalParameter ')' Block Finally := 'finally' Block- Throws:
CompileExceptionIOException
-
parseSwitchStatement
public Java.Statement parseSwitchStatement() throws CompileException, IOException
SwitchStatement := 'switch' '(' Expression ')' '{' { SwitchLabels BlockStatements } '}' SwitchLabels := SwitchLabels { SwitchLabels } SwitchLabel := 'case' Expression ':' | 'default' ':'- Throws:
CompileExceptionIOException
-
parseSynchronizedStatement
public Java.Statement parseSynchronizedStatement() throws CompileException, IOException
SynchronizedStatement := 'synchronized' '(' expression ')' Block- Throws:
CompileExceptionIOException
-
parseReturnStatement
public Java.Statement parseReturnStatement() throws CompileException, IOException
ReturnStatement := 'return' [ Expression ] ';'
- Throws:
CompileExceptionIOException
-
parseThrowStatement
public Java.Statement parseThrowStatement() throws CompileException, IOException
ThrowStatement := 'throw' Expression ';'
- Throws:
CompileExceptionIOException
-
parseBreakStatement
public Java.Statement parseBreakStatement() throws CompileException, IOException
BreakStatement := 'break' [ Identifier ] ';'
- Throws:
CompileExceptionIOException
-
parseContinueStatement
public Java.Statement parseContinueStatement() throws CompileException, IOException
ContinueStatement := 'continue' [ Identifier ] ';'
- Throws:
CompileExceptionIOException
-
parseAssertStatement
public Java.Statement parseAssertStatement() throws CompileException, IOException
AssertStatement := 'assert' Expression [ ':' Expression ] ';'
- Throws:
CompileExceptionIOException
-
parseEmptyStatement
public Java.Statement parseEmptyStatement() throws CompileException, IOException
EmptyStatement := ';'
- Throws:
CompileExceptionIOException
-
parseExpressionList
public Java.Rvalue[] parseExpressionList() throws CompileException, IOException
ExpressionList := Expression { ',' Expression }- Throws:
CompileExceptionIOException
-
parseType
public Java.Type parseType() throws CompileException, IOException
Type := ( 'byte' | 'short' | 'char' | 'int' | 'long' | 'float' | 'double' | 'boolean' | ReferenceType ) { '[' ']' }- Throws:
CompileExceptionIOException
-
parseReferenceType
public Java.ReferenceType parseReferenceType() throws CompileException, IOException
ReferenceType := QualifiedIdentifier [ TypeArguments ]
- Throws:
CompileExceptionIOException
-
parseReferenceTypeList
public Java.ReferenceType[] parseReferenceTypeList() throws CompileException, IOException
ReferenceTypeList := ReferenceType { ',' ReferenceType }- Throws:
CompileExceptionIOException
-
parseExpression
public Java.Atom parseExpression() throws CompileException, IOException
Expression := AssignmentExpression
- Throws:
CompileExceptionIOException
-
parseAssignmentExpression
public Java.Atom parseAssignmentExpression() throws CompileException, IOException
AssignmentExpression := ConditionalExpression [ AssignmentOperator AssignmentExpression ] AssignmentOperator := '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|='- Throws:
CompileExceptionIOException
-
parseConditionalExpression
public Java.Atom parseConditionalExpression() throws CompileException, IOException
ConditionalExpression := ConditionalOrExpression [ '?' Expression ':' ConditionalExpression ]- Throws:
CompileExceptionIOException
-
parseConditionalOrExpression
public Java.Atom parseConditionalOrExpression() throws CompileException, IOException
ConditionalOrExpression := ConditionalAndExpression { '||' ConditionalAndExpression ]- Throws:
CompileExceptionIOException
-
parseConditionalAndExpression
public Java.Atom parseConditionalAndExpression() throws CompileException, IOException
ConditionalAndExpression := InclusiveOrExpression { '&&' InclusiveOrExpression }- Throws:
CompileExceptionIOException
-
parseInclusiveOrExpression
public Java.Atom parseInclusiveOrExpression() throws CompileException, IOException
InclusiveOrExpression := ExclusiveOrExpression { '|' ExclusiveOrExpression }- Throws:
CompileExceptionIOException
-
parseExclusiveOrExpression
public Java.Atom parseExclusiveOrExpression() throws CompileException, IOException
ExclusiveOrExpression := AndExpression { '^' AndExpression }- Throws:
CompileExceptionIOException
-
parseAndExpression
public Java.Atom parseAndExpression() throws CompileException, IOException
AndExpression := EqualityExpression { '&' EqualityExpression }- Throws:
CompileExceptionIOException
-
parseEqualityExpression
public Java.Atom parseEqualityExpression() throws CompileException, IOException
EqualityExpression := RelationalExpression { ( '==' | '!=' ) RelationalExpression }- Throws:
CompileExceptionIOException
-
parseRelationalExpression
public Java.Atom parseRelationalExpression() throws CompileException, IOException
RelationalExpression := ShiftExpression { 'instanceof' ReferenceType | '<' ShiftExpression [ { ',' TypeArgument } '>' ] | '<' TypeArgument [ { ',' TypeArgument } '>' ] | ( '>' | '<=' | '>=' ) ShiftExpression }- Throws:
CompileExceptionIOException
-
parseShiftExpression
public Java.Atom parseShiftExpression() throws CompileException, IOException
ShiftExpression := AdditiveExpression { ( '<<' | '>>' | '>>>' ) AdditiveExpression }- Throws:
CompileExceptionIOException
-
parseAdditiveExpression
public Java.Atom parseAdditiveExpression() throws CompileException, IOException
AdditiveExpression := MultiplicativeExpression { ( '+' | '-' ) MultiplicativeExpression }- Throws:
CompileExceptionIOException
-
parseMultiplicativeExpression
public Java.Atom parseMultiplicativeExpression() throws CompileException, IOException
MultiplicativeExpression := UnaryExpression { ( '*' | '/' | '%' ) UnaryExpression }- Throws:
CompileExceptionIOException
-
parseUnaryExpression
public Java.Atom parseUnaryExpression() throws CompileException, IOException
UnaryExpression := { PrefixOperator } Primary { Selector } { PostfixOperator } PrefixOperator := '++' | '--' | '+' | '-' | '~' | '!' PostfixOperator := '++' | '--'- Throws:
CompileExceptionIOException
-
parsePrimary
public Java.Atom parsePrimary() throws CompileException, 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- Throws:
CompileExceptionIOException
-
parseSelector
public Java.Atom parseSelector(Java.Atom atom) throws CompileException, IOException
Selector := '.' Identifier | // FieldAccess 15.11.1 '.' Identifier Arguments | // MethodInvocation '.' 'this' // QualifiedThis 15.8.4 '.' 'super' Arguments // Qualified superclass constructor invocation (JLS7 8.8.7.1) '.' 'super' '.' Identifier | // SuperclassFieldReference (JLS7 15.11.2) '.' 'super' '.' Identifier Arguments | // SuperclassMethodInvocation (JLS7 15.12.3) '.' 'new' Identifier Arguments [ ClassBody ] | // QualifiedClassInstanceCreationExpression 15.9 '.' 'class' '[' Expression ']' // ArrayAccessExpression 15.13- Throws:
CompileExceptionIOException
-
parseDimExprs
public Java.Rvalue[] parseDimExprs() throws CompileException, IOException
DimExprs := DimExpr { DimExpr }- Throws:
CompileExceptionIOException
-
parseDimExpr
public Java.Rvalue parseDimExpr() throws CompileException, IOException
DimExpr := '[' Expression ']'
- Throws:
CompileExceptionIOException
-
parseArguments
public Java.Rvalue[] parseArguments() throws CompileException, IOException
Arguments := '(' [ ArgumentList ] ')'- Throws:
CompileExceptionIOException
-
parseArgumentList
public Java.Rvalue[] parseArgumentList() throws CompileException, IOException
ArgumentList := Expression { ',' Expression }- Throws:
CompileExceptionIOException
-
parseLiteral
public Java.Rvalue parseLiteral() throws CompileException, IOException
Literal := IntegerLiteral | FloatingPointLiteral | BooleanLiteral | CharacterLiteral | StringLiteral | NullLiteral- Throws:
CompileExceptionIOException
-
parseExpressionStatement
public Java.Statement parseExpressionStatement() throws CompileException, IOException
ExpressionStatement := Expression ';'
- Throws:
CompileExceptionIOException
-
location
public Location location()
-
peek
public Scanner.Token peek() throws CompileException, IOException
- Returns:
- The next token, but does not consume it
- Throws:
CompileExceptionIOException
-
peekNextButOne
public Scanner.Token peekNextButOne() throws CompileException, IOException
- Returns:
- The next-but-one token, but consumes neither the next nor the next-but-one token
- Throws:
CompileExceptionIOException
-
read
public Scanner.Token read() throws CompileException, IOException
- Returns:
- The next and also consumes it, or
nulliff the scanner is at end-of-input - Throws:
CompileExceptionIOException
-
peek
public boolean peek(String suspected) throws CompileException, IOException
- Returns:
- Whether the value of the next token equals
suspected; does not consume the next token - Throws:
CompileExceptionIOException
-
peek
public int peek(String[] suspected) throws CompileException, IOException
Checks whether the value of the next token equals any of thesuspected; does not consume the next token.- Returns:
- The index of the first of the
suspectedthat equals the value of the next token, or -1 if the value of the next token equals none of thesuspected - Throws:
CompileExceptionIOException
-
peek
public int peek(int[] suspected) throws CompileException, IOExceptionChecks whether the type of the next token is any of thesuspected; does not consume the next token.- Returns:
- The index of the first of the
suspectedtypes that is the next token's type, or -1 if the type of the next token is none of thesuspectedtypes - Throws:
CompileExceptionIOException
-
peekNextButOne
public boolean peekNextButOne(String suspected) throws CompileException, IOException
- Returns:
- Whether the value of the next-but-one token equals the
suspected; consumes neither the next nor the next-but-one token - Throws:
CompileExceptionIOException
-
read
public void read(String expected) throws CompileException, IOException
Verifies that the value of the next token equalsexpected, and consumes the token.- Throws:
CompileException- The value of the next token does not equalexpected(this includes the case that the scanner is at end-of-input)IOException
-
read
public int read(String[] expected) throws CompileException, IOException
Verifies that the value of the next token equals one of theexpected, and consumes the token.- Returns:
- The index of the consumed token within
expected - Throws:
CompileException- The value of the next token does not equal any of theexpected(this includes the case where the scanner is at end-of-input)IOException
-
peekRead
public boolean peekRead(String suspected) throws CompileException, IOException
- Returns:
- Whether the value of the next token equals the
suspected; if so, it consumes the next token - Throws:
CompileExceptionIOException
-
peekRead
public int peekRead(String[] values) throws CompileException, IOException
- Returns:
- -1 iff the next token is none of
values - Throws:
CompileExceptionIOException
-
peekEof
public boolean peekEof() throws CompileException, IOException- Returns:
- Whether the scanner is at end-of-input
- Throws:
CompileExceptionIOException
-
peekIdentifier
public String peekIdentifier() throws CompileException, IOException
- Returns:
nulliff the next token is not an identifier, otherwise the value of the identifier token- Throws:
CompileExceptionIOException
-
peekLiteral
public boolean peekLiteral() throws CompileException, IOException- Returns:
- Whether the next token is a literal
- Throws:
CompileExceptionIOException
-
readIdentifier
public String readIdentifier() throws CompileException, IOException
- Returns:
- The value of the next token, which is an indentifier
- Throws:
CompileException- The next token is not an identifierIOException
-
readOperator
public String readOperator() throws CompileException, IOException
- Returns:
- The value of the next token, which is an operator
- Throws:
CompileException- The next token is not an operatorIOException
-
setWarningHandler
public void setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install aWarningHandler.Notice that there is no
Parser.setErrorHandler()method, but parse errors always throw aCompileException. 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.- Parameters:
optionalWarningHandler-nullto indicate that no warnings be issued
-
compileException
protected final CompileException compileException(String message)
Convenience method for throwing aCompileException.
-
-