Implement a parser that converts a stream of tokens given in infix notation (produced from an input string by the Lexer) into stack of objects representing an expression in postfix notation. This expression should then be evaluated into a float value in a straightforward way (-> tests) by popping/operating on the stack.
The above should be realized by the exceptional answer given in:
The stack of objects should should be represented by two related stacks and a choice method to chose which of the two stacks should be popped next (so that they represent the single object stack). The first stack should be the stack that eventually gets reduced into a single value, the calculated result, and should contain something like:
Operand or RValue (?): an object holding a fixed number that will not change during calculation
The second stack should contain adresses to a number of different
Operator
Function
both of which operate on and transform the first stack.
Implement a parser that converts a stream of tokens given in infix notation (produced from an input string by the
Lexer
) into stack of objects representing an expression in postfix notation. This expression should then be evaluated into a float value in a straightforward way (-> tests) by popping/operating on the stack. The above should be realized by the exceptional answer given in:https://stackoverflow.com/questions/16380234/handling-extra-operators-in-shunting-yard/16392115#16392115
The stack of objects should should be represented by two related stacks and a choice method to chose which of the two stacks should be popped next (so that they represent the single object stack). The first stack should be the stack that eventually gets reduced into a single value, the calculated result, and should contain something like:
Operand
orRValue
(?): an object holding a fixed number that will not change during calculationThe second stack should contain adresses to a number of different
Operator
Function
both of which operate on and transform the first stack.