tracer.expression
Class Symbol

java.lang.Object
  |
  +--tracer.expression.Symbol

public class Symbol
extends java.lang.Object

An input symbol in an expression.


Field Summary
 ExprNode enode
          The reduced expression node, if symbol type if SYM_EXPRNODE.
 Function func
          The function of a TK_FUNCTION token.
 double nval
          The value of a TK_NUMBER token.
(package private) static int[][] precTab
          Precedence table used for parsing the expression.
 int stype
          Symbol type of the symbol.
static int SYM_EXPRNODE
          The symbol type representing a reduced expression node.
static int SYM_TERMINAL
          The symbol type representing a terminal symbol.
static int SYM_UNKNOWN
          The symbol type representing unknown symbol.
static int TK_BRACKETL
          The token representing a left bracket in an expression.
static int TK_BRACKETR
          The token representing a right bracket in an expression.
static int TK_DIV
          The token representing a division sign in an expression.
static int TK_EOE
          The token representing the end of an expression.
static int TK_FUNCTION
          The token representing a function in an expression.
static int TK_MINUS
          The token representing a minus sign in an expression.
static int TK_MULT
          The token representing a multply sign in an expression.
static int TK_NUMBER
          The token representing a number in an expression.
static int TK_PLUS
          The token representing a plus sign in an expression.
static int TK_POW
          The token representing a power sign in an expression.
static int TK_VARIABLE
          The token representing a variable in an expression.
 int ttype
          The terminal type of the symbol, if symbol type if SYM_TERMINAL.
 Variable variable
          The variable of a TK_VARIABLE token.
 
Constructor Summary
Symbol()
          Create an empty symbol.
Symbol(int type, ExprNode en)
          Create a Function token with symbol type specified as SYM_EXPRNODE, and an expression node.
Symbol(int type, int tk)
          Create a token symbol with symbol type and token type.
Symbol(int type, int tk, char vchar)
           
Symbol(int type, int tk, double val)
          Create a Number token with symbol type specified as SYM_TERMINAL, token type specified as TK_NUMBER and a value
Symbol(int type, int tk, java.lang.String str)
          Create a Variable token or Function token with symbol type specified as SYM_TERMINAL.
 
Method Summary
 boolean equal(Symbol a)
          Returns true if current symbol has the same precedence as symbol a.
 boolean greater(Symbol a)
          Returns true if current symbol has higher precedence than symbol a.
 boolean isEOE()
          Returns true if the symbol represents the end of an expression.
 boolean isExprNode()
          Returns true if the symbol represents an expression node.
 boolean less(Symbol a)
          Returns true if current symbol has lower precedence than symbol a.
(package private) static int precTabIndex(int token)
          Convert a token type to an index in the precedence table.
 java.lang.String toString()
          Returns the string representation of the current symbol.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SYM_UNKNOWN

public static final int SYM_UNKNOWN
The symbol type representing unknown symbol.

SYM_EXPRNODE

public static final int SYM_EXPRNODE
The symbol type representing a reduced expression node.

SYM_TERMINAL

public static final int SYM_TERMINAL
The symbol type representing a terminal symbol.

TK_EOE

public static final int TK_EOE
The token representing the end of an expression.

TK_NUMBER

public static final int TK_NUMBER
The token representing a number in an expression.

TK_VARIABLE

public static final int TK_VARIABLE
The token representing a variable in an expression.

TK_BRACKETL

public static final int TK_BRACKETL
The token representing a left bracket in an expression.

TK_BRACKETR

public static final int TK_BRACKETR
The token representing a right bracket in an expression.

TK_PLUS

public static final int TK_PLUS
The token representing a plus sign in an expression.

TK_MINUS

public static final int TK_MINUS
The token representing a minus sign in an expression.

TK_MULT

public static final int TK_MULT
The token representing a multply sign in an expression.

TK_DIV

public static final int TK_DIV
The token representing a division sign in an expression.

TK_POW

public static final int TK_POW
The token representing a power sign in an expression.

TK_FUNCTION

public static final int TK_FUNCTION
The token representing a function in an expression.

stype

public int stype
Symbol type of the symbol.

ttype

public int ttype
The terminal type of the symbol, if symbol type if SYM_TERMINAL.

enode

public ExprNode enode
The reduced expression node, if symbol type if SYM_EXPRNODE.

nval

public double nval
The value of a TK_NUMBER token.

func

public Function func
The function of a TK_FUNCTION token.

variable

public Variable variable
The variable of a TK_VARIABLE token.

precTab

static int[][] precTab
Precedence table used for parsing the expression.
Constructor Detail

Symbol

public Symbol()
Create an empty symbol.

Symbol

public Symbol(int type,
              int tk)
Create a token symbol with symbol type and token type. It is used for creating symbols for operators, EOE and brackets.

Symbol

public Symbol(int type,
              int tk,
              double val)
Create a Number token with symbol type specified as SYM_TERMINAL, token type specified as TK_NUMBER and a value

Symbol

public Symbol(int type,
              int tk,
              char vchar)
       throws ExpressionParseException

Symbol

public Symbol(int type,
              int tk,
              java.lang.String str)
       throws ExpressionParseException
Create a Variable token or Function token with symbol type specified as SYM_TERMINAL. Variable token will be created if token type is specified as TK_VARIABLE and the string representation of a variable ("X", "Y", "Z", "E", "PI") is given. Function token will be created if token type is specified as TK_FUNCTION and the string representation of the function is given.

Symbol

public Symbol(int type,
              ExprNode en)
Create a Function token with symbol type specified as SYM_EXPRNODE, and an expression node.
Method Detail

precTabIndex

static int precTabIndex(int token)
                 throws ExpressionParseException
Convert a token type to an index in the precedence table.

isEOE

public boolean isEOE()
Returns true if the symbol represents the end of an expression.

isExprNode

public boolean isExprNode()
Returns true if the symbol represents an expression node.

less

public boolean less(Symbol a)
             throws ExpressionParseException
Returns true if current symbol has lower precedence than symbol a.

equal

public boolean equal(Symbol a)
              throws ExpressionParseException
Returns true if current symbol has the same precedence as symbol a.

greater

public boolean greater(Symbol a)
                throws ExpressionParseException
Returns true if current symbol has higher precedence than symbol a.

toString

public java.lang.String toString()
Returns the string representation of the current symbol.
Overrides:
toString in class java.lang.Object