Operator Priority or Maximum Munch Rule for First Inherited Operators

Here I have the following code snippet:

int a,b,x;
a=b=1;
x=a+++b;

Now the value xwill be 2, because it awill increase first, and then added to b.

The following is a compiled bytecode:

 0  iconst_1
 1  dup
 2  istore_2 [b]
 3  istore_1 [a]
 4  iload_1 [a]
 5  iinc 1 1 [a]
 8  iload_2 [b]
 9  iadd
10  istore_3 [x]

Thus, the expression will be equivalent x = (a++) + b.

Now, another expression x=a++++bwill not compile due to the maximum munch rule. It will become x = (a++) ++ band therefore a compilation error.

Is the above behavior x=a+++bdue to the priority of the ++ operator or because of the max munch rule ?

+4
3

:

, , .

, a-b (§3.5) a, -, b,    - ,    a, -, -, b   .

,

x=a+++b

x=(a++)+b

, a++++b ++, ++, b, .

+7

"++" "++". +++ b, - "add", (++) - "increment variable by 1". "++++", , a<unary increment variable by 1> <add> <add>, . " ", (a ++) .

, Java ,

z = a++ + ++b;  // this works
z = a+++++b;    // this fails

, , ( ++ ++

0

munch - , lexer, , lexer . , x=a+++b x=(a++)+b - munch, :

lexer a+++b, [ a] [ ] [] [ b]. [ ] ( , ++ , +). (a ++) + b .

0

All Articles