Arithmetic evaluation: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1,332:
There are python modules, such as Ply, which facilitate the implementation of parsers. This example, however, uses only standard Python with the parser having
two stacks, one for operators, one for operands.
<lang Python>import operator
 
class AstNode(object):
Line 1,447:
expr = raw_input("Expression:")
astTree = Lex( expr, Yaccer())
print expr, '=',astTree.eval()</Pythonlang>