Class OPToken
- java.lang.Object
- 
- com.tangosol.coherence.dsltools.precedence.OPToken
 
- 
- Direct Known Subclasses:
- BetweenOPToken,- ColonToken,- ContainsOPToken,- IdentifierOPToken,- InfixOPToken,- InfixRightOPToken,- KeywordOPToken,- LiteralOPToken,- NestingOPToken,- NotOPToken,- PathOPToken,- PeekOPToken,- PrefixOPToken,- PunctuationOPToken
 
 public class OPToken extends Object OPToken is the root class for the Top Down Operator Precedence Parsing framework's tokens. This framework was first done by Vaughan Pratt in 1973 an is undergoing a bit of a renaissance with people that find the typical formal grammer tool a bit to heavyweight. The fundamental idea behind "Pratt Parsers" is that Tokens are objects that posses methods that allow them to make precedence decisions, match other tokens, and build abstract syntax trees (AST). The central issue of the precedence problem is that given an operand object between two operators, should the operand be bound to the left operator or the right operator? obj1 OP1 obj2 OP2 obj3 like: (1 + 2 * 3) Does obj2 bind to OP1 or to OP2? The technique we will use has Token objects "know" their precedence levels, and implement methods called "nud" (the null denotation in Pratt speak) and "led" (the left denotation). A nud method "should" have no interest in the tokens to the left while a "led" method does. A nud method is typically used on values such as variables and literals and by prefix operators like '-', or 'not'. A led method is used by infix operators and suffix operators. A token will often have both a nud method and a led method with the canonical example being '-' which is both a prefix operator and an infix operator. The heart of Pratt's technique is the "expression" function. It takes a right binding power that controls how aggressively that it should bind to tokens on its right. We also pass the parser to the token objects so that their functions may look at context and have access to the tokenizer.- Author:
- djl 2009.03.14
- See Also:
- OPParser
 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringBINARY_OPERATOR_NODEThe AST node name for a Binary Operator node.static StringBINDING_NODEThe AST node name for a Binding Node.static StringCALL_NODEThe AST node name for a Method Call Node.static StringDEREF_NODEThe AST node name for a De-referencing Node.static StringFIELD_LISTThe AST node name for a Field List Node.static StringIDENTIFIER_NODEThe AST node name for an Identifier Node.static StringLIST_NODEThe AST node name for a List of Values Node.static StringLITERAL_NODEThe AST node name for a Literal Node.protected intm_nBindingPowerThe power that this token binds, typically to the left.protected Stringm_sLedASTNameA functor for building ast for led method.protected Stringm_sNudASTNameA functor for building ast for nud method.protected Stringm_sValueThe string value of the literal.static intPRECEDENCE_ASSIGNMENTThe binding precedence for assignment operators assignment such as = += -= *= /= %= &= ^= |= <<= >>= >>>=static intPRECEDENCE_BITWISEThe binding precedence for bitwise operators such as >>> >> and <<static intPRECEDENCE_EXPONENTThe binding precedence for exponent arithmetic, i.e. raising by a powerstatic intPRECEDENCE_IDENTIFIERThe binding precedence for identifier tokensstatic intPRECEDENCE_KEYWORDThe binding precedence for keyword tokensstatic intPRECEDENCE_LOGICALThe binding precedence for logical tokens such as &&, ||, etcstatic intPRECEDENCE_LOGICAL_BITWISEThe binding precedence for bitwise logical tokens such as &, |, ^ etcstatic intPRECEDENCE_PARENTHESESThe binding precedence for parentheses ( ) [ ]static intPRECEDENCE_PRODUCTThe binding precedence for product arithmetic, multiplication, division, mod * / %static intPRECEDENCE_RELATIONALThe binding precedence for relational operators such as ==, <=, like, contains etcstatic intPRECEDENCE_SUMThe binding precedence for sum arithmetic, i.e. + and -static intPRECEDENCE_UNARYThe binding precedence for other unary operators: pre-increment, pre-decrement, plus, minus, logical negation, bitwise complement, type cast ++expr --expr +expr -expr !static intPRECEDENCE_UNARY_POSTThe binding precedence for unary post operators such as post-increment and post-decrement of the form expr++ or expr--static StringUNARY_OPERATOR_NODEThe AST node name for a Unary Operator Node.
 - 
Constructor SummaryConstructors Constructor Description OPToken()Construct a new OPToken.OPToken(String sId)Construct a new OPToken with the given parameters.OPToken(String sId, int nBp)Construct a new OPToken with the given parameters.OPToken(String sId, int nBp, String sAstName)Construct a new OPToken with the given parameters.OPToken(String sId, int nBp, String sLedASTName, String sNudASTName)Construct a new OPToken with the given parameters.OPToken(String sId, String sAstName)Construct a new OPToken with the given parameters.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)intgetBindingPower()Get The binding precedence of this token.StringgetId()Obtain the string representation of this token.StringgetLedASTName()Get led AST Name for this tokenStringgetNudASTName()Get nud AST Name for this tokenStringgetValue()Get a string value that identifies this tokeninthashCode()Termled(OPParser parser, Term leftNode)Process this token and possibly the given leftNodein the context of a parser with the left denotation.intleftBindingPower()Obtain the power that this token will bind to the left.protected TermnewAST(String sAstName, Term term)Create an Abstract Syntax Node for the given arguments.protected TermnewAST(String sAstName, String sFunctor)Create an Abstract Syntax Node for the given arguments.protected TermnewAST(String sAstName, String sFunctor, Term term)Create an Abstract Syntax Node for the given arguments.protected TermnewAST(String sAstName, String sFunctor, Term t1, Term t2)Create an Abstract Syntax Node for the given arguments.protected TermnewAST(String sAstName, String sFunctor, Term t1, Term t2, Term t3)Create an Abstract Syntax Node for the given arguments.Termnud(OPParser parser)Process this token in the context of parser p with the null denotation.voidsetBindingPower(int nBp)Set The binding precedence that this token will use for binding to the right.voidsetId(String sId)Set the string representation of this token to the given id.voidsetLedASTName(String sAstName)Set the led AST Name for this token to be the given stringvoidsetNudASTName(String sAstName)Set the nud AST Name for this token to be the given stringvoidsetValue(String s)Set the AST Name for this token to be the given stringStringtoString()Return a human-readable description for this token.
 
- 
- 
- 
Field Detail- 
BINARY_OPERATOR_NODEpublic static String BINARY_OPERATOR_NODE The AST node name for a Binary Operator node.
 - 
BINDING_NODEpublic static String BINDING_NODE The AST node name for a Binding Node.
 - 
CALL_NODEpublic static String CALL_NODE The AST node name for a Method Call Node.
 - 
DEREF_NODEpublic static String DEREF_NODE The AST node name for a De-referencing Node.
 - 
FIELD_LISTpublic static String FIELD_LIST The AST node name for a Field List Node.
 - 
IDENTIFIER_NODEpublic static String IDENTIFIER_NODE The AST node name for an Identifier Node.
 - 
LIST_NODEpublic static String LIST_NODE The AST node name for a List of Values Node.
 - 
LITERAL_NODEpublic static String LITERAL_NODE The AST node name for a Literal Node.
 - 
UNARY_OPERATOR_NODEpublic static String UNARY_OPERATOR_NODE The AST node name for a Unary Operator Node.
 - 
PRECEDENCE_KEYWORDpublic static final int PRECEDENCE_KEYWORD The binding precedence for keyword tokens- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_IDENTIFIERpublic static final int PRECEDENCE_IDENTIFIER The binding precedence for identifier tokens- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_ASSIGNMENTpublic static final int PRECEDENCE_ASSIGNMENT The binding precedence for assignment operators assignment such as = += -= *= /= %= &= ^= |= <<= >>= >>>=- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_LOGICALpublic static final int PRECEDENCE_LOGICAL The binding precedence for logical tokens such as &&, ||, etc- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_LOGICAL_BITWISEpublic static final int PRECEDENCE_LOGICAL_BITWISE The binding precedence for bitwise logical tokens such as &, |, ^ etc- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_RELATIONALpublic static final int PRECEDENCE_RELATIONAL The binding precedence for relational operators such as ==, <=, like, contains etc- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_BITWISEpublic static final int PRECEDENCE_BITWISE The binding precedence for bitwise operators such as >>> >> and <<- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_SUMpublic static final int PRECEDENCE_SUM The binding precedence for sum arithmetic, i.e. + and -- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_PRODUCTpublic static final int PRECEDENCE_PRODUCT The binding precedence for product arithmetic, multiplication, division, mod * / %- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_EXPONENTpublic static final int PRECEDENCE_EXPONENT The binding precedence for exponent arithmetic, i.e. raising by a power- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_UNARYpublic static final int PRECEDENCE_UNARY The binding precedence for other unary operators: pre-increment, pre-decrement, plus, minus, logical negation, bitwise complement, type cast ++expr --expr +expr -expr ! ~ (type)- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_UNARY_POSTpublic static final int PRECEDENCE_UNARY_POST The binding precedence for unary post operators such as post-increment and post-decrement of the form expr++ or expr--- See Also:
- Constant Field Values
 
 - 
PRECEDENCE_PARENTHESESpublic static final int PRECEDENCE_PARENTHESES The binding precedence for parentheses ( ) [ ]- See Also:
- Constant Field Values
 
 - 
m_sValueprotected String m_sValue The string value of the literal.
 - 
m_sLedASTNameprotected String m_sLedASTName A functor for building ast for led method.
 - 
m_sNudASTNameprotected String m_sNudASTName A functor for building ast for nud method.
 - 
m_nBindingPowerprotected int m_nBindingPower The power that this token binds, typically to the left.
 
- 
 - 
Constructor Detail- 
OPTokenpublic OPToken() Construct a new OPToken.
 - 
OPTokenpublic OPToken(String sId) Construct a new OPToken with the given parameters.- Parameters:
- sId- string representation of the literal
 
 - 
OPTokenpublic OPToken(String sId, int nBp) Construct a new OPToken with the given parameters.- Parameters:
- sId- string representation of the token
- nBp- The binding precedence for this token
 
 - 
OPTokenpublic OPToken(String sId, String sAstName) Construct a new OPToken with the given parameters.- Parameters:
- sId- string representation of the token
- sAstName- the type code for this literal token
 
 - 
OPTokenpublic OPToken(String sId, int nBp, String sAstName) Construct a new OPToken with the given parameters.- Parameters:
- sId- string representation of the token
- nBp- The binding precedence for this token
- sAstName- the name for this tokens AST
 
 - 
OPTokenpublic OPToken(String sId, int nBp, String sLedASTName, String sNudASTName) Construct a new OPToken with the given parameters.- Parameters:
- sId- string representation of the token
- nBp- The binding precedence for this token
- sLedASTName- the name for this tokens AST
- sNudASTName- the name for this tokens AST
 
 
- 
 - 
Method Detail- 
leftBindingPowerpublic int leftBindingPower() Obtain the power that this token will bind to the left.- Returns:
- the left binding power
 
 - 
nudpublic Term nud(OPParser parser) Process this token in the context of parser p with the null denotation. A nud method typically will have no interest in the token to the left. The processing results in an Abstract Syntax Tree Node that captures the meaning- Parameters:
- parser- the parser that is the context for parsing
- Returns:
- an AstNode
 
 - 
ledpublic Term led(OPParser parser, Term leftNode) Process this token and possibly the given leftNodein the context of a parser with the left denotation. A led method typically will be interested t in the token to the left. The processing results in an Abstract Syntax Tree Node that captures the meaning- Parameters:
- parser- the parser that is the context for parsing
- leftNode- an ast Term that the token is possibly interested in
- Returns:
- an AstNode
 
 - 
newASTprotected Term newAST(String sAstName, String sFunctor) Create an Abstract Syntax Node for the given arguments. If the astName argument is not null then use it for the functor and the given functor argument become the first child Term.- Parameters:
- sAstName- classification functor or null
- sFunctor- functor for ast node to be constructed
- Returns:
- a Term representing the AST
 
 - 
newASTprotected Term newAST(String sAstName, Term term) Create an Abstract Syntax Node for the given arguments. If the astName argument is not null then use it for the functor otherwise just assume the Term t is good.- Parameters:
- sAstName- classification functor or null
- term- an Term that is part of the ast
- Returns:
- a Term representing the AST
 
 - 
newASTprotected Term newAST(String sAstName, String sFunctor, Term term) Create an Abstract Syntax Node for the given arguments. If the astName argument is not null then use it for the functor and the given functor argument become the first child Term.- Parameters:
- sAstName- classification functor or null
- sFunctor- functor for ast node to be constructed
- term- an Term that is part of the ast
- Returns:
- a Term representing the AST
 
 - 
newASTprotected Term newAST(String sAstName, String sFunctor, Term t1, Term t2) Create an Abstract Syntax Node for the given arguments. If the astName argument is not null then use it for the functor and the given functor argument become the first child Term.- Parameters:
- sAstName- classification functor or null
- sFunctor- functor for ast node to be constructed
- t1- an Term that is part of the ast
- t2- an Term that is part of the ast
- Returns:
- a Term representing the AST
 
 - 
newASTprotected Term newAST(String sAstName, String sFunctor, Term t1, Term t2, Term t3) Create an Abstract Syntax Node for the given arguments. If the astName argument is not null then use it for the functor and the given functor argument become the first child Term.- Parameters:
- sAstName- classification functor or null
- sFunctor- functor for ast node to be constructed
- t1- an Term that is part of the ast
- t2- an Term that is part of the ast
- t3- an Term that is part of the ast
- Returns:
- a Term representing the AST
 
 - 
getIdpublic String getId() Obtain the string representation of this token.- Returns:
- the string representation
 
 - 
setIdpublic void setId(String sId) Set the string representation of this token to the given id.- Parameters:
- sId- the string representation for the token
 
 - 
getBindingPowerpublic int getBindingPower() Get The binding precedence of this token.- Returns:
- The binding precedence
 
 - 
setBindingPowerpublic void setBindingPower(int nBp) Set The binding precedence that this token will use for binding to the right.- Parameters:
- nBp- the power power for this token
 
 - 
getNudASTNamepublic String getNudASTName() Get nud AST Name for this token- Returns:
- the nud ast name for this token
 
 - 
setNudASTNamepublic void setNudASTName(String sAstName) Set the nud AST Name for this token to be the given string- Parameters:
- sAstName- the nud ast name for this token
 
 - 
getLedASTNamepublic String getLedASTName() Get led AST Name for this token- Returns:
- the led ast name for this token
 
 - 
setLedASTNamepublic void setLedASTName(String sAstName) Set the led AST Name for this token to be the given string- Parameters:
- sAstName- the led ast name for this token
 
 - 
getValuepublic String getValue() Get a string value that identifies this token- Returns:
- the a string that identifies this token
 
 - 
setValuepublic void setValue(String s) Set the AST Name for this token to be the given string- Parameters:
- s- the ast name for this token
 
 - 
toStringpublic String toString() Return a human-readable description for this token.
 
- 
 
-