T
Thomas
Hello I 'm writing a simple ONP expression evaluator with functions in java.
The constrains about the class hierarchy are like that :
abstract Symbol implements Evaluate (which contains
method evaluate)
/ \
/ \
/ \
abstract Function abstract Operand
/ | \ / |
Plus Minus Ln Literal Const Variable
The evaluation process should be : after parsing the input we put all those
object into the queue. By reading the queue and using the stack to keep the
temporary values (both of them I implement on my own) i have to do like that
:
1) if it is an Operand put in on stack
2) if it is an function and
2)a we have enought arguments on stack we valuate the function
2)b we throw exepction
(i can distinguish beetwen this two types and here i don't need help,
because of the diffrent number of arguments they take and exceptions)
In the main loop I have to keep the refrence to the object taken from FIFO,
and here is the problem : what type of refrence it should be ? Not a symbol
because it is abstract, but it implements the Evaluate interface therefore
it would be useful. I
confused. Any suggestions, please ?
The constrains about the class hierarchy are like that :
abstract Symbol implements Evaluate (which contains
method evaluate)
/ \
/ \
/ \
abstract Function abstract Operand
/ | \ / |
Plus Minus Ln Literal Const Variable
The evaluation process should be : after parsing the input we put all those
object into the queue. By reading the queue and using the stack to keep the
temporary values (both of them I implement on my own) i have to do like that
:
1) if it is an Operand put in on stack
2) if it is an function and
2)a we have enought arguments on stack we valuate the function
2)b we throw exepction
(i can distinguish beetwen this two types and here i don't need help,
because of the diffrent number of arguments they take and exceptions)
In the main loop I have to keep the refrence to the object taken from FIFO,
and here is the problem : what type of refrence it should be ? Not a symbol
because it is abstract, but it implements the Evaluate interface therefore
it would be useful. I
confused. Any suggestions, please ?