The STYX system comes up with a macro preprocessing facility -
based on the following macro definition syntax and evaluation process
during the lexical analysis:
#include Path | supports modular grammar design
The macro will be replaced by the content of source file 'Path' and then rescanned. |
#macro Name ( Parameter , ... ) = Text #end | supports conditional parsing and text replacement
Parameter and replacement text definition is optional. The macro will be collected by the preprocessing module and skipped by the scanner. Each macro expression will be replaced according to the previously definition and then rescanned. |
' Delimiter | introduces another character as delimiter for the actual macro parameter
Spaces will be used as default delimiter. To reactive the default behaviour specify ' -. The scanner skips these token. |
#if[n]def Name IfPart #else ElsePart #end | supports conditional parsing
Dependant on the definition of macro 'Name' the scanner skips the 'ElsePart' or 'IfPart'. Its possible to introduce environment variables as macros. |
You can use this preprocessing facility if your regular grammar defines
the above kind of macros in the same way -
apart from token names and keywords.
( see below and styx reference )
Note: The preprocessing module is not reentrant.
Identifier for the ( macro ) token names
#define SPP_TOK_IDE 0 // Identifier #define SPP_TOK_MACDFN 1 // Macro #define SPP_TOK_MACSEP 2 // Delimiter #define SPP_TOK_MACINC 3 // Include #define SPP_TOK_MACCOND 4 // Condition
Identifier for macro token keywords
#define SPP_PAT_START 5 // #macro #define SPP_PAT_END 6 // #end #define SPP_PAT_IFDEF 7 // #ifdef #define SPP_PAT_IFNDEF 8 // #ifndef #define SPP_PAT_ELSE 9 // #else #define SPP_PAT_INC 10 // #include
Identifier for include path and character set
#define SPP_INC_PATH 11 #define SPP_INC_CHARSET 12
void SPP_init(MAP(long,symbol) pPreParMap) | initializes STYX-konform macro preprocessing 'pPreParMap': re-definitions for macro token names, initial macro token keywords, include path and characterset |
void SPP_addCtxMacro(symbol pMacNam) | adds 'pMacNam' as pre-defined macro |
void SPP_quit(void) | terminates STYX-konform macro preprocessing |
int SPP_premac ( Scn_Stream pStream, c_string cTokNam, c_string cTokVal, symbol* cMacVal ) | preprocesses current token of non-binary scan stream 'pStream' 'cTokNam': name of separated token 'cTokVal': value of separated token 'cMacVal': preprocessing result ( see [scn_base] ) ( cTokNam, cTokVal: single byte or utf-8 characterset ) |