com.rychlik.calculator.parser
Class Calculator

java.lang.Object
  extended by com.rychlik.calculator.parser.Calculator
All Implemented Interfaces:
CalculatorConstants

public class Calculator
extends java.lang.Object
implements CalculatorConstants

This class implements a parser for a simple arithmetical language.


Field Summary
 Token jj_nt
           
 boolean lookingAhead
           
 Token token
           
 CalculatorTokenManager token_source
           
 
Fields inherited from interface com.rychlik.calculator.parser.CalculatorConstants
AND, ASSIGN, BEGIN, BREAK, COMMA, CONSTANT, CONTINUE, DEFAULT, DEFINE, DIGIT, DIVIDE, ELSE, END, EOF, EOL, EQ, EXP, FLOAT, GE, GT, ID, IF, ILLEGAL, INTEGER, LE, LETTER, LPAREN, LT, MINUS, MULTIPLY, NE, OR, PLUS, PRINT, RETURN, RPAREN, SEPARATOR, tokenImage, WHILE
 
Constructor Summary
Calculator()
           
Calculator(CalculatorTokenManager tm)
           
Calculator(java.io.InputStream stream)
           
Calculator(java.io.InputStream s, StackMachine sm)
           
Calculator(java.io.Reader stream)
           
Calculator(StackMachine sm)
           
Calculator(java.io.StringReader r, StackMachine sm)
           
 
Method Summary
 int arglist()
           
 void assignment()
           
 void breakStatement()
           
 void checkIdentifier(java.lang.String id)
          Check whether id is a legal identifier.
 int compileStream()
           
 int compileString(java.lang.String s)
           
 void conjunction()
           
 void continueStatement()
           
 void definition()
           
 void disable_tracing()
           
 void disjunction()
           
 void enable_tracing()
           
 double evalStream()
           
 double evalString(java.lang.String s)
           
 void expression()
           
 void factor()
           
 void funcall()
           
 ParseException generateParseException()
           
 Token getNextToken()
           
 Token getToken(int index)
           
 void identifier()
           
 void ifStatement()
           
 void logical()
           
 void oneLine()
           
 void power()
           
 void print()
           
 void program()
           
 void ReInit(CalculatorTokenManager tm)
           
 void ReInit(java.io.InputStream stream)
           
 void ReInit(java.io.Reader stream)
           
 void relational()
           
 void returnStatement()
           
 void signed_factor()
           
 void signed_power()
           
 void signed_term()
           
 void simple_expression()
           
 void sum()
           
 void term()
           
 void whileStatement()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

token_source

public CalculatorTokenManager token_source

token

public Token token

jj_nt

public Token jj_nt

lookingAhead

public boolean lookingAhead
Constructor Detail

Calculator

public Calculator(java.io.StringReader r,
                  StackMachine sm)

Calculator

public Calculator(java.io.InputStream s,
                  StackMachine sm)

Calculator

public Calculator(StackMachine sm)

Calculator

public Calculator()

Calculator

public Calculator(java.io.InputStream stream)

Calculator

public Calculator(java.io.Reader stream)

Calculator

public Calculator(CalculatorTokenManager tm)
Method Detail

compileStream

public int compileStream()
                  throws ParseException
Throws:
ParseException

evalStream

public double evalStream()
                  throws ParseException
Throws:
ParseException

compileString

public int compileString(java.lang.String s)
                  throws ParseException
Parameters:
s - String to be evaluated.
Returns:
The value of the expression.
Throws:
ParseException - Thrown when the string does not represent a syntactically correct expression.

evalString

public double evalString(java.lang.String s)
                  throws ParseException
Parameters:
s - String to be evaluated.
Returns:
The value of the expression.
Throws:
ParseException - Thrown when the string does not represent a syntactically correct expression.

checkIdentifier

public void checkIdentifier(java.lang.String id)
                     throws ParseException
Check whether id is a legal identifier.

Parameters:
id - The name of the variable
Throws:
ParseException - if id is not a valid identifier.

program

public final void program()
                   throws ParseException
Throws:
ParseException

oneLine

public final void oneLine()
                   throws ParseException
Throws:
ParseException

print

public final void print()
                 throws ParseException
Throws:
ParseException

ifStatement

public final void ifStatement()
                       throws ParseException
Throws:
ParseException

whileStatement

public final void whileStatement()
                          throws ParseException
Throws:
ParseException

expression

public final void expression()
                      throws ParseException
Throws:
ParseException

simple_expression

public final void simple_expression()
                             throws ParseException
Throws:
ParseException

logical

public final void logical()
                   throws ParseException
Throws:
ParseException

conjunction

public final void conjunction()
                       throws ParseException
Throws:
ParseException

disjunction

public final void disjunction()
                       throws ParseException
Throws:
ParseException

relational

public final void relational()
                      throws ParseException
Throws:
ParseException

assignment

public final void assignment()
                      throws ParseException
Throws:
ParseException

definition

public final void definition()
                      throws ParseException
Throws:
ParseException

continueStatement

public final void continueStatement()
                             throws ParseException
Throws:
ParseException

breakStatement

public final void breakStatement()
                          throws ParseException
Throws:
ParseException

returnStatement

public final void returnStatement()
                           throws ParseException
Throws:
ParseException

funcall

public final void funcall()
                   throws ParseException
Throws:
ParseException

sum

public final void sum()
               throws ParseException
Throws:
ParseException

term

public final void term()
                throws ParseException
Throws:
ParseException

power

public final void power()
                 throws ParseException
Throws:
ParseException

signed_term

public final void signed_term()
                       throws ParseException
Throws:
ParseException

signed_power

public final void signed_power()
                        throws ParseException
Throws:
ParseException

signed_factor

public final void signed_factor()
                         throws ParseException
Throws:
ParseException

factor

public final void factor()
                  throws ParseException
Throws:
ParseException

identifier

public final void identifier()
                      throws ParseException
Throws:
ParseException

arglist

public final int arglist()
                  throws ParseException
Throws:
ParseException

ReInit

public void ReInit(java.io.InputStream stream)

ReInit

public void ReInit(java.io.Reader stream)

ReInit

public void ReInit(CalculatorTokenManager tm)

getNextToken

public final Token getNextToken()

getToken

public final Token getToken(int index)

generateParseException

public ParseException generateParseException()

enable_tracing

public final void enable_tracing()

disable_tracing

public final void disable_tracing()