|
ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavafe.parser.ParseUtil
javafe.parser.ParseType
javafe.parser.ParseExpr
javafe.parser.ParseStmt
javafe.parser.Parse
Parses java source.
Uses the static make*()
methods of the classes of
the javafe.ast
package to create AST nodes.
The main entry point is the method
parseStream(CorrelatedReader, boolean)
.
Each parsing method for a particular syntactic unit is documented with appropriate grammar production rules for that syntactic unit. These grammar rules follow the conventions described in "The Java Language Specification", with the addition of the symbols '(', ')', '[', ']', '*', '+', and '|', which have their usual meaning. When necessary, we denote the corresponding concrete tokens using LPAREN, RPAREN, LSQBRACKET, RSQBRACKET, STAR, PLUS and BITOR.
ASTNode
,
ParseStmt
Field Summary | |
private Lex |
parseStreamLexer
|
protected StackVector |
seqFormalParaDecl
Internal working storage for many Parse functions. |
protected StackVector |
seqImportDecl
Internal working storage for many Parse functions. |
protected StackVector |
seqTypeDecl
Internal working storage for many Parse functions. |
protected StackVector |
seqTypeName
Internal working storage for many Parse functions. |
Fields inherited from class javafe.parser.ParseStmt |
seqCatchClause, seqStmt |
Fields inherited from class javafe.parser.ParseExpr |
seqExpr, seqTypeDeclElem, seqVarInit |
Fields inherited from class javafe.parser.ParseType |
seqIdentifier |
Fields inherited from class javafe.parser.ParseUtil |
modifierKeywords, modifierPragmas, seqModifierPragma |
Constructor Summary | |
Parse()
|
Method Summary | |
(package private) void |
addDefaultConstructor(TypeDeclElemVec elems,
int loc,
boolean specOnly)
If no constructors are found in "elems", adds a default one to it. |
private boolean |
atStartOfConstructorOrMethod(Lex l)
checks for X TypeModifierPragma* ( in the input stream. |
CompilationUnit |
parseCompilationUnit(Lex l,
boolean specOnly)
Parse a CompilationUnit. |
FormalParaDeclVec |
parseFormalParameterList(Lex l)
Parse a FormalParameterList, which includes enclosing parens. |
protected ImportDecl |
parseImportDeclaration(Lex l)
Parse an ImportDeclaration. |
CompilationUnit |
parseStream(CorrelatedReader in,
boolean specOnly)
Parse a CompilationUnit from an input stream. |
protected TypeDecl |
parseTypeDeclaration(Lex l,
boolean specOnly)
Parse a TypeDeclaration (ie a class or interface declaration). |
protected TypeDecl |
parseTypeDeclaration(Lex l,
boolean specOnly,
int modifiers,
ModifierPragmaVec modifierPragmas,
int loc)
|
protected TypeDeclElem |
parseTypeDeclElemIntoSeqTDE(Lex l,
int keyword,
Identifier containerId,
boolean specOnly)
Parse a TypeDeclElem, which is either a field, method, or constructor declaration, a static block, or a TypeDecl [1.1]. |
protected TypeDecl |
parseTypeDeclTail(Lex l,
boolean specOnly,
int loc,
int modifiers,
ModifierPragmaVec modifierPragmas)
Parse a TypeDeclTail (ie a class or interface declaration starting at the keyword 'class' or 'interface'). |
protected TypeNameVec |
parseTypeNames(Lex l,
int keyword)
Parse a keyword, followed by a comma-separated list of TypeNames. |
Methods inherited from class javafe.parser.ParseStmt |
addStmt, isStatementExpression, parseBlock, parseConstructorBody, parseFormalParaDecl, parseStatement |
Methods inherited from class javafe.parser.ParseType |
isPrimitiveKeywordTag, parseBracketPairs, parseIdentifier, parseName, parsePrimitiveType, parsePrimitiveTypeOrTypeName, parseType, parseTypeModifierPragmas, parseTypeName |
Methods inherited from class javafe.parser.ParseUtil |
arrayToString, error, expect, fail, getJavaModifier, isJavaModifier, operatorTokenToTag, parseModifierPragmas, parseModifiers, parseMoreModifierPragmas |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final StackVector seqTypeName
protected final StackVector seqFormalParaDecl
protected final StackVector seqImportDecl
protected final StackVector seqTypeDecl
private Lex parseStreamLexer
Constructor Detail |
public Parse()
Method Detail |
public CompilationUnit parseStream(CorrelatedReader in, boolean specOnly)
Requires: prefix of in contains text from which the CompilationUnit non-terminal can be derrived.
Ensures: parses a CompilationUnit from the input
stream, generating a syntax tree for it. All errors are treated
as fatal errors and are reporting through ErrorSet
.
ErrorSet
public CompilationUnit parseCompilationUnit(Lex l, boolean specOnly)
CompilationUnit: [Package name ;] ImportDeclaration* TypeDeclaration*To handle pragmas, call this method directly with an appropriate Lex object.
protected ImportDecl parseImportDeclaration(Lex l)
ImportDeclaration: import Name ; import Name . STAR ;
protected TypeDecl parseTypeDeclaration(Lex l, boolean specOnly)
TypeDeclaration: ClassDeclaration InterfaceDeclaration ; ClassDeclaration: TypeDeclElemPragma* Modifiers class Identifier [extends TypeName] [implements TypeNameList] { TypeDeclElem* } TypeDeclElemPragma* Modifiers interface Identifier [extends TypeNameList] { TypeDeclElem* }
protected TypeDecl parseTypeDeclaration(Lex l, boolean specOnly, int modifiers, ModifierPragmaVec modifierPragmas, int loc)
protected TypeDecl parseTypeDeclTail(Lex l, boolean specOnly, int loc, int modifiers, ModifierPragmaVec modifierPragmas)
TypeDeclTail: class Identifier [TypeModifierPragma]* [extends TypeName] [implements TypeNameList] { TypeDeclElem* } interface Identifier [TypeModifierPragma]* [extends TypeNameList] { TypeDeclElem* }
parseTypeDeclTail
in class ParseStmt
private boolean atStartOfConstructorOrMethod(Lex l)
void addDefaultConstructor(TypeDeclElemVec elems, int loc, boolean specOnly)
addDefaultConstructor
in class ParseExpr
protected TypeNameVec parseTypeNames(Lex l, int keyword)
TypeNames: keyword TypeNameList empty TypeNameList: TypeName ( , TypeName )*
protected TypeDeclElem parseTypeDeclElemIntoSeqTDE(Lex l, int keyword, Identifier containerId, boolean specOnly)
A field declaration may define many fields. Since returning multiple declared entities is cumbersome, this method simply adds all the declared entities onto the StackVector seqTypeDeclElem. The keyword argument is either CLASS or INTERFACE. The argument containerId is the name of the enclosing class, which is necessary for checking constructor declarations.
TypeDeclElem: FieldDeclaration MethodDeclaration ConstructorDeclaration InitBlock TypeDeclElemPragma TypeDeclaration [1.1] ; FieldDeclaration: Modifiers Type VariableDeclarator (, VariableDeclarator)* ; MethodDeclaration: Modifiers Type Identifier FormalParameterList BracketPair* [throws TypeNameList] ( ; | Block ) ConstructorDeclaration: Modifiers Identifier FormalParameterList Block InitBlock: Modifiers Block VariableDeclarator: Identifier BRACKET_PAIR* [ = VariableInitializer ]
parseTypeDeclElemIntoSeqTDE
in class ParseExpr
TagConstants
public FormalParaDeclVec parseFormalParameterList(Lex l)
FormalParameterList: LPAREN FormalParameter (, FormalParameter)* RPAREN FormalParameter: [Modifiers] Type Identifier BracketPair* ModifierPragma* [1.1]
|
ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |