- The main algorithms used in the program are the Shunting yard and Reverse Polish Notation/AST evaluation to transform the mathematical infix expression into a postfix notation, making easier for computers to work with
- I split the expression given by the user into many tokens - pass those to my infix to postfix function, then evaluate the AST
- Taylor series was used to approximate the values of the trig functions
- one limitation is the need for spaces between numbers, functions and operators in your expression (see example below)
- the
github.com/golang-collections/collection
repo is used for the Stack and Queue Data Structure
git clone https://github.com/nizarbenalla/Math-Expression-Evaluator.git
cd MathExpressionEvaluator
go build
./MathExpressionEvaluator_ -math <expression>
./MathExpressionEvaluator_ -math "( cos ( 1 ) + 3 ) * ( 10 - 1 + 1 ) "
Your answer is :
35.4030230586814
./MathExpressionEvaluator_ -math "( 1 - 8 ) + ( 5 / 2 )"
Enter the expression you want to compute
-4.5
./MathExpressionEvaluator_ -math " cos ( 1 ) "
Your answer is :
0.5403023058681397