com.rychlik.calculator.parser
Class Calculator
java.lang.Object
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.
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 |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
token_source
public CalculatorTokenManager token_source
token
public Token token
jj_nt
public Token jj_nt
lookingAhead
public boolean lookingAhead
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)
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()