File: rpninput.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 (28 lines) | stat: -rw-r--r-- 1,272 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
Consider the definition of tt(input):
        verb(
    input:    
            // empty 
    | 
            input line
    ;
        )
    This definition should be read as follows: em(A complete input is either
an empty string, or a complete input followed by an input line). Notice that
`complete input' is defined in terms of itself. This definition is said to be
em(left recursive) since the rule's nonterminal (tt(input)) appears as the
leftmost symbol in the production rule. See section ref(RECURSIVE).

The first alternative is empty: there are no symbols between the colon and the
first `tt(|)'; this means that input can match an empty string of input (no
tokens). We write the rules this way because it is legitimate to type
tt(Ctrl-d) (end of input) immediately after starting the calculator. By
convention empty alternatives are provided with the comment `tt(// empty)'.

The second production rule (`tt(input line)') handles all nontrivial input. It
means em(after reading any number of lines, read one more line). The left
recursion turns this rule into a loop: it processes any number of lines.

The parser's parsing function continues to process input until a grammatical
error is encountered or untilthe lexical analyzer returns the end-of-file
token.