0

I'm learning shunting yard algorithm. I've read wikipedia and it provided me with detailed steps.

But if you write the expression like 1 2 + it will be evaluated in the same way as 1 + 2.

Do you know how to fix it?

  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. [On topic](http://stackoverflow.com/help/on-topic) and [how to ask](http://stackoverflow.com/help/how-to-ask) apply here. – Prune Apr 06 '18 at 17:31
  • In particular, what's wrong with evaluating `1 2 +`? – Prune Apr 06 '18 at 17:32
  • It is not in infix notation. (When implementing mathematical expressions parser you want to be aware that input is incorrect) –  Apr 06 '18 at 17:49
  • Some [solutions have been presented before](https://stackoverflow.com/q/29634992/555045) but IMO if you're going to add significant parser tech you might as well use an actual parser – harold Apr 06 '18 at 17:52
  • Thanks, I haven't seen the solution. Sorry ) –  Apr 06 '18 at 17:54
  • @George: right -- the shunt isn't an accept-reject parser. It promises to properly evaluate legal expressions, but doesn't guarantee rejection of other input. – Prune Apr 06 '18 at 17:56

0 Answers0