[antlr-interest] Continuing problem with # directives

uprightness_of_character andrei at metalanguage.com
Wed May 14 17:01:42 PDT 2003


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/ 




More information about the antlr-interest mailing list