1

Assume I have a condition in the form of "(a > b) OR (c < d)". How can I convert it to reverse polish notation and calculate it? I gave it a try by setting the "and/or" tokens at the lowest precedence level and got "a b c OR > d <". Is it right?

Basically I want to add conditional features to this implementation of the shunting yard algorithm; http://eddmann.com/posts/shunting-yard-implementation-in-java/

pnuts
  • 58,317
  • 11
  • 87
  • 139
  • 1
    Operator goes after operands. So: a b > for (a > b). For all of it: a b > c d < OR. Not really sure this is a programming question though. – Steven Hansen Sep 24 '15 at 21:17
  • I'm working on a Shunting Yard algorithm based on this implementation; http://eddmann.com/posts/shunting-yard-implementation-in-java/ – David Jalbert Sep 24 '15 at 21:20
  • And yes, it looks like I just had to change the level of precedence of the conditional tokens. It makes much more sense now. Thanks! – David Jalbert Sep 24 '15 at 21:21

1 Answers1

2

(a > b) OR (c < d) in RPN:

a b > c d < OR

Make sure you read left-to-right:

Post Fix Algorithm

adamsuskin
  • 547
  • 3
  • 16