World's most popular travel blog for travel bloggers.

[Solved]: Binary operators with higher precedence than unary operators

, , No Comments
Problem Detail: 

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.

Asked By : Ray Toal

Answered By : mhum

In Perl, the 'not' operator has lower precedence than +. The expression (false + not 1) evaluates just fine.

Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/18835

 Ask a Question

 Download Related Notes/Documents

0 comments:

Post a Comment

Let us know your responses and feedback