java.lang.Object
com.voytechs.jnetstream.npl.ExpressionParser
- public class ExpressionParser
- extends java.lang.Object
Express parser.
A standard C-Like expression will be parsed into an expression tree.
The expression tree then can be traversed and evaluated via a number of methods.
The expression parser is called using the parseExpression() method and passing it a String
containing the expression to be parsed.
The parser has the following operators defined:
"+" - class PlusOpNode - NORMAL/BINARY
"-" - class MinusOpNode - NORMAL/BINARY
"*" - class MultiplyOpNode - HIGH/BINARY
"/" - class DivideOpNode - HIGH/BINARY
"&" - class AndOpNode - HIGH/BINARY
"|" - class OrOpNode - HIGH/BINARY
"%" - class ModOpNode - NORMAL/BINARY
"^" - class PowOpNode - NORMAL/BINARY
"~" - class InverseOpNode - LOW/UNARY
"&&" - class LogicalAndOpNode - NORMAL/BINARY
"||" - class LogicalOrOpNode - NORMAL/BINARY
"!" - class LogicalNotOpNode - LOW/UNARY
"==" - class LogicalEqualOpNode - NORMAL/BINARY
"!=" - class LogicalNotEqualOpNode - NORMAL/BINARY
"<" - class LessThanOpNode - NORMAL/BINARY
"<=" - class LessEqualsOpNode - NORMAL/BINARY
"<=" - class GreaterThanOpNode - NORMAL/BINARY
"<=" - class GreaterEqualsThanOpNode - NORMAL/BINARY
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
debug
private static final boolean debug
- See Also:
- Constant Field Values
s1
protected java.util.Stack s1
s2
protected java.util.Stack s2
expression
protected java.lang.String expression
context
public static java.util.Hashtable context
ExpressionParser
public ExpressionParser()
- Initialize the parser.
parse
public Node parse(java.lang.String exp)
throws SyntaxError
- Returns the root node of the parse tree or Glyths.
parse
public Node parse(java.io.Reader input)
throws SyntaxError
- Returns the root node of the parse tree or Glyths.
parseExpression
protected Node parseExpression(ExpTokenizer tokens)
throws SyntaxError
- Returns the root node of the parsed tree or Glyths.
processBuiltinStatement
protected void processBuiltinStatement(ExpTokenizer tokens,
Token token,
Token peek)
- Processes tokens that are builtin statement or variables.
processOpNodes
protected void processOpNodes()
- Processes all of the OP nodes found on the stack until the stack is emptied.
The two stacks are s1 for operators and s2 for operands (parameters)
main
public static void main(java.lang.String[] args)
- Test function for ExpressionParser