General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Tasks related to input processingInsert a File into the Input Text
Some processors need to insert the content of an arbitrary file at
a specific point in the input text currently being processed.
For example, consider the C preprocessor $/Input/Include.gnrc :instThe Include module exports the token processor InclDirective
(see Token Processors of Lexical analysis specification),
allowing the developer to implement a file inclusion
command as a lexical token
(see Lexical analysis specification).
To implement the $#include\040+\" (auxEOL) [InclDirective]This scanner specification begins with the regular expression #include\040+\" , which matches the beginning of the command
(see Regular Expressions of Lexical analysis specification).
This regular expression requires at least one space to follow the
word include , but allows more spaces to precede the string
giving the file name.
The last character of the regular expression is the delimiter of the file
name string.
The auxiliary scanner
The token processor
Given the above assumption,
Finally, Recall that the lexical token was specified as: $#include\040+\" (auxEOL) [InclDirective]This specification identifies the lexical token as a comment rather than a basic symbol (see Lexical analysis specification). Because it is a comment, it can be used wherever a comment is allowed in the source text. It may be that the developer wishes to restrict file insertion to specific grammatical constructs. In that case, the lexical token should be identified as a basic symbol by giving it a name: Insertion: $#include\040+\" (auxEOL) [InclDirective]The basic symbol name Insertion can then be used in the grammar just
as any basic symbol name.
Incorrectly-placed insertion points will be reported as syntax
errors, but the contents of the files specified by the insertion
commands will still be inserted at the specified points.
|