在PHP中解析数学表达式

编程入门 行业动态 更新时间:2024-10-18 20:27:05
本文介绍了在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中解析数学表达式

本文发布于:2023-11-10 16:14:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575855.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   数学   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!