Evaluating mathematical expressions in Python

前端 未结 5 1254
小鲜肉
小鲜肉 2020-12-17 18:24

I want to tokenize a given mathematical expression into a parse tree like this:

((3 + 4 - 1) * 5 + 6 * -7) / 2

                          \'/\'
                      


        
5条回答
  •  隐瞒了意图╮
    2020-12-17 19:20

    Several parser frameworks exist for Python; some common ones are PLY and pyparsing. Ned Batchelder has a pretty complete list.

提交回复
热议问题