The comma operator is used to separate multiple expressions within a single statement. It evaluates the left operand, discards the result, evaluates the right operand, and returns the result of the right operand. It is primarily used in situations where multiple expressions need to be executed in a specific order, such as in a for loop's increment section.
Since the operators precedences for lox are more or less the same as those of C, here is a precedence table with a couple of operators used by lox arranged in descending order of precedence:
| Precedence |
Operator |
Description |
Associativity |
| Highest |
?: |
Ternary conditional |
Right to left |
|
== != |
Equality operators |
Left to right |
|
! ~ ++ -- + - |
Unary operators |
Right to left |
|
+ - |
Addition, subtraction |
Left to right |
|
< <= > >= |
Relational operators |
Left to right |
|
* / % |
Multiplication, division, modulo |
Left to right |
|
, |
Comma operator |
Left to right |
The comma operator is used to separate multiple expressions within a single statement. It evaluates the left operand, discards the result, evaluates the right operand, and returns the result of the right operand. It is primarily used in situations where multiple expressions need to be executed in a specific order, such as in a for loop's increment section.
Since the operators precedences for lox are more or less the same as those of C, here is a precedence table with a couple of operators used by lox arranged in descending order of precedence: