File: actions.yo

package info (click to toggle)
bisonc%2B%2B 6.09.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,984 kB
  • sloc: cpp: 9,375; ansic: 1,505; fortran: 1,134; makefile: 1,062; sh: 526; yacc: 84; lex: 60
file content (32 lines) | stat: -rw-r--r-- 1,455 bytes parent folder | download | duplicates (6)
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
A program usually must do more than just parse its input; it must also produce
some output based on the input. In a b() grammar, a grammar rule can have an
action consisting of bf(C++) statements. Each time the parser recognizes a
match for that rule, its associated action is executed. See section
ref(ACTIONS).

The purpose of an action usually is to compute the semantic value of the whole
construct from the semantic values of its parts. For example, suppose we have
a rule stating that an expression can be the sum of two expressions. Once the
parser has recognized the rule's parts, each of its subexpressions has a
semantic value of its own. The action for this rule
could consist of a bf(C++) expression computing the rule's semantic value from
its subexpressions.

Actions usually compute semantic values and refer to semantic values of
elements of production rules. This happens so frequently that several
shorthand notations can be used to simplify referring to semantic
values. These shorthand notations are covered extensively in section
ref(ACTIONS) and its sub-sections.

For example, here is a rule stating that an expression can be the sum of two
subexpressions:
        verb(
    expr: expr '+' expr   
        { 
            $$ = $1 + $3; 
        }
    ;
        )
    The action defines how the semantic value of the rule (using shorthand
tt($$)) is computed from the values of the two sub-expressions (shorthands
tt($1) and tt($3)).