This is a simple calculator I wrote in Elixir for Web Development - CS4550.
I implemented a lexer, parser, and interpreter for the calculations. I parsed the information into Reverse Polish Notation with the Shunting-Yard Algorithm and evaluated it with a simple stack interpreter in order to guaruntee order of operations.
It supports parentheses, floating-point operations, integer operations, and has four functions (+, -, *, /):
Reverse Polish Notation - https://en.wikipedia.org/wiki/Reverse_Polish_notation
Shunting-Yard Algorithm - https://en.wikipedia.org/wiki/Shunting-yard_algorithm
Write a four function calculator in Elixir.
Start by creating an Elixir project called "calc" with:
$ mix new calc
Your program should consist of a Calc module (lib/calc.ex) with at least two functions:
- Calc.eval (String -> Number) # Should parse and evaulate an arithmetic expression.
- Calc.main # Should repeatedly print a prompt, read one line, eval it, and print the result.
In addition, you should write tests for the public functions in your calc module (test/calc_test.exs), which should pass when you type "mix test".
Sample session:
calc$ mix run -e Calc.main > 2 + 3 5 > 5 * 1 5 > 20 / 4 5 > 24 / 6 + (5 - 4) 5 > 1 + 3 * 3 + 1 11 > ^C^C
- Push your calculator to github.
- Submit a filled in hw04-status.txt