Evaluates arithmetic expressions
Using the Shunting yard algorithm it produces an expression tree which is then evaluated by depth-first searching it.
git clone https://github.com/TrAyZeN/arith-eval.git
cd arith-eval
cargo build --release
./arith-eval "12 * (5 - 2) % 4 + 8"
The following grammar is read by the parser. Terminals are single-quoted.
expr ::= term term_follow
term_follow ::= '+' term term_follow
| '-' term term_follow
| Ɛ
term ::= factor factor_follow
factor_follow ::= '*' factor factor_follow
| '/' factor factor_follow
| '%' factor factor_follow
| Ɛ
factor ::= '(' expr ')'
| number
number ::= digit | digit number
digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
Contribution are welcomed
license TrAyZeN