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
|
The input file for b() is a grammar file. Different from Bison++ and Bison
grammar files, b() grammar file consist of just two sections. The general form
of a b() grammar file looks like this:
verb(
Bisonc++ directives
%%
Grammar rules
)
Readers familiar with Bison may note that there is no em(C declaration
section) and no section to define em(Additional C code). With b() these
sections are superfluous since, due to the fact that a b() parser is defined
as a bf(C++) class, all additional code required for the parser's
implementation can be incorporated into the parser class itself. Also, bf(C++)
classes normally only require declarations that can be defined in the classes'
header files, so also the `additional C code' section was omitted from
b()'s grammar file.
The `%%' is a separator that appears in every b() grammar file
separating the two sections.
The directives section is used to declare the names of the terminal and
nonterminal symbols, and may also describe operator precedence and the data
types of semantic values of various symbols. Additional directives are used to
define, e.g., the name of the generated parser class and a namespace in which
the parser class is defined. All b() directives are covered in section
ref(DIRECTIVES).
Grammar rules define how to construct em(nonterminal symbols). The grammar
rules section defines one or more b() grammar rules. See
section ref(RULES), covering the syntax of grammar rules.
The `%%' separator must always be specified, even if the directives section is
empty.
B()'s grammar file may be split into several files. Each file may be given a
suggestive name. This allows quick identification of where a particular
section or rule is found, and improves readability of the designed
grammar. The link(%include)(INCLUDE)-directive (see section ref(INCLUDE)) can
be used to include a partial grammar specification file into another
specification file.
|