ANTLR, C-styled macro definitions -
What is the easiest (or best) way to implement macro definition in ANTLR? I have a system similar to the one currently present in the C / C ++ language:
#Define FUNCTION (a, b) a + b #define PI 3.1415
How and when do I replace?
If you are doing a pre-processor in the style of C, then you have a pre-processing Want to pass the separate first pass (which means that - pass before processing your standard lex / parse pass)
How exactly is it up to you to pass - you can pass your input text to the entry in a gramer, take the result and hand to another grammar, etc.
Or you can create separate programs that are able to input stdin
and output to stdout
, or pass text between pipes, etc.
Once you've worked, check the simple case for each token of searching your keywords that you see against your table of #define
s, and If it matches, replace it with the definition you define. You need to be able to parse the function parameters, but you should not try more than this.
Comments
Post a Comment