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