[antlr-interest] Continuing problem with # directives
mzukowski at yci.com
mzukowski at yci.com
Thu May 15 08:36:09 PDT 2003
You might also consider handling the preprocessor directives in the lexer
via lexer states. That would let you enforce that it is followed by an
end-of-line.
Monty
-----Original Message-----
From: uprightness_of_character [mailto:andrei at metalanguage.com]
Sent: Wednesday, May 14, 2003 5:02 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Continuing problem with # directives
Ok, so now I have a solution for detecting '#' as the start of a
directive in C. Now I wrote the following grammar rule for the parser:
hash_directive
:
HASH_DIRECTIVE_BEGIN
"include"
(
STRING
| LESS ( ~GREATER )+ GREATER
)
;
This will nicely match #include "a" or #include <iostream>. Cool. But
now I need to enforce that the directive ends with some trailing
spaces and a newline. Otherwise, my parser will consider the following
construct legal:
#include "a" void foo() {}
But the problem is, my NEWLINE rule sets the token type to SKIP, so I
can't detect it in the parser. Any good solution for that? Thanks!
Andrei
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list