OpenSCAD User Manual's section on operators does not mention precedence. Quick Web searches found nothing. I assume the usual order of exponentiation, then multiplication, then addition does hold, but how does e.g. a conditional operator or unary minus interact with these? Is there an official document describing the precedence of operators in OpenSCAD?
Asked
Active
Viewed 115 times
4
-
I'm not sure if/where it's documented but I think largely they follow C or C++ precedent for precedence. – R.. GitHub STOP HELPING ICE Sep 28 '21 at 02:12
-
1If you aren't sure, use parenthesis to force precedence. – 0scar Sep 28 '21 at 11:39
-
@0scar That's what I'm doing, but it would be nice to know. – user31389 Sep 28 '21 at 12:55
1 Answers
3
Within OpenSCAD expressions, the order of precedence is:
Operators | Description |
---|---|
() [] | group, vector, or range |
() [] . | function call, indexing, member lookup |
^ | exponentiation |
! + - | unary operations |
* / % | multiplication |
+ - | addition |
< <= >= > | ordering |
== != | equality |
&& | logical AND |
|| | logical OR |
?: function() let() assert() echo() | ternary operator and unary pseudo-operators |
There are no bit-wise operators, and neither comma nor "=" are operators.
Source: openscad/src/parser.y