Operator precedence: Difference between revisions

Standardize Pascal, allegedly adding new external links [spam detection false positive]
(Standardize Pascal, allegedly adding new external links [spam detection false positive])
Line 16:
=={{header|8th}}==
In 8th it's very simple: the currently invoked word has precedence, and items are operated upon in the order they are popped off the stack.
 
=={{header|6502 Assembly}}==
There are two types of indirect addressing: Indirect X and Indirect Y. These differ in that the indirect X mode applies the offset before looking up the address.
Line 849 ⟶ 850:
|}
=={{header|Delphi}}==
See table at [[#Free Pascal|Free Pascal]].
 
=={{header|Eiffel}}==
 
Line 1,191 ⟶ 1,193:
|}
 
=={{header|Free Pascal}}==
{| class="wikitable" style="margin: auto;"
|+ operator precedence in FreePascal
! operator !! precedence !! category
|-
| <code>not</code>, unary&nbsp;<code>+</code>, unary&nbsp;<code>-</code>, <code>@</code>, <code>**</code> || highest (first) || unary operators, power
|-
| <code>*</code>, <code>/</code>, <code>div</code>, <code>mod</code>, <code>and</code>, <code>shl</code>, <code>shr</code>, <code>as</code>, <code><<</code>, <code>>></code>, <strike><code>is</code> [until FPC 3.3.1]</strike>
| second
| multiplying operators
|-
| <code>+</code>, <code>-</code>, <code>or</code>, <code>xor</code>, <code>><</code>
| third
| adding operators
|-
| <code>=</code>, <code><></code>, <code><</code>, <code>></code>, <code><=</code>, <code>>=</code>, <code>in</code>, <code>is</code> [since FPC 3.3.1]
| lowest
| relational operators
|}
 
“[B]inary operators of the same precedence are left-associative.”
Nevertheless, “[t]he order in which expressions of the same precedence are evaluated is not guaranteed to be left-to-right.”
(quotes from the Free Pascal Reference Guide)
 
The default configuration sets <code>{$boolEval off}</code> (<code>{$B-}</code> for short).
This enables “lazy evaluation” and thus affects evaluation order.
 
One notable difference to standardized [[#Pascal|Pascal]] in operator precedence can be switched:
Normally, Free Pascal’s unary minus is at the highest precedence level.
With <code>{$modeSwitch ISOUnaryMinus+}</code>, which is enabled by default in <code>{$mode ISO}</code> and <code>{$mode extendedPascal}</code>, unary minus can be put at the same level as all other adding operators (like the ISO standards define).
 
=={{header|Furor}}==
Line 1,913 ⟶ 1,945:
 
=={{header|Pascal}}==
Standard Pascal, as laid out in ISO standard 7185, recognizes four precedence levels.
This table contains the precedence and associativity of operators:
Extended Pascal (EP), defined in ISO standard 10206, has one additional level, [[Exponentiation with infix operators in (or operating on) the base#Pascal|exponentiating operators]].
{| class="wikitable"
The following is a consolidated table for both standards:
! Priority || Description || Operators || Associativity
 
{| class="wikitable" style="margin: auto;"
|+ operator precedence in Pascal
! class !! operators
|-
| highest || negation || ||
* <code> (a>n) and (b<n)not</code>
|-
| exponentiating operators ||
| 1 || unary operators ||<code> not @ </code>|| left to right
* <code>**</code> (only in EP)
* <code>pow</code> (only in EP)
|-
| multiplying operators ||
| 2 || mult operators ||<code> * / div mod and shl shr as << >> </code>|| left to right
* <code>*</code>
* <code>/</code>
* <code>div</code>
* <code>mod</code>
* <code>and</code>
* <code>and_then</code> (only available in EP)
|-
| 3 || add adding operators ||<code> + - or xor </code>|| left to right
* <code>+</code>
* <code>-</code>
* <code>><</code> (only in EP)
* <code>or</code>
* <code>or_else</code> (only available in EP)
|-
| relational operators ||
| 4 || relations ||<code> = <> < > <= >= in is </code>|| left to right
* <code>=</code>
|-
* <code><></code>
| lowest || || ||
* <code><</code>
* <code>></code>
* <code><=</code>
* <code>>=</code>
* <code>in</code>
|}
“Sequences of two or more operators of the same precedence shall be left associative.”
'''Example'''::<br>
(quote from ISO standards)
The expression <code> ( a>n and b<n ) </code> is equivalent to :
 
<code> ( ( a > (n and b) ) < n ) </code> , so, it is invalid !<br>
However, unlike some other programming languages, operator precedence ''does not'' define evaluation order.
we must code:<br>
This is because Pascal does not permit “lazy evaluation”:
<code> (a>n) and (b<n)</code>
Except in the case of <code>and_then</code> and <code>or_else</code>, the ''evaluation order implementation-defined''.
Some compilers, for instance the FPC ([[#Free Pascal|Free Pascal]] Compiler), evaluate “more complex” subexpression first before evaluating “easy” subexpressions (rationale: avoid register spilling).
 
=={{header|Perl}}==
149

edits