Debian Codegraph @

documentation/manual/grammar/alternatives.yo

raw
1 Simple alternatives can be specified using the vertical bar (tt(|)). Each
2 alternative should begin with a unique identifying terminal token. The
3 terminal token may actually be hidden in a nonterminal rule, in which case
4 that nonterminal can be used as an alias for the nonterminal. In fact
5 identical terminal tokens may be used if at some point the terminal tokens
6 differ over different alternatives. Here are some examples:
7 verb(
8 // Example 1: plain terminal distinguishing tokens
9 expr:
10 ID
11 |
12 NUMBER
13 ;
14
15 // Example 2: nested terminal distinguishing tokens
16 expr:
17 id
18 |
19 number
20 ;
21
22 id:
23 ID
24 ;
25
26 number:
27 NUMBER
28 ;
29
30 // Example 3: eventually diverting routes
31 expr:
32 ID
33 id
34 |
35 ID
36 number
37 ;
38
39 id:
40 ID
41 ;
42
43 number:
44 NUMBER
45 ;
46 )