Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| 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

## javafe.parser
Class Parse

    java.lang.Object
      javafe.parser.ParseUtil
          javafe.parser.ParseType
              javafe.parser.ParseExpr
                  javafe.parser.ParseStmt
                      javafe.parser.Parse

Direct Known Subclasses:
  EscPragmaParser

public class Parse
extends ParseStmt

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.

See Also:
  `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 `TypeName`s.

Methods inherited from class javafe.parser.ParseStmt
`addStmt, isStatementExpression, parseBlock, parseConstructorBody, parseFormalParaDecl, parseStatement`

Methods inherited from class javafe.parser.ParseExpr
`addOperator, isStartOfUnaryExpressionNotPlusMinus, parseArgumentList, parseArrayInitializer, parseCastExpression, parseClassLiteralSuffix, parseExpression, parseExpressionList, parseNewExpression, parseNewExpressionTail, parsePrimaryExpression, parsePrimarySuffix, parseSuper, parseUnaryExpression, parseVariableInitializer`

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

### seqTypeName

    protected final StackVector seqTypeName

  Internal working storage for many Parse functions.

### seqFormalParaDecl

    protected final StackVector seqFormalParaDecl

  Internal working storage for many Parse functions.

### seqImportDecl

    protected final StackVector seqImportDecl

  Internal working storage for many Parse functions.

### seqTypeDecl

    protected final StackVector seqTypeDecl

  Internal working storage for many Parse functions.

### parseStreamLexer

    private Lex parseStreamLexer

Constructor Detail

### Parse

    public Parse()

Method Detail

### parseStream

    public CompilationUnit parseStream(CorrelatedReader in,
                                       boolean specOnly)

  Parse a `CompilationUnit` from an input stream.

  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`.

  See Also:
    `ErrorSet`

### parseCompilationUnit

    public CompilationUnit parseCompilationUnit(Lex l,
                                                boolean specOnly)

  Parse a `CompilationUnit`.

            CompilationUnit:
               [Package name ;] ImportDeclaration* TypeDeclaration*

  To handle pragmas, call this method directly with an appropriate `Lex` object.

### parseImportDeclaration

    protected ImportDecl parseImportDeclaration(Lex l)

  Parse an `ImportDeclaration`.

          ImportDeclaration:
            import Name ;
            import Name . STAR ;

### parseTypeDeclaration

    protected TypeDecl parseTypeDeclaration(Lex l,
                                            boolean specOnly)

  Parse a `TypeDeclaration` (ie a class or interface declaration).

            TypeDeclaration:
              ClassDeclaration
              InterfaceDeclaration
              ;

            ClassDeclaration:
              TypeDeclElemPragma* Modifiers class Identifier [extends TypeName] [implements TypeNameList]
                { TypeDeclElem* }
              TypeDeclElemPragma* Modifiers interface Identifier [extends TypeNameList]
                { TypeDeclElem* }

### parseTypeDeclaration

    protected TypeDecl parseTypeDeclaration(Lex l,
                                            boolean specOnly,
                                            int modifiers,
                                            ModifierPragmaVec modifierPragmas,
                                            int loc)

### parseTypeDeclTail

    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').

            TypeDeclTail:
              class Identifier [TypeModifierPragma]* [extends TypeName] [implements TypeNameList]
                { TypeDeclElem* }
              interface Identifier [TypeModifierPragma]* [extends TypeNameList] { TypeDeclElem* }

  Specified by:
    `parseTypeDeclTail` in class `ParseStmt`

### atStartOfConstructorOrMethod

    private boolean atStartOfConstructorOrMethod(Lex l)

  checks for X TypeModifierPragma* ( in the input stream. Use this to match the beginning of a constructor or method declration versus the beginning of a field declaration.

### addDefaultConstructor

    void addDefaultConstructor(TypeDeclElemVec elems,
                               int loc,
                               boolean specOnly)

  If no constructors are found in "elems", adds a default one to it. If a default constructor is created, the "loc" and "locId" fields of the default constructor will be set to "loc".

  Specified by:
    `addDefaultConstructor` in class `ParseExpr`

### parseTypeNames

    protected TypeNameVec parseTypeNames(Lex l,
                                         int keyword)

  Parse a keyword, followed by a comma-separated list of `TypeName`s. Used to parse throws clauses, and super-interface clauses.

            TypeNames:
               keyword TypeNameList
               empty

            TypeNameList:
              TypeName ( , TypeName )*

### parseTypeDeclElemIntoSeqTDE

    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].

  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 ]

  Specified by:
    `parseTypeDeclElemIntoSeqTDE` in class `ParseExpr`
  See Also:
    `TagConstants`

### parseFormalParameterList

    public FormalParaDeclVec parseFormalParameterList(Lex l)

  Parse a `FormalParameterList`, which includes enclosing parens. Note: this definition differs from JLS, where it does not include the parens

            FormalParameterList:
              LPAREN FormalParameter (, FormalParameter)* RPAREN

            FormalParameter:
              [Modifiers] Type Identifier BracketPair* ModifierPragma*     [1.1]

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| 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

The ESC/Java2 Project Homepage