File: formal.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 (34 lines) | stat: -rw-r--r-- 1,691 bytes parent folder | download | duplicates (10)
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
A formal grammar is a mathematical construct. To define the language for
B(), you must write a file expressing the grammar in b() syntax: a
em(B() grammar file). See chapter ref(GRAMMARFILES).

A nonterminal symbol in the formal grammar is represented in b() input as
an identifier, like an identifier in bf(C++). By convention, it should be in
lower case, such as tt(expr), tt(stmt) or tt(declaration). 

The b() representation for a terminal symbol is also called a token
type. Token types as well can be represented as bf(C++)-like identifiers. By
convention, these identifiers should be upper case to distinguish them from
nonterminals: for example, tt(INTEGER), tt(IDENTIFIER), tt(IF) or
tt(RETURN). A terminal symbol that stands for a particular keyword in the
language should be named after that keyword converted to upper case. The
terminal symbol tt(error) is reserved for error recovery. See section 
ref(SYMBOLS), which also describes the current restrictions on the names of
terminal symbols.

A terminal symbol can also be represented as a character literal, just like a
bf(C++) character constant. You should do this whenever a token is just a
single character (parenthesis, plus-sign, etc.): use that same character in a
literal as the terminal symbol for that token.

The grammar rules also have an expression in b() syntax. For example, here is
the b() rule for a bf(C++) return statement. The semicolon in quotes is a
literal character token, representing part of the bf(C++) syntax for the
statement; the naked semicolon, and the colon, are b() punctuation used in
every rule.
        verb(
    stmt:   
        RETURN expr ';'
    ;
        )
    See section ref(RULES).