How would the infix and stack priorities be extended to include the operators <, >, <=, >=, ==, !=, !, &&, and ||?
When parsing an infix expression, for example: P + (Q – F) / Y#, each symbol has a priority which is relevant to their order of operation. / and * have a higher priority than + and -.
Here are the priorities I have/understand:
Priority * / + - ( ) #
Infix 2 2 1 1 3 0 0
Stack 2 2 1 1 0 n/a 0
-
Can you please elaborate? I don't understand what you're asking (and I think I should).
twodayslate : When parsing an infix expression, for example: P + (Q – F) / Y#, each symbol has a priority which is relevant to their order of operation. / and * have a higher priority than + and -Svante : Please elaborate by editing your question.twodayslate : edited, thanks for the help. LMK if you understand now... -
Found: Operator Precedence in Java & Infix operators
But why?
Thomas Padron-McCarthy : I still don't understand your question. And yes, I know what operator priorities are, and I know about stacks, and I know about infix (and postfix, and prefix), and I know how to translate between them. And I teach the compiler course. But I don't understand what your question is. -
That depends on what priorities you want, right? Unless you are asking about the priorities in a specific language (if so, elaborate).
Anyway, <, >, <= and >= do not apply to booleans, == and != apply to anything, and !, && and || apply solely to booleans. But they ALL return booleans, so you want to apply those which do not apply to booleans first, those which might apply to booleans next, and finally those which only apply to booleans. As for the last, ! has precedence over && and ||. Though not necessary, I'd make && have precedence over ||, because some logic notations work that way.
So the precedence would wind up being:
( * / + - < > <= >= == != ! && || ) #
0 comments:
Post a Comment