Skip to content

This is a just-for-fun implementation of the Shunting Yard Algorithm. It was meant to be a research of the algorithm and experiments during the implementation.

License

Notifications You must be signed in to change notification settings

jorgecortesdev/xpression

Repository files navigation

Xpression

Tests

This is a just for fun implementation of the Shunting Yard Algorithm, it was only meant to be research of the algorithm and experiments during the implementation.

Installation

Just clone the repo:

git clone https://github.com/jorgecortesdev/xpression

Usage

It includes a controller class called Calculator that can be used as:

$expression = "1 + 2 * 3";

$calculator = new Calculator(new SimpleTokenizer, new ShuntingYard, new Postfix);
echo $calculator->read($expression)->evaluate();

It can resolve a more complex expressions like:

$expression = "8 + ( 4 * 2 ) / ( 4 - 2 ) ^ 2";

$calculator = new Calculator(new SimpleTokenizer, new ShuntingYard, new Postfix);
echo $calculator->read($expression)->evaluate();

Notes

  • The expression needs to be separated by spaces, this is due SimpleTokenizer class.
  • The supported operators are:
    • +
    • /
    • *
    • ^
    • -

Tests

To see what is currently tested you can use:

composer install
composer test

About

This is a just-for-fun implementation of the Shunting Yard Algorithm. It was meant to be a research of the algorithm and experiments during the implementation.

Topics

Resources

License

Stars

Watchers

Forks

Languages