ezylang / EvalEx

EvalEx is a handy expression evaluator for Java, that allows to evaluate simple mathematical and boolean expressions.
https://ezylang.github.io/EvalEx/
Apache License 2.0
981 stars 268 forks source link

validate() error #175

Closed sunzhiran closed 6 years ago

sunzhiran commented 6 years ago

expression = new Expression("1 1+2/"); the result is 1.5;but this expression is not legal

RobertZenz commented 6 years ago

EvalEx does support Reverse Polish Notation, I'm not completely sure but that might actually be a valid expression. For example, 1 + (1 2)/ is also a valid expression.

But I have too little experience with RPN and the parser of EvalEx to be completely sure about that.

uklimaschewski commented 6 years ago

I added a syntax check for this to the shunting yard method. (See commit 4aaa75f20864f91b70ea59d010c1f5a6b05b0363) EvalEx works with RPN internally when an expression is evaluated. For this, it uses a shunting yard algorithm to transform a normal expression to RPN notation. But the above expression is not even a RPN.