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
|
The lexical scanner developed in this section is used to monitor the
production of a file from several subfiles. The setup is as follows: the
input-language defines tt(#include) directives, followed by a text
string specifying the file (path) which should be included at the location of
the tt(#include).
In order to avoid complexities irrelevant to the current example, the format
of the tt(#include) statement is restricted to the form tt(#include
<filepath>). The file specified between the angle brackets should be
available at the location indicated by tt(filepath). If the file is not
available, the program terminates after issuing an error message.
The program is started with one or two filename arguments. If the program is
started with just one filename argument, the output is written to the
standard output stream tt(cout). Otherwise, the output is written to
the stream whose name is given as the program's second argument.
The program defines a maximum i(nesting depth). Once this maximum is exceeded,
the program terminates after issuing an error message. In that case, the
filename stack indicating where which file was included is printed.
An additional feature of the program is that (standard bf(C++)) comment-lines
are ignored. Include-directives in comment-lines are also ignored.
The program is created in five major steps:
itemization(
it() First, the file tt(lexer) is constructed, containing the
input-language specifications.
it() From the specifications in tt(lexer) the requirements for the
tt(class Scanner) evolve. The tt(Scanner) class derives from the base class
ti(ScannerBase) generated by ti(flexc++).
it() Next, tt(main) is constructed. A tt(Scanner) object is created
inspecting the command-line arguments. If successful, the scanner's member
tt(lex) is called to produce the program's output.
it() Now that the global setup of the program has been specified,
the member functions of the various classes are implemented.
it() Finally, the program is compiled and linked.
)
|