com.voytechs.jnetstream.npl
Class ExpressionParser

java.lang.Object
  extended by 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


Field Summary
static java.util.Map context
           
protected  java.lang.String expression
           
protected  java.util.Stack s1
           
protected  java.util.Stack s2
           
 
Constructor Summary
ExpressionParser()
          Initialize the parser.
 
Method Summary
static void main(java.lang.String[] args)
          Test function for ExpressionParser
 Node parse(java.io.Reader input)
          Returns the root node of the parse tree or Glyths.
 Node parse(java.lang.String exp)
          Returns the root node of the parse tree or Glyths.
protected  Node parseExpression(ExpTokenizer tokens)
          Returns the root node of the parsed tree or Glyths.
protected  void processBuiltinStatement(ExpTokenizer tokens, Token token, Token peek)
          Processes tokens that are builtin statement or variables.
protected  void processOpNodes()
          Processes all of the OP nodes found on the stack until the stack is emptied.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s1

protected java.util.Stack s1

s2

protected java.util.Stack s2

expression

protected java.lang.String expression

context

public static java.util.Map context
Constructor Detail

ExpressionParser

public ExpressionParser()
Initialize the parser.

Method Detail

parse

public Node parse(java.lang.String exp)
           throws SyntaxError
Returns the root node of the parse tree or Glyths.

Parameters:
exp - Expression string to be parsed into the expression tree.
Returns:
Root node of the parsed tree.
Throws:
SyntaxError

parse

public Node parse(java.io.Reader input)
           throws SyntaxError
Returns the root node of the parse tree or Glyths.

Parameters:
exp - Input Reader stream to be parsed into the expression tree.
Returns:
Root node of the parsed tree.
Throws:
SyntaxError

parseExpression

protected Node parseExpression(ExpTokenizer tokens)
                        throws SyntaxError
Returns the root node of the parsed tree or Glyths.

Parameters:
tokens - Tokenizer object initialized with the express string or stream.
Throws:
SyntaxError

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

Parameters:
args - command line arguments