A parentheses expression is a DSL object that explicitly groups a subexpression, causing it to be processed as a unit and to inherit the value and type of that subexpression. section 12.2 section 13.1
Implementation uses parentheses in several connected places:
- The expression AST wraps a subexpression such as 2 + 3 so it is processed before the surrounding operation. section 12.2
- The projection may insert virtual, show-only parentheses when nested binary operations would otherwise hide the AST’s meaning. section 12.2
- The code generator applies the same precedence test when emitting executable expressions, without changing the underlying AST. section 12.2
- The type system returns the type of the Parentheses object’s subexpression, preserving the grouped expression’s semantic type. section 13.1
Grouping 2 + 3
For 1 * (2 + 3), the Parentheses object wraps the 2 + 3 subexpression. The grouping makes that addition occur before multiplication and lets the projection and generated code display the intended order. section 12.2
Figure 12.13 The AST representing the expression 1 * (2 + 3), “fixed” by wrapping 2 + 3 in parentheses
Inspect the AST representation that fixes 1 * (2 + 3) by wrapping 2 + 3 in a Parentheses object. section 12.2
