本文介绍了在PHP中解析数学表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将数学表达式解析成表达式树。 但我被困在我需要实现功能和否定的舞台上。我不明白使用Shunting-Yard算法的逻辑。
I'm currently trying to parse math expression into expression tree. But I'm stuck on the stage where I need to implement functions and negates. I don't understand logic to do it using Shunting-Yard algorithm.
我目前想做的是支持
- 否定,像 - (x + 5)
- 函数调用,如min(x,y)
- 功能刚刚在函数名称后面,像cos ^ 2(x)
- 隐含乘法,像2x一样2 * x
- 科学符号
- 常量e和pi
- Negates, like -(x+5)
- Function calls, like min(x,y)
- Power just after function name, like cos^2(x)
- Implicit multiplication, like 2x is same as 2*x
- Scientific notation
- Constants e and pi
有人可以告诉我如何实现这个吗? p>
Can somebody tell me hints how to implement this?
推荐答案工作,PSR-0兼容的分流码算法的实现可以在这里找到: github/andig/php-shunting-yard/tree/dev 。 它支持常量,自定义功能等。
An working, PSR-0 compatible implementation of the shunting yard algorithm can be found here: github/andig/php-shunting-yard/tree/dev. It supports constants, custom functions etc.
更多推荐
在PHP中解析数学表达式
发布评论