SYA

Published in 2024/08/02 - Source code

SYA is a Shunting Yard Algorithm implemented in Rust, with a Lexer/Tokenizer included.

It can be used to evaluate and solve mathematical expressions and is specially useful when writing a simple interpreter or compiler.

Shunting Yard Algorithm

Basically, the algorithm first converts the mathematical expression into Reverse Polish Notation (RPN):

( A + B * C → ABC * +)

Which is very weird to read and takes some time to get used to it, but it will be useful for us to correctly solve the expressions in the right precedence. After that, the algorithm then traverses through the RPN pushing numbers to the stack. When a operator is found, it is applied to the two last numbers of the stack.

You can check all the source code here.