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

javafe.parser
Class ParseExpr

java.lang.Object
  extended byjavafe.parser.ParseUtil
      extended byjavafe.parser.ParseType
          extended byjavafe.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
OperatorPrecedencAssoc
TagConstants.STAR170left
TagConstants.DIV 170left
TagConstants.MOD 170left
TagConstants.ADD 160left
TagConstants.SUB 160left
TagConstants.LSHIFT150left
TagConstants.RSHIFT150left
TagConstants.URSHIFT150left
TagConstants.GE140left
TagConstants.GT140left
TagConstants.LT140left
TagConstants.LE140left
TagConstants.INSTANCEOF140left
TagConstants.EQ130left
TagConstants.NE130left
TagConstants.BITAND120left
TagConstants.BITXOR110left
TagConstants.BITOR100left
TagConstants.AND90left
TagConstants.OR80left
TagConstants.QUESTIONMARK70left
TagConstants.ASSIGN60right
TagConstants.ASGMUL60right
TagConstants.ASGDIV60right
TagConstants.ASGREM60right
TagConstants.ASGADD60right
TagConstants.ASGSUB60right
TagConstants.ASGLSHIFT60right
TagConstants.ASGRSHIFT60right
TagConstants.ASGURSHIFT60right
TagConstants.ASGBITAND60right
TagConstants.ASGBITOR60right
TagConstants.ASGBITXOR60right

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

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

The ESC/Java2 Project Homepage