Tasks related to input processing
This module supports generating processors that include the contents
of a file into the currently read input stream. The effect is the same
as that known from the preprocessor
Such facilities are used, for example, in some systems for functional or logical languages, where commands like
use ["myfile"]cause the inclusion of the given file at the place of the use command.
The file is included at the current position of the input stream
when that computation is executed. That computation can either
be specified within the concrete grammar to be initiated by the
parser. Or it can be specified in a
This module is instantiated without generic parameters by
This facility is demonstrated by inserting a construct into our running example that allows to comprise sets of declarations on separate files and include them in the program text. Such declaration files may be used to specify common interfaces.
The file inclusion construct is introduced by the concrete productions
Declaration: FileInclusion ';'. FileInclusion: 'include' FileName.
We add a scanner specification for the terminal symbol
FileName: C_STRING_LIT [c_mkstr]Hence, an input program may contain file inclusion commands like
ATTR InpFileEx: int; RULE: FileInclusion ::= 'include' FileName COMPUTE .InpFileEx = NewInput (StringTable (FileName)) BOTTOMUP; IF (NOT (.InpFileEx), message (ERROR, CatStrInd ("can not open file ", FileName), 0, COORDREF)); END;The file name is specified to be the text of the
Note: The above computation is executed when the
Declaration: 'include' FileName ';'.instead would delay insertion until the token following that