| 1 |
The design process when using b(), from grammar specification |
| 2 |
to a working compiler or interpreter, consists of the following steps: |
| 3 |
itemization( |
| 4 |
it() First a grammar is apecified in a form recognized by b() (see |
| 5 |
chapter ref(GRAMMARFILES)). |
| 6 |
|
| 7 |
For each grammatical rule in the language, an action can be defined that |
| 8 |
is performed when a production rule has completely been recognized. The action |
| 9 |
is described using bf(C++) statements. |
| 10 |
it() Run b() on the grammar, producing the parser class and several of its |
| 11 |
member functions (among which the parsing member function `tt(parse)'). |
| 12 |
it() Design a lexical scanner to process input, passing tokens to the |
| 13 |
parser. The lexical scanner may be written by hand (see section ref(LEX)), but |
| 14 |
it can also be produced by, e.g., bf(flex)(1) (using bf(flex)(1) is not |
| 15 |
covered in this manual). |
| 16 |
it() All the parser's members (except for the member tt(parse()) and its |
| 17 |
support functions) 1must be implemented by the programmer. Commonly additional |
| 18 |
member functions are also be declared in the parser class' header. At the |
| 19 |
very least the member tt(int lex()), calling the lexecal scanner to produce |
| 20 |
the next available token, em(must) be implemented (although a standardized |
| 21 |
implementation can optionallu be generated by b()). The member tt(lex) is |
| 22 |
called by tt(parse's) support functions to obtain the next available |
| 23 |
token. The member function tt(void error(char const *msg)) may also be |
| 24 |
re-implemented by the programmer (a simple in-line implementation is |
| 25 |
provided by default). The member function tt(error) is called when |
| 26 |
tt(parse) encounters (syntactic) errors. |
| 27 |
it() The parser can now be used in a program. A simple example would |
| 28 |
be: |
| 29 |
verb( |
| 30 |
int main() |
| 31 |
{ |
| 32 |
Parser parser; |
| 33 |
return parser.parse(); |
| 34 |
} |
| 35 |
) |
| 36 |
) |
| 37 |
Once the program's source files are available, they must be compiled and |
| 38 |
linked togrether, producing the final program. |