Debian Codegraph @

documentation/manual/concepts/output.yo

raw
1 When b() is run, it processes a grammar file. If the grammar is error-free b()
2 produces a bf(C++) em(class), in which several em(members) have already been
3 defined. Therefore, b()'s em(output) consists of em(header files) and a
4 bf(C++) source file, defining a member (tt(parse)) that parses the language
5 described by the grammar. The class and its implementation is called a b()
6 em(parser class). Keep in mind that the b() utility and the produced parser
7 classes are distinct pieces of software: the b() utility is a program whose
8 output is the b() parser class that is used by your program.
9
10 More specifically, b() generates the following files from a b()
11 grammar file:
12 itemization(
13 it() A em(baseclass header), which can be included by em(lexical scanners)
14 (see below), primarily defining the em(lexical tokens) that the parser expects
15 the lexical scanner to return;
16 it() A em(class header), defining the b() parser class interface;
17 it() An em(implementation header), which is used to declare all entities
18 which are em(only) used by b()'s parser class em(implementation) (and not
19 required by the remaining parts of your program);
20 it() The em(parsing member), actually performing the parsing of a
21 provided input according to the rules of the defined b() grammar (that
22 you, as b()'s user, defined).
23 )
24
25 The task of b()'s tt(parse) member is to group tokens according to rules
26 defined in the grammar -- for example, to combine identifiers and operators
27 into expressions. As it does this, it executes the actions of the grammar
28 rules it has recognized.
29
30 The tokens processed by the parser produced by b() are made available by an
31 object called the em(lexical analyzer) or em(lexical scanner). The scanner is
32 not produced by b(), but must somehow be supplied (e.g., by writing it
33 yourself). The tt(parse) member requests the next token from the lexical
34 analyzer whenever it needs another token. The parser itself doesn't know the
35 semantic values of the received tokens. Typically the lexical scanner produces
36 tokens by parsing the characters of the program's input text. This, however,
37 is not something that b() concerns itself with. See also section ref(LEX).
38
39 B()'s parsing function is a member function named tt(parse). This parsing
40 function nor the parser object for which it is called defines a complete
41 bf(C++) program: you must supply some additional details. One `detail' to be
42 supplied is is the lexical analyzer. The parser class itself declares several
43 additional members which can easily be redefined to fit your needs. One of
44 these additional members is the error-reporting function called by tt(parse)
45 to report errors. By default b() provides simple, but sensible,
46 implementations for such members.
47
48 Having constructed a parser class and a lexical scanner class, em(objects) of
49 those classes must be defined in a complete bf(C++) program. Usually such
50 objects are defined in tt(main); you have to provide this function, and
51 arrange for it to call the parser's tt(parse) function, lest the parser never
52 run. See chapter ref(INTERFACE).
53
54 Note that, different from conventions used by Bison and Bison++, b() does not
55 impose a particular name convention. In particular, there is em(no) need to
56 begin all variable and function names used in the b() parser with `yy' or
57 `YY'. However, some name restrictions on symbolic tokens exist. See section
58 ref(IMPROPER) for details.