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.
Field Summary |
com.rychlik.calculator.parser.Token |
jj_nt
|
boolean |
lookingAhead
|
com.rychlik.calculator.parser.Token |
token
|
com.rychlik.calculator.parser.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(com.rychlik.calculator.parser.CalculatorTokenManager tm)
|
Calculator(java.io.InputStream stream)
|
Calculator(java.io.InputStream s,
com.rychlik.calculator.StackMachine sm)
|
Calculator(java.io.Reader stream)
|
Calculator(com.rychlik.calculator.StackMachine sm)
|
Calculator(java.io.StringReader r,
com.rychlik.calculator.StackMachine sm)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
token_source
public com.rychlik.calculator.parser.CalculatorTokenManager token_source
token
public com.rychlik.calculator.parser.Token token
jj_nt
public com.rychlik.calculator.parser.Token jj_nt
lookingAhead
public boolean lookingAhead
Calculator
public Calculator(java.io.StringReader r,
com.rychlik.calculator.StackMachine sm)
Calculator
public Calculator(java.io.InputStream s,
com.rychlik.calculator.StackMachine sm)
Calculator
public Calculator(com.rychlik.calculator.StackMachine sm)
Calculator
public Calculator()
Calculator
public Calculator(java.io.InputStream stream)
Calculator
public Calculator(java.io.Reader stream)
Calculator
public Calculator(com.rychlik.calculator.parser.CalculatorTokenManager tm)
compileStream
public int compileStream()
throws ParseException
ParseException
evalStream
public double evalStream()
throws ParseException
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
ParseException
oneLine
public final void oneLine()
throws ParseException
ParseException
print
public final void print()
throws ParseException
ParseException
ifStatement
public final void ifStatement()
throws ParseException
ParseException
whileStatement
public final void whileStatement()
throws ParseException
ParseException
expression
public final void expression()
throws ParseException
ParseException
simple_expression
public final void simple_expression()
throws ParseException
ParseException
logical
public final void logical()
throws ParseException
ParseException
conjunction
public final void conjunction()
throws ParseException
ParseException
disjunction
public final void disjunction()
throws ParseException
ParseException
relational
public final void relational()
throws ParseException
ParseException
assignment
public final void assignment()
throws ParseException
ParseException
definition
public final void definition()
throws ParseException
ParseException
continueStatement
public final void continueStatement()
throws ParseException
ParseException
breakStatement
public final void breakStatement()
throws ParseException
ParseException
returnStatement
public final void returnStatement()
throws ParseException
ParseException
funcall
public final void funcall()
throws ParseException
ParseException
sum
public final void sum()
throws ParseException
ParseException
term
public final void term()
throws ParseException
ParseException
power
public final void power()
throws ParseException
ParseException
signed_term
public final void signed_term()
throws ParseException
ParseException
signed_power
public final void signed_power()
throws ParseException
ParseException
signed_factor
public final void signed_factor()
throws ParseException
ParseException
factor
public final void factor()
throws ParseException
ParseException
identifier
public final void identifier()
throws ParseException
ParseException
arglist
public final int arglist()
throws ParseException
ParseException
ReInit
public void ReInit(java.io.InputStream stream)
ReInit
public void ReInit(java.io.Reader stream)
ReInit
public void ReInit(com.rychlik.calculator.parser.CalculatorTokenManager tm)
getNextToken
public final com.rychlik.calculator.parser.Token getNextToken()
getToken
public final com.rychlik.calculator.parser.Token getToken(int index)
generateParseException
public final com.rychlik.calculator.parser.ParseException generateParseException()
enable_tracing
public final void enable_tracing()
disable_tracing
public final void disable_tracing()
|