Diana proposed an algorithm for parsing complex mathematical expressionsspecified in an infix notation is one where an operator is present between two operandse.g.(2+5.This algorithm is also used in compiler creation in the parsing phase to generate abstract syntax treeand postfix notations.The algorithm also involves parsing expressions including parenthess and power operations.the algorithm is basically,stack based.
It is a simple example of shunting yard algorithm:
input:3+4 Add 3 to the output queue(whenever a number is read,it is add to the output).push ‘+’ onto the operator stack .Add 4 to the output queue.After readind the expression ,pop the operators off the stack and add them to the output. In these case,there only one operator,’+’.The resulting postfix notation is ‘34+’.
Your friend has requested you to help him in implementing this algorithm as he has to solve large mathmatical expressions given in infix notations
Note:the characters in the input are seperated by spaces
Ex :
i/p1:10+2*6
o/p:22
Comments
Leave a comment