File: nested.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 (51 lines) | stat: -rw-r--r-- 1,636 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Finally, we add the em(nested) rule to our bag of rule-tricks. Again, nested
rules appear frequently: parenthesized expressions and compound statements are
two very well known examples. These kind of rules are characterized by the
fact that the nested variant is itself an example of the element appearing in
the nested variant. The definition of a statement is actually a bit more
complex than the definition of an expression, since the statement appearing in
the compound statement is in fact an optional series of elements. Let's first
have a look at the nested expression rule. Here it is, in a basic form:
        verb(
    expr:
        NUMBER
    |
        ID
    |
        expr '+' expr
    |
        ...
    |
        '(' expr ')'
    ;
        )
    This definition is simply characterized that the nonterminal tt(expr)
appears within a set of parentheses, which is not too complex. 

    The definition of tt(opt_statements), however, is a bit more complex. But
acknowledging the fact that a tt(statement) contains among other elements a
compound statement, and that a compound statement, in turn, contains
tt(opt_statements) an tt(opt_statements) construction can be formulated
accordingly:
        verb(
    opt_statements:         // define an optional series
        // empty
    |
        opt_statements statement
    ;
        
    statement:              // define alternatives for `statement'
        expr_statement
    |
        if_statement
    |
        ...
    |
        compound_statement
    ;

    compound_statement:     // define the compound statement itself
        '{' opt_statements '}'
    ;
        )