![]() |
![]() |
![]() |
General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
![]() ![]() |
![]() |
Tasks related to input processingInsert a File into the Input Stream
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 $/Input/Include.gnrc:inst The module provides the following function:
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 include "myfile"; wherever a Declaration is
allowed.
The following 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 FileName
token. The computation has to executed while the input is read and the tree
is built bottom-up. Hence it is specified BOTTOMUP .
Note: The above computation is executed when the Declaration: 'include' FileName ';'.instead would delay insertion until the token following that ;
has been read.
|