java method for parsing nested expressions

后端 未结 5 1206
Happy的楠姐
Happy的楠姐 2020-12-16 04:37

lets say I\'ve written a function to evaluate a simple mathematical operation, and I have some user input in a string such as: \"1 + [2 + [3+4]]\" How can I parse these squa

5条回答
  •  悲&欢浪女
    2020-12-16 05:02

    I think regex is not a good choice to achieve this functionality

    You should convert user expression to postfix or prefix notation and then build an expression tree from them. This is a standard approach in CS (language does not really matter here) to solve this issue in a clean way

提交回复
热议问题