| Imp |
Copyright (c) 1998-1999 Redshift
Software Inc. All Rights Reserved
|
6 |
The Preprocessor |
||
The IMP preprocessor converts a stream of character input into it into an output stream modified by preprocessor directives. All preprocessor directives begin with the # and may appear anywhere in the text stream. |
|||
6.1 |
Preprocessor Expressions |
||
The IMP preprocessor evaluates preprocessor expressions and inserts the result into the text stream. A preprocessor expression begins with #$ and is terminated by $#. For example, an already defined macro InitWindow could be invoked as follows;
|
|||
6.2 |
Preprocessor Statements |
||
The IMP preprocessor evaluates preprocessor statements and acts accordingly. A preprocessor statement begins with a # and any whitespace character and is terminated by any whitespace character and another #. Preprocessor statements and ordinary statements may be freely mixed and preprocessor expressions used to pass information to the preprocessor from ordinary statements. IMP preprocessor statements are largely identical to IMP statements. Macro statements are very similar to routines, but have some differences. |
|||
6.2.1 |
Macros |
||
A macro definition has three differences from a routine definition. First, a macro never has a return value, so a macro does not have a return variable list. Second, Macro parameters have no type information since they are textual items. Lastly, a macro definition may have a rest parameter as its final input. The rest paramenter is an array of any additional arguments given to the macro when it is invoked. For example, consider how we might define the InitWindow macro used above;
|
|||
6.2.2 |
Insert |
||
The IMP preprocessor can insert a file into the text stream by reading a string containing a filename. This provides a capability similar to C's #include. For example, a file named myfile could be read in as follows;
|
|||
6.3 |
Comments |
||
The IMP preproccesor removes comments from the text stream. A comment starts with the # and if the immediately following character is also a # runs until the end of the current line. Otherwise the comment runs until a corresponding character and a # is found. The grouping tokens form corresponding pairs, all other non whitespace characters correspond to themselves. Comments may nest as long as they use different characters after and before the #. |
|||
6.4 |
Escaping the # |
||
The IMP preprocessor will ignore any # immediately follow by a !. This allows the programmer to embed the # in ordinary text. This allows the programmer to use the preproccessor in situations where the hash may have some meaning by itself e.g. using the preprocessor to generate code for a language other than IMP. |
|||
Reference |
|||||||
|
|
1 Lexical |
2 Programs |
3 Declarations |
4 Expressions |
5 Statements |
6 Preprocessor |
7 EBNF |