-1

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.

What I currently want to do is to support

  • 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

Can somebody tell me hints how to implement this?

bummi
  • 27,123
  • 14
  • 62
  • 101
Paul R
  • 2,631
  • 3
  • 38
  • 72

1 Answers1

1

An working, PSR-0 compatible implementation of the shunting yard algorithm can be found here: https://github.com/andig/php-shunting-yard/tree/dev. It supports constants, custom functions etc.

andig
  • 13,378
  • 13
  • 61
  • 98