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 ParseExpr

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

Direct Known Subclasses:
  ParseStmt

public abstract class ParseExpr
extends ParseType

Parses java expressions. Extended by `ParseStmt`.

See Also:
  `ASTNode`, `ParseType`, `ParseStmt`

Field Summary
`private int` | `defaultStackSize`
`private Expr[]` | `exprStack`
`private boolean[]` | `isLeftAssocTable`
`private int[]` | `locStack`
`private int[]` | `opStack`
`private int[]` | `precedenceStack`
`private int[]` | `precedenceTable`
`protected StackVector` | `seqExpr` Internal working storage for parseNewExpression, parseExpressionList, and ParseStmt.parseForStmt functions.
`protected StackVector` | `seqTypeDeclElem` Internal working storage for parseNewExpression function.
`protected StackVector` | `seqVarInit` Internal working storage for parseArrayInitializer function.
`private int` | `stackPtr`

Fields inherited from class javafe.parser.ParseType
`seqIdentifier`

Fields inherited from class javafe.parser.ParseUtil
`modifierKeywords, modifierPragmas, seqModifierPragma`

Constructor Summary
`ParseExpr()`

Method Summary
`(package private) abstract void` | `addDefaultConstructor(TypeDeclElemVec elems, int loc, boolean specOnly)` If no constructors are found in "elems", adds a default one to it.
`void` | `addOperator(int ttype, int precedence, boolean isLeftAssoc)` Add an infix, binary operator to the parser with a given precedence and associativity.
`boolean` | `isStartOfUnaryExpressionNotPlusMinus(int tag)` Determines whether the tag is the first token of a `UnaryExpressionNotPlusMinus`.
`ExprVec` | `parseArgumentList(Lex l)` Parse an `ArgumentList`, which includes enclosing parens.
`ArrayInit` | `parseArrayInitializer(Lex l)`
`Expr` | `parseCastExpression(Lex l)` Parse a `CastExpression`.
`protected Expr` | `parseClassLiteralSuffix(Lex l, Type t)` parses '. class', then produces a class literal expression using Type t.
`Expr` | `parseExpression(Lex l)` Parse an `Expression`.
`ExprVec` | `parseExpressionList(Lex l, int terminator)` Parse an `ExpressionList`.
`Expr` | `parseNewExpression(Lex l)` Parse a `NewExpression`.
`Expr` | `parseNewExpressionTail(Lex l, Type type, int locNew)`
`protected Expr` | `parsePrimaryExpression(Lex l)` Parse a `PrimaryExpression`.
`protected Expr` | `parsePrimarySuffix(Lex l, Expr primary)`
`Name` | `parseSuper(Lex l)` Parse `super`.
`(package private) abstract TypeDeclElem` | `parseTypeDeclElemIntoSeqTDE(Lex l, int keyword, Identifier containerId, boolean specOnly)` Parse an element of a type declaration into "seq".
`Expr` | `parseUnaryExpression(Lex l)` Parse a `UnaryExpression`.
`VarInit` | `parseVariableInitializer(Lex l, boolean specOnly)` Parse VariableInitializer.

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

### defaultStackSize

    private int defaultStackSize

### stackPtr

    private int stackPtr

### exprStack

    private Expr[] exprStack

### opStack

    private int[] opStack

### precedenceStack

    private int[] precedenceStack

### locStack

    private int[] locStack

### precedenceTable

    private int[] precedenceTable

### isLeftAssocTable

    private boolean[] isLeftAssocTable

### seqExpr

    protected final StackVector seqExpr

  Internal working storage for parseNewExpression, parseExpressionList, and ParseStmt.parseForStmt functions.

### seqVarInit

    protected final StackVector seqVarInit

  Internal working storage for parseArrayInitializer function.

### seqTypeDeclElem

    protected final StackVector seqTypeDeclElem

  Internal working storage for parseNewExpression function.

Constructor Detail

### ParseExpr

    public ParseExpr()

Method Detail

### addDefaultConstructor

    abstract 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". A declaration of this method is needed because class declarations can be in expressions. However, the body lives in Parse.java

### parseTypeDeclElemIntoSeqTDE

    abstract TypeDeclElem parseTypeDeclElemIntoSeqTDE(Lex l,
                                                      int keyword,
                                                      Identifier containerId,
                                                      boolean specOnly)

  Parse an element of a type declaration into "seq". "keyword" should be the kind of type decl, one of CLASS or INTERFACE. "containerId" should be the name of the containing type decl. Lives in Parse.java; more doc can be found there.

### addOperator

    public void addOperator(int ttype,
                            int precedence,
                            boolean isLeftAssoc)

  Add an infix, binary operator to the parser with a given precedence and associativity. The precedence level must be greater than zero. The following table gives the precedence levels assigned to the built-in Java operators

  Operator | Precedenc | Assoc
  TagConstants.STAR | 170 | left
  TagConstants.DIV | 170 | left
  TagConstants.MOD | 170 | left
  TagConstants.ADD | 160 | left
  TagConstants.SUB | 160 | left
  TagConstants.LSHIFT | 150 | left
  TagConstants.RSHIFT | 150 | left
  TagConstants.URSHIFT | 150 | left
  TagConstants.GE | 140 | left
  TagConstants.GT | 140 | left
  TagConstants.LT | 140 | left
  TagConstants.LE | 140 | left
  TagConstants.INSTANCEOF | 140 | left
  TagConstants.EQ | 130 | left
  TagConstants.NE | 130 | left
  TagConstants.BITAND | 120 | left
  TagConstants.BITXOR | 110 | left
  TagConstants.BITOR | 100 | left
  TagConstants.AND | 90 | left
  TagConstants.OR | 80 | left
  TagConstants.QUESTIONMARK | 70 | left
  TagConstants.ASSIGN | 60 | right
  TagConstants.ASGMUL | 60 | right
  TagConstants.ASGDIV | 60 | right
  TagConstants.ASGREM | 60 | right
  TagConstants.ASGADD | 60 | right
  TagConstants.ASGSUB | 60 | right
  TagConstants.ASGLSHIFT | 60 | right
  TagConstants.ASGRSHIFT | 60 | right
  TagConstants.ASGURSHIFT | 60 | right
  TagConstants.ASGBITAND | 60 | right
  TagConstants.ASGBITOR | 60 | right
  TagConstants.ASGBITXOR | 60 | right

  (The operators `?` and `instanceof` are treated specially by the parser, but this special treatment respects the precedence levels indicated above.)

### parseExpression

    public Expr parseExpression(Lex l)

  Parse an `Expression`.

  Does operator-precedence parsing of a large amount of the `Expression` hierarchy, all the way down to `UnaryExpression`.

       Expression:
       UnaryExpression
       Expression BinaryOp Expression
       Expression instanceof Type
       Expression ? Expression : Expression

       BinaryOp: one of
       STAR / % PLUS - << >> >>> > >= < <= == != & BITOR ^ && ||
       = *= /= %= += -= <<= >>= >>>= &= |= ^=

  This grammar is ambiguous; the precedence parsing machinery resolves the ambiguity appropriately, according to the grammar in chapter 19 of "The Java Language Specification".

### parseUnaryExpression

    public Expr parseUnaryExpression(Lex l)

  Parse a `UnaryExpression`.

           UnaryExpression:
           PLUS UnaryExpression
           -  UnaryExpression
           ++ UnaryExpression
           -- UnaryExpression
           ~  UnaryExpression
           !  UnaryExpression
           PrimaryExpression
           CastExpression

  A `CastExpression` (as opposed to a `PrimaryExpression`) is recognised by the lookahead sequences:

           LPAREN PrimitiveType
           LPAREN Name (LSQBRACKET RSQBRACKET)* RPAREN X

  where `X` is the first token of a `UnaryExpressionNotPlusMinus`, cf. isStartOfUnaryExpressionNotPlusMinus(-).

### isStartOfUnaryExpressionNotPlusMinus

    public boolean isStartOfUnaryExpressionNotPlusMinus(int tag)

  Determines whether the tag is the first token of a `UnaryExpressionNotPlusMinus`. For the default Java grammar, this amounts to is tag one of: ~ ! Literal Id this new super LPAREN However, it is expected that grammar extensions may extend this list.

### parseCastExpression

    public Expr parseCastExpression(Lex l)

  Parse a `CastExpression`.

           CastExpression:
           ( PrimitiveType Dimsopt ) UnaryExpression
           ( Name Dimsopt ) UnaryExpressionNotPlusMinus

           The non-terminal UnaryExpressionNotPlusMinus describes a
           subset of UnaryExpression as described in chapter 19 of "The
           Java Language Specification"

### parsePrimaryExpression

    protected Expr parsePrimaryExpression(Lex l)

  Parse a `PrimaryExpression`.

           PrimaryExpression:
           PrimaryCore PrimarySuffix*

           PrimaryCore:
           Literal
           Name
           Name ArgumentList
           this
           super . Identifier
           super . Identifier ArgumentList
           NewExpression
           LPAREN Expression RPAREN
           TypeName . this			[1.1]
           Type . class				[1.1]
           (This allows void . class because we treat void as a primitive type)

           PrimarySuffix:
           ++
           --
           LSQBRACKET Expression RSQBRACKET
           . Identifier
           . Identifier ArgumentList

### parseClassLiteralSuffix

    protected Expr parseClassLiteralSuffix(Lex l,
                                           Type t)

  parses '. class', then produces a class literal expression using Type t.

### parsePrimarySuffix

    protected Expr parsePrimarySuffix(Lex l,
                                      Expr primary)

### parseNewExpression

    public Expr parseNewExpression(Lex l)

  Parse a `NewExpression`. NewExpression subsumes ClassInstanceCreationExpression and ArrayCreationExpression.

           NewExpression:
           new TypeName ArgumentList [ TypeDeclBody ]
           new PrimitiveTypeOrTypeName DimExpr+ BracketPairs*

           DimExpr:
           LSQBRACKET Expression RSQBRACKET

### parseNewExpressionTail

    public Expr parseNewExpressionTail(Lex l,
                                       Type type,
                                       int locNew)

### parseArgumentList

    public ExprVec parseArgumentList(Lex l)

  Parse an `ArgumentList`, which includes enclosing parens.

           ArgumentList:
           LPAREN [ Expression (, Expression)* ] RPAREN

### parseExpressionList

    public ExprVec parseExpressionList(Lex l,
                                       int terminator)

  Parse an `ExpressionList`. Consumes specified terminator.

           ExpressionList:
           [ Expression (, Expression)* ]

### parseSuper

    public Name parseSuper(Lex l)

  Parse `super`.

### parseVariableInitializer

    public VarInit parseVariableInitializer(Lex l,
                                            boolean specOnly)

  Parse VariableInitializer.

           VariableInitializer:
           Expression
           ArrayInitializer

           ArrayInitializer:
           { [ VariableInitializer ( , VariableInitializer )*] ,opt }

### parseArrayInitializer

    public ArrayInit parseArrayInitializer(Lex l)

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