| 1 |
Syntax: quote( |
| 2 |
bf(%left) [ <type> ] terminal(s) nl() |
| 3 |
bf(%nonassoc) [ <type> ] terminal(s) nl() |
| 4 |
bf(%right) [ <type> ] terminal(s) |
| 5 |
) |
| 6 |
These directives are called em(precedence directives) (see also section |
| 7 |
ref(PRECEDENCE) for general information on operator precedence). |
| 8 |
|
| 9 |
The tt(%left), tt(%right), and tt(%nonassoc) directives are used to |
| 10 |
declare tokens and to specify their precedence and associativity, all at once. |
| 11 |
itemization( |
| 12 |
it() The em(associativity) of an operator tt(op) determines how repeated |
| 13 |
uses of the operator em(nest): whether `tt(x op y op z)' is parsed by combining |
| 14 |
tt(x) with tt(y) first or by combining tt(y) with tt(z) first. tt(%left) |
| 15 |
specifies em(left-associativity) (combining tt(x) with tt(y) first) and |
| 16 |
tt(%right) specifies em(right-associativity) (combining tt(y) with tt(z) |
| 17 |
first). tt(%nonassoc) specifies em(no) associativity, which means that `tt(x |
| 18 |
op y op z)' is not a defined operation, and could be considered an error. |
| 19 |
it() The em(precedence) of an operator determines how it nests in |
| 20 |
combination with other operators. All the tokens declared in a single |
| 21 |
precedence directive have equal precedence and nest together according to |
| 22 |
their associativity. When two tokens declared in different precedence |
| 23 |
directives associate, the one declared em(later) has the higher precedence and |
| 24 |
is grouped em(first). |
| 25 |
) |
| 26 |
The tt(<type>) specification is optional, and specifies the type of the |
| 27 |
semantic value when a token specified to the right of a tt(<type>) |
| 28 |
specification is received. The pointed arrows are part of the type |
| 29 |
specification; the type itself must be a field of a tt(%union) |
| 30 |
(see section ref(UNION)) or it must be a polymorphic em(tag) (see section |
| 31 |
ref(POLYMORPHIC)). |
| 32 |
|
| 33 |
When multiple tokens are listed they must be separated by whitespace or by |
| 34 |
commas. Note that the precedence directives also serve to define token names: |
| 35 |
symbolic tokens mentioned with these directives should not be defined using |
| 36 |
tt(%token) directives. |
| 37 |
|