Language text preprocessor
The preprocessor is a part of the language compiler, that is executed at the first phase of code compilation, which processes the input text data before the main compilation. The role of the preprocessor is to remove comments, apply macros, include subfiles of a source code and analyze various directives.
Comments
A comments are a regions in code, that are skipped by the compiler while reading the code.
Comments in Cind lanugage are like in C/C++ languages, that is,
there is a comment region from characters:
Directives
A directive is a kind of preprocessor's instruction, that is inserted into the code.
Each directive starts with hash character
A directive can be a macro definition, macro undefinition,
file inclusion, beginning of conditional section, etc
(for list of directives see below).
For example, those are 4 directives:
For more about expression used in conditional directive see Expression in preprocessor directives.
List of preprocessor directives
directive | arguments | description | example |
#define | MACRONAME CODE | defines macro | #define pi 3.141592654f |
#define | MACRONAME(x,y) CODE | defines macro with parameters | #define MAX(x,y) ((x>y)?x:y) |
#undef | MACRONAME | undefines macro | #undef pi |
#ifdef | MACRONAME | includes the followin region of code if the given macro is defined |
#ifdef ABC |
#ifndef | MACRONAME | includes the followin region of code if the given macro is not defined |
#ifndef ABC |
#if | (condition) | includes the followin region of code if the given condition is true |
#if (2+3 > 6) |
#else | starts alternative region of code | ||
#endif | ends conditional region of code | ||
#include | "file name" | includes code from the other file | #include "./mylibs/m2.cind" |
Macros
Macro is a set of characters, identified by name, that will be inserted into the code,
in the place of that name.
The preprocessor holds a list of macros and inserts them while processing the code.
To define macro use preprocessor's directive
For example, if macro named
Macro can also has parameters.
For example, applying macro
More examples:
To remove macros from preprocessor's list use
Conditional section
A conditional section consists of a piece of code, that can be included into the main code
depending on some conditional value.
That conditionally included piece of code should be placed between
For example:
When expression inside
For syntax of that expression see Expression in preprocessor directives.
An optional directive
Example:
A beginning directive for a conditional section can be one of:
A conditional sections can be placed recursively. Example:
Including files
An
Examples:
Sticking lines
The preprocessor stickes neighboring lines, when first of them ends with backslash character
Example:
gives:
Combining strings
The preprocessor also glues strings inside code, when they are side by side on the same line.
That may be useful to build string value containing some value from a macro.
Example: