# Questions tagged [operator-precedence]

The tag has no usage guidance.

15 questions
Filter by
Sorted by
Tagged with
1answer
103 views

### How can I efficiently test that a parser handles multiple levels of operator precedence correctly?

I'm working on a parser for a (very small) toy language, and I want to test that it's parsing expressions with the appropriate precedence. Previously I just had arithmetic operators, so there weren't ...
2answers
834 views

### What is the logic in the order of operator precedence? [closed]

Absolutely academic context question- I found countless articles listing the order of operator precedence in all languages, but what is the logical reasoning behind that specific order? For clarity ...
2answers
3k views

### Should I use parenthesis around every operators?

The facts This is a very similar question to this one, but here I am talking about a more general case the MISRA-C3 Rule 5.0.2 or the SEI CERT C EXP00-C rule (more permissive). Within MISRA-C3 I ...
2answers
195 views

### Operators precedence

I have a code snippet in Java: int y = ++x * 5 / x-- + --x; So my confusion was since x--(postfix) has higher precedence than ++x(prefix) operator so x-- should be executed first then ++x.But a ...
2answers
166 views

### Operators precedence in java (unary plus and addition) [closed]

I'm having trouble in figuring out why the output for theses two lines is different .. public static void main(String[] args) { System.out.println("6.0+1="+6.0+1); System.out.println("6.0+1="+(...
1answer
2k views

### Shunting-yard algorithm and unary minus

I am attempting to implement a shunting-yard algorithm for a calculator following the rules laid out in https://en.wikipedia.org/wiki/Shunting-yard_algorithm . When programming the unary minus, ...
3answers
2k views

### Is order of arguments in an arithmetic expression important to achieve as most exact result as possible (speed is not necessary)?

Actually, in this question I do not ask about particular language or architecture, however I understand there might be some differences. In physics / engineering it is usually better to handle ...
3answers
176 views

### Proper way to interpret this dereference operation?

I've seen this example in a text book and am a little confused how to interpret the operator precedence rules. Given this struct: typedef struct { char *data; size_t start, end; } ...
3answers
5k views

### Precedence of function in Shunting-yard algorithm

I am working through the Shunting-yard algorithm, as described by wikipedia. The description of the algorithm when dealing with operators is as follows: If the token is an operator, o1, then: ...
1answer
142 views

### The difference between (-(a*b)) and ((-a)*b)

One of our teachers said that there is just one example that there is a difference between (-(a*b)) and ((-a)*b). He said by using two's complement you can find one. I am trying to find this example. ...
1answer
280 views

### Order of Operations Annoyance [duplicate]

In most programming languages (C#, JavaScript, Java) the order of operations precedence has that equality comparison come BEFORE bitwise comparisons. This means that if you have a bit operation and ...
2answers
862 views

### Should ** bind more tightly than !, ~?

Designing a programming language, I'm including the ** exponentiation operator. In Fortran and Python, the two languages I know of which have this operator, it binds more tightly than unary minus, ...
14answers
73k views

### Should I use parentheses in logical statements even where not necessary?

Let's say I have a boolean condition a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedent than OR. I could write this line of code: If (a AND b) OR (c AND d)...
1answer
180 views

### Evaluation order of the expressions

The C Programming Language by K & R states that C, like most languages, does not specify the order in which operands of an operator are evaluated. (The exceptions are &&,||,?: and ','). ...
2answers
7k views

### Why do bitwise operators have lower priority than comparisons?

Could someone explain the rationale, why in a bunch of most popular languages (see note below) comparison operators (==, !=, <, >, <=, >=) have higher priority than bitwise operators (&, |, ^...