Debian Codegraph @

documentation/manual/directives/defaultactions.yo

raw
1 Syntax: bf(%default-actions) tt(off|quiet|warn|std)
2
3 By default, production rules without final action blocks are augmented by the
4 bf(bison)(1) parser generator with tt($$ = $1) action blocks: the semantic
5 value of the first component is returned as the rule's semantic value. Its
6 manual also states that for empty rules there is no meaningful default
7 action. However, it could be argued that empty production rules could return
8 default semantic values, resulting in every matched rule having a defined
9 semantic value.
10
11 When multiple semantic value types are used, the semantic value type returned
12 by a tt($$ = $1) action is not uniquely defined. For one rule tt($1) might be
13 an tt(int) field in a union, for another rule it might be a tt(std::string
14 *). With polymorphic semantic values comparable situations are encountered.
15
16 By default, b() mimics bison's behavior in that it adds a tt($$ = $1) action
17 block to rules not having final action blocks, but not to empty production
18 rules. This default behavior can also explicitly be configured using the
19 tt(default-actions std) option or directive.
20
21 B() also supports alternate ways of handling rules not having final action
22 blocks. When tt(off) is specified, b() does not add tt($$ = $1) action
23 blocks; when polymorphic semantic values are used, then specifying
24 itemization(
25 it() tt(warn) adds specialized action blocks, using the semantic types of
26 the first elements of the production rules, while issuing a warning;
27 it() tt(quiet) adds these action blocks without issuing warnings.
28 )
29 When either tt(warn) or tt(quiet) are specified the types of $$ and $1 must
30 match. When b() detects a type mismatches it issues errors.
31
32 When polymorphic semantic values are used then the default tt($$ = $1) action
33 probably is less useful than when, e.g., plain tt(%stype) semantic values are
34 used. After all, no semantic values are associated with tt($$). Furthermore,
35 once the production rule has been recognized, the production rule is reduced
36 to the rule's left-hand side non-terminal. Thus, tt($1) ceases to exists,
37 immediately following the tt($$ = $1) statement. Therefore, em(if) default
38 actions are used in combination with polymorphic semantic value types they are
39 implemented using move-operations: tt($$ = std::move($1)). However, in this
40 situation default actions can frequently be suppressed, slightly improving the
41 efficency of the generated parser.
42
43 When a default action block can be added to a production rule and either
44 tt(warn) or tt(quiet) was specified, b() compares the types associated with
45 rule's nonterminal, and with the production rule's first element. The tt(warn)
46 and tt(quiet) specifications make identical decisions about the action
47 blocks to add, but in addition tt(warn) also shows a warning message that the
48 action block is added to the production rule.
49 itemization(
50 it() If no type is associated with the rule then no default action block
51 is added if no type was associated with the production rule's first
52 element either; otherwise an error is issued.
53 it() If the rule's type is tt(STYPE_) then, if no type is associated
54 with the production rule's first element it is initialized to
55 tt(STYPE_); otherwise it is initialized with the first element's
56 semantic value.
57 it() If the rule is associated with a polymorphic tag then, if the same
58 tag was associated with production rule's first element it is
59 initialized with the first element's semantic value. Otherwise an
60 error is issued.
61 )
62