[fpc-devel] Incomplete docs on operator precedence / Question about actual precedence

Sven Barth pascaldragon at googlemail.com
Mon Feb 3 15:37:00 CET 2014


Am 03.02.2014 12:17, schrieb Michael Van Canneyt:
>
>
> On Mon, 3 Feb 2014, Sven Barth wrote:
>
>> Am 03.02.2014 12:04, schrieb Michael Van Canneyt:
>>>
>>>
>>> On Mon, 3 Feb 2014, Sven Barth wrote:
>>>
>>>> Am 03.02.2014 08:58, schrieb Michael Van Canneyt:
>>>>> As for unary minus: this is the same as a binary minus in 
>>>>> arithmatic expressions.
>>>>
>>>> Not quite. Take this example:
>>>> === output end ===
>>>>
>>>> So unary minus (and also unary plus which is a valid operator as 
>>>> well!) binds stronger than multiplication.
>>>
>>> Then that is an anomaly introduced by operator overloading.
>>>
>>> In math, -2^2 = -4
>> Yes and the same is true in FPC with operator overloading. If you add 
>> a ** operator overload (which uses Trunc(Power(aLeft.i, aRight.i)) ) 
>> and have this expression: -t1 ** t2 with t1.i = 2 and t2.i = 2 the 
>> result will be -4 as well.
>>
>> Please keep in mind that -2^2 is (-2) * (-2).
>
> ? Not in math:
>
> -2^2 = - (2^2)
Eh, yes, sorry. It should have been - (2 * 2) of course *blush*

Nevertheless FPC provides the correct operator precedence (no matter 
whether overloading is used or not, because that is done at a different 
level of the parser):
- power
- unary plus/minus
- product/divison
- addition/substraction

Regards,
Sven



More information about the fpc-devel mailing list