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 ParseStmt

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

Direct Known Subclasses:
  Parse

public abstract class ParseStmt
extends ParseExpr

`Parse` objects parse Java statements, creating AST structures for the parsed input using the static `make*()` methods of the classes in the `javafe.ast` package.

The concrete grammar for statements is as follows:

     Statement:
     ';'
     | (Modifier | ModifierPragma)* ClassDeclaration
     | (Modifier | ModifierPragma)* Type { Idn [ '=' InitExpr ] },+ ';'
     | Idn ':' Stmt
     | Expr ';'
     | '{' BlockStmt* '}'
     // In an assert, BoolExpr must be of type boolean, NonVoidExpr must
     // not be of type void
     | 'assert' BoolExpr [ ':' NonVoidExpr ] ';'
     | 'break' [ Idn ] ';'
     | 'continue' [ Idn ] ';'
     | 'return' [ Expr ] ';'
     | 'throw' Expr ';'
     | 'if' '(' Expr ')' Stmt [ 'else' Stmt ]
     | 'do' Stmt 'while' '(' Expr ')' ';'
     | 'while' '(' Expr ')' Stmt
     | 'for' '(' [ VDeclInit | StmtExpr,* ] ';' Expr ';' StmtExpr,* ')' Stmt
     | 'switch' '(' Expr ')'
         '{' { {'case' Expr ':' | 'default:'}* BlockStmt* }* '}'
     | 'synchronized' '(' Expr ')' '{' BlockStmt* '}'
     | 'try' '{' BlockStmt* '}' { 'catch' '(' VDecl,* ')' '{' BlockStmt* '}' }*
         [ 'finally' '{' BlockStmt* '}' ]
     | StmtPragma

Currently, there is no error recovery. Upon detection of a syntax error, all methods in this class throw a `RuntimeException` with a (weak) error message.

Although the class as a whole is thread-safe, that is, different threads can be calling methods of different instances of `ParseStmt` at the same time, individual instances are not.

See Also:
  `ASTNode`

Field Summary
`protected StackVector` | `seqCatchClause`
`protected StackVector` | `seqStmt` Internal working storage for many `ParseStmt` functions.

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
`ParseStmt()`

Method Summary
`protected void` | `addStmt(Lex l)` Internal method for parsing a `Stmt`.
`private void` | `addVarDeclStmts(Lex l, int modifiers, ModifierPragmaVec modifierPragmas, Type basetype)` Internal routine for parsing variable declarations after the leading type has been parsed.
`static boolean` | `isStatementExpression(Expr e)`
`BlockStmt` | `parseBlock(Lex l, boolean specOnly)` Method for parsing a `Block`.
`private CatchClauseVec` | `parseCatches(Lex l)` Internal routine for parsing zero or more catch clauses.
`BlockStmt` | `parseConstructorBody(Lex l)` Method for parsing a `ConstructorBody`.
`FormalParaDecl` | `parseFormalParaDecl(Lex l)` Routine for parsing a single formal parameter declarations.
`private ForStmt` | `parseForStmt(Lex l, int keywordloc)` Internal method for parsing a switch statement.
`Stmt` | `parseStatement(Lex l)` Method for parsing a `Stmt`.
`private SwitchStmt` | `parseSwitchStmt(Lex l, int keywordloc)` Internal method for parsing a switch statement.
`(package private) abstract TypeDecl` | `parseTypeDeclTail(Lex l, boolean specOnly, int loc, int modifiers, ModifierPragmaVec modifierPragmas)` Parse a type declaration stating at the class/interface keyword.

Methods inherited from class javafe.parser.ParseExpr
`addDefaultConstructor, addOperator, isStartOfUnaryExpressionNotPlusMinus, parseArgumentList, parseArrayInitializer, parseCastExpression, parseClassLiteralSuffix, parseExpression, parseExpressionList, parseNewExpression, parseNewExpressionTail, parsePrimaryExpression, parsePrimarySuffix, parseSuper, parseTypeDeclElemIntoSeqTDE, 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

### seqStmt

    protected final StackVector seqStmt

  Internal working storage for many `ParseStmt` functions.

### seqCatchClause

    protected final StackVector seqCatchClause

Constructor Detail

### ParseStmt

    public ParseStmt()

Method Detail

### parseTypeDeclTail

    abstract TypeDecl parseTypeDeclTail(Lex l,
                                        boolean specOnly,
                                        int loc,
                                        int modifiers,
                                        ModifierPragmaVec modifierPragmas)

  Parse a type declaration stating at the class/interface keyword. A declaration of this method is needed because class declarations can be in statements. However, the body (and more documentation) lives in Parse.java.

### parseStatement

    public Stmt parseStatement(Lex l)

  Method for parsing a `Stmt`.

  Effects: Parses a single `Stmt` according to the grammar at the top of this file, except that it does not accept variable-declaration statements. If no syntax errors are encountered, it adds one or more `Stmt` to `seqStmt`, leaving `l` at the token just after the trailing `}` of the statement. More than one statement is added only in the case of variable declarations that declare more than one variable.

### addStmt

    protected void addStmt(Lex l)

  Internal method for parsing a `Stmt`.

  Effects: Parses a single `Stmt` according to the grammar at the top of this file. If no syntax errors are encountered, it adds one or more `Stmt` to `seqStmt`, leaving `l` at the token just after the trailing `}` of the statement. More than one statement is added only in the case of variable declarations that declare more than one variable.

### parseConstructorBody

    public BlockStmt parseConstructorBody(Lex l)

  Method for parsing a `ConstructorBody`.

  Effects: Parses the following grammar:

       Block ::=
       '{' [ { 'this' | 'super' ] '(' ArgumentList ')' ] { VarDeclInit | Stmt }* '}'

  If no syntax errors are encountered, it returns a parse tree for the parsed input, leaving `l` at the token just after the trailing `}` of the statement.

### parseBlock

    public BlockStmt parseBlock(Lex l,
                                boolean specOnly)

  Method for parsing a `Block`.

  Effects: Parses the following grammar:

       Block ::=
       '{' { VarDeclInit | Stmt }* '}'

  If no syntax errors are encountered, it returns a parse tree for the parsed input, leaving `l` at the token just after the trailing `}` of the statement.

### parseForStmt

    private ForStmt parseForStmt(Lex l,
                                 int keywordloc)

  Internal method for parsing a switch statement.

  Effects: Parses the following grammar:

       ForStmtRemainder ::=
       '(' [VDeclInit | StmtExpr,* ] ';' Expr ';' StmtExpr,* ')' Stmt

  Note that it assumes the leading `for` has already been parsed; `keywordloc` is the location assumed for the `for` token.

  If no syntax errors are encountered, it returns a parse tree for the parsed input, leaving `l` at the token just after the trailing `}` of the statement.

### parseSwitchStmt

    private SwitchStmt parseSwitchStmt(Lex l,
                                       int keywordloc)

  Internal method for parsing a switch statement.

  Effects: Parses the following grammar:

       SwitchStmtRemainder ::=
       '(' Expr ')' '{' { 'case' Expr ':' | 'default ':' | Stmt }* '}'

  Note that it assumes the trailing `switch` has already been parsed; `keywordLoc` is the location assumed for the `switch` token.

  If no syntax errors are encountered, it returns a parse tree for the parsed input, leaving `l` at the token just after the trailing `}` of the statement.

### parseCatches

    private CatchClauseVec parseCatches(Lex l)

  Internal routine for parsing zero or more catch clauses.

  Effects: Parses the following grammar:

       Catches ::= { 'catch' '(' [Modifiers] Type Idn ')' Block }*

  At the start of each iteration (including the first), if the first token is not `catch`, it stops trying to parse, returning the (possibly empty) sequence of catch clauses parsed already and leaving the token at the first token following the last catch clause parsed. If the first token is `catch`, then it tries to parse a catch clause, throwing an exception if a syntax error is found.

### addVarDeclStmts

    private void addVarDeclStmts(Lex l,
                                 int modifiers,
                                 ModifierPragmaVec modifierPragmas,
                                 Type basetype)

  Internal routine for parsing variable declarations after the leading type has been parsed.

  Effects: Parses the following grammar:

       VarDeclRemainder ::=
       { Idn { '[' ']' }* [ '=' VariableInitializer ] },*

  Each `VarDeclRemainder` found is combined with `basetype` to create a `VarDeclStmt` which is added to the end of `seqStmt`.

  On entry, it assumes at least one `VarDeclRemainder` is available, and throws an exception if one isn't. At the end of each iteration, it stops trying to parse if the comma is not present, leaving the token at the first token following the last `VarDeclRemainder` parsed. If a comma is found, then it tries to parse the next `VarDeclRemainder`, throwing an exception if a syntax error is found.

### parseFormalParaDecl

    public FormalParaDecl parseFormalParaDecl(Lex l)

  Routine for parsing a single formal parameter declarations.

  Effects: Parses the following grammar:

       FormalParaDecl ::= { [Modifiers] Type Idn ModifierPragma* }

  returning an ASTNode representing the result. Leaves `l` pointing to the token just after the `FormalParaDecl`.

### isStatementExpression

    public static boolean isStatementExpression(Expr e)

  Returns:
    true iff `e` is a Java `StatementExpression` as defined in the grammar given in the language spec.

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