Closed Mesabloo closed 3 years ago
Because of the way CPP works, it complicates the grammar quite a bit.
Basically, we would have to skip all lines starting with #
(if we were doing a tool CPP-alike), while still registering them (keeping the starting and ending positions, etc) and post-process them after parsing.
If we were to use CPP, we would most likely lose some of the positions in the source code, which is a bit worrying.
The target and macro alternatives (#37 and #38) are much easier to parse, and provide the same basic set of functionalities when combined with #40.
And because of all the problems that may arise from the user's environment (e.g. invalid or broken environment), I don't think it is worth tackling this problem.
CPP (the C PreProcessor) is used to transform some code into some other depending on the preprocessor directives in the processed code. It is possible, for example, to define macros, or do conditional compilation.
Macros (#38) and targets (#37) are some of the features that CPP can cover. It also is more general, allowing for
#error
ing out even before parsing the source code,#include
ing source files into others (using include guards with#ifndef
and#define
).While this should work, and provides a handful lot of features, there are several drawbacks:
We could consider using it, but we need to evaluate the cost of it first, checking whether we can preserve positions, so that the user does not get trash errors. Creating our own macro system may also yield better errors, for example allowing to report errors like "at line N: blablabla, coming from expansion of macro at line M: blablabla".