Arity counts how many subexpressions, or operands, an AST object for an expression concept can contain. Properties whose values are not subexpressions do not contribute. Most expression concepts have arity 0, 1, 2, or 3. section 11.5.1
Common arities have specific names:
- Nullary expressions contain no subexpressions, as with literals and other references to AST objects. section 11.5.1
- Unary expressions contain one subexpression, as with logical negation, arithmetic negation, grouping, and increment or decrement. section 11.5.1
- Binary expressions contain two subexpressions, commonly named the left and right operands. section 11.5.1
- Ternary expressions contain three subexpressions; variadic expressions contain a variable number, as in function calls or array literals. section 11.5.1
Arity and compositionality
A positive-arity expression can contain other expressions as operands. Replacing a subexpression with the value produced by evaluating it leaves the whole expression's result unchanged. Repeated composition can therefore construct ASTs of arbitrary size from a small set of expression concepts. section 11.5.2
Table 11.1 Expression concepts and their properties
|
Concept
|
Arity (properties containing subexpressions)
|
Other properties
|
|---|---|---|
Attribute Reference
|
0
|
"attribute" (a reference to an
Attribute)
|
Binary Operation
|
2 ("left operand", "right operand")
|
"operator" (a value from a small, fixed set of strings)
|
Number
|
0
|
"value" (a string that represents a number value)
|
Compare expression concepts by separating their subexpression-bearing properties from their other properties. section 11.5.1




