Generally (perhaps always) in programming languages, unary operators have the highest precedence. In some langauges, such as Standard ML, one can dynamically change the precedence of binary operators at run time.
But what if we have a language where binary operators had higher precedence than unary ones? Do such languages exist? And how would we interpret certain cases? For example, let's say binary +
had higher precedence than unary prefix @
. In some cases this is obvious because it would mean that
@x+y
would parse as
@(x+y)
rather than
(@x)+y
BUT, how would we parse
x + @y
Would it be a syntax error (as in it cannot be parsed) or should it parse as x+(@y)
? I don't mean for this to necessarily be an opinion question; I am more interested to know if any real programming languages exist with high-precedence binary operators, and if so, what do they do.
not
,and
, andor
despite using them frequently in the past. I would accept that as an answer. I'm just so used to that Wirth-style of grammar writing where the operator precedence is built into parsing rules and that approach would seem to me to make syntax errors out of these things. I realize a language can parse with anything-goes rules but drew a blank as to which languages did this. Prolog and Perl are great answers. $\endgroup$EXP -> [not] TERM {'+' TERM}
andTERM -> FACTOR {'*' FACTOR}
andFACTOR -> id | numlit
for example, then there would be no way to parsex + not y
with this grammar. So the grammar would have to be written some other way, I would think. $\endgroup$