| java.lang.Object sun.tools.java.Scanner sun.tools.java.Parser
All known Subclasses: sun.tools.javac.BatchParser,
Parser | public class Parser extends Scanner implements ParserActions,Constants(Code) | | This class is used to parse Java statements and expressions.
The result is a parse tree.
This class implements an operator precedence parser. Errors are
reported to the Environment object, if the error can't be
resolved immediately, a SyntaxError exception is thrown.
Error recovery is implemented by catching SyntaxError exceptions
and discarding input tokens until an input token is reached that
is possibly a legal continuation.
The parse tree that is constructed represents the input
exactly (no rewrites to simpler forms). This is important
if the resulting tree is to be used for code formatting in
a programming environment. Currently only documentation comments
are retained.
The parsing algorithm does NOT use any type information. Changes
in the type system do not affect the structure of the parse tree.
This restriction does introduce an ambiguity an expression of the
form: (e1) e2 is assumed to be a cast if e2 does not start with
an operator. That means that (a) - b is interpreted as subtract
b from a and not cast negative b to type a. However, if a is a
simple type (byte, int, ...) then it is assumed to be a cast.
WARNING: The contents of this source file are not part of any
supported API. Code that depends on them does so at its own risk:
they are subject to change or removal without notice.
author: Arthur van Hoff version: 1.97, 05/05/07 |
Method Summary | |
final protected void | addArgument(Node n) | public ClassDefinition | beginClass(long off, String doc, int mod, IdentifierToken nm, IdentifierToken sup, IdentifierToken impl) | protected void | beginClass(long off, String doc, int mod, Identifier nm, Identifier sup, Identifier impl) | public void | defineField(long where, ClassDefinition c, String doc, int mod, Type t, IdentifierToken nm, IdentifierToken args, IdentifierToken exp, Node val) | protected void | defineField(long where, String doc, int mod, Type t, Identifier nm, Identifier args, Identifier exp, Node val) | public void | endClass(long off, ClassDefinition c) | protected void | endClass(long off, Identifier nm) | protected void | expect(int t) Expect a token, return its value, scan the next token or
throw an exception. | final protected Expression | exprArgs(int index) | protected ClassDefinition | getCurrentClass() Report the current class under construction. | public void | importClass(long off, IdentifierToken nm) | protected void | importClass(long off, Identifier nm) | public void | importPackage(long off, IdentifierToken nm) | protected void | importPackage(long off, Identifier nm) | public void | match(int open, int close) | public void | packageDeclaration(long off, IdentifierToken nm) | protected void | packageDeclaration(long off, Identifier nm) | protected Type | parseArrayBrackets(Type t) Parse the tail of a type expression, which might be array brackets. | protected Expression | parseBinaryExpression(Expression e) Given a left-hand term, parse an operator and right-hand term. | protected Statement | parseBlockStatement() | protected void | parseClass() Parse a top-level class or interface declaration. | protected ClassDefinition | parseClassBody(IdentifierToken nm, int mod, int ctx, String doc, Vector ext, Vector impl, long p) Parse the body of a class or interface declaration,
starting at the left brace. | protected Statement | parseDeclaration(long p, int mod, Expression type) Parse declaration, called after the type expression
has been parsed and the current token is IDENT. | protected Expression | parseExpression() Parse an expression. | protected void | parseField() Parse a field. | public void | parseFile() Parse an Java file. | protected Identifier | parseIdentifier(boolean star) | protected void | parseInheritance(Vector ext, Vector impl) | protected Statement | parseLocalClass(int mod) Parse a block-local class or interface declaration. | protected Expression | parseMethodExpression(Expression e, Identifier id) Parse a method invocation. | protected int | parseModifiers(int mask) Parse a possibly-empty sequence of modifier keywords. | protected IdentifierToken | parseName(boolean star) Parse an identifier. | protected ClassDefinition | parseNamedClass(int mod, int ctx, String doc) Parse a named class or interface declaration,
starting at "class" or "interface". | protected Expression | parseNewInstanceExpression(long p, Expression outerArg, Expression type) Parse a new instance expression. | protected Statement | parseStatement() Parse a statement. | protected Expression | parseTerm() Parse a primary expression. | protected Type | parseType() Parse a type expression, this results in a Type. | protected Expression | parseTypeExpression() Parse a type expression. | protected void | recoverField(ClassDefinition newClass) Recover after a syntax error in a field. | protected void | recoverFile() Recover after a syntax error in the file. | protected boolean | recoverStatement() Recover after a syntax error in a statement. | public long | scan() | final protected Statement | statArgs(int index) | protected void | topLevelExpression(Expression e) Check if an expression is a legal toplevel expression. |
actions | ParserActions actions(Code) | | Usually this.actions == (ParserActions)this .
However, a delegate scanner can produce tokens for this parser,
in which case (Scanner)this is unused,
except for this.token and this.pos
instance variables which are filled from the real scanner
by this.scan() and the constructor.
|
argIndex | protected int argIndex(Code) | | |
scanner | protected Scanner scanner(Code) | | Usually this.scanner == (Scanner)this .
However, a delegate scanner can produce tokens for this parser,
in which case (Scanner)this is unused,
except for this.token and this.pos
instance variables which are filled from the real scanner
by this.scan() and the constructor.
|
addArgument | final protected void addArgument(Node n)(Code) | | |
expect | protected void expect(int t) throws SyntaxError, IOException(Code) | | Expect a token, return its value, scan the next token or
throw an exception.
|
getCurrentClass | protected ClassDefinition getCurrentClass()(Code) | | Report the current class under construction.
By default, it's a no-op which returns null.
It may only be called before the corresponding endClass().
|
packageDeclaration | protected void packageDeclaration(long off, Identifier nm)(Code) | | |
parseArrayBrackets | protected Type parseArrayBrackets(Type t) throws SyntaxError, IOException(Code) | | Parse the tail of a type expression, which might be array brackets.
Return the given type, as possibly modified by the suffix.
|
parseFile | public void parseFile()(Code) | | Parse an Java file.
|
parseModifiers | protected int parseModifiers(int mask) throws IOException(Code) | | Parse a possibly-empty sequence of modifier keywords.
Return the resulting bitmask.
Diagnose repeated modifiers, but make no other checks.
Only modifiers mentioned in the given bitmask are scanned;
an unmatched modifier must be handled by the caller.
|
parseName | protected IdentifierToken parseName(boolean star) throws SyntaxError, IOException(Code) | | Parse an identifier. ie: a.b.c returns "a.b.c"
If star is true then "a.b.*" is allowed.
The return value encodes both the identifier and its location.
|
parseType | protected Type parseType() throws SyntaxError, IOException(Code) | | Parse a type expression, this results in a Type.
The parse includes trailing array brackets.
|
recoverField | protected void recoverField(ClassDefinition newClass) throws SyntaxError, IOException(Code) | | Recover after a syntax error in a field. This involves
discarding tokens until an EOF or a possible legal
continuation is encountered.
|
recoverFile | protected void recoverFile() throws IOException(Code) | | Recover after a syntax error in the file.
This involves discarding tokens until an EOF
or a possible legal continuation is encountered.
|
recoverStatement | protected boolean recoverStatement() throws SyntaxError, IOException(Code) | | Recover after a syntax error in a statement. This involves
discarding tokens until EOF or a possible continuation is
encountered.
|
topLevelExpression | protected void topLevelExpression(Expression e)(Code) | | Check if an expression is a legal toplevel expression.
Only method, inc, dec, and new expression are allowed.
|
|
|