[antlr-interest] Continuing problem with # directives

Anthony W Youngman Anthony.Youngman at ECA-International.com
Thu May 15 04:04:05 PDT 2003


I create a newline token called EOL, and then when my parser constructs
its tree it doesn't bother putting it in the tree. Would that work?

Or maybe a parser rule that recognises and dumps EOL.

Cheers,
Wol

-----Original Message-----
From: uprightness_of_character [mailto:andrei at metalanguage.com] 
Sent: 15 May 2003 01:02
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/ 

-------------- next part --------------
This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.


More information about the antlr-interest mailing list