Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.voytechs.jnetstream.npl
Class ExpressionParser  view ExpressionParser download ExpressionParser.java

java.lang.Object
  extended bycom.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.Hashtable context
           
private static boolean debug
           
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

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
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.


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