[antlr-interest] How to intersperse #line directives into expressions and statements?

Stephen Siegel siegel at udel.edu
Tue May 29 05:26:56 PDT 2012


I'm working on an ANTLR-based C preprocessor/parser/tree.   All in Java.  It keeps track of the origin of every token (in addition to file, line number, and character index, the history of the token through macro expansions and #include directives).   This information will all be accessible through the AST.  At this point, the preprocessor is basically working.  If you or anyone else is interested in checking it out or contributing to its development, drop me a line.
-Steve


On May 29, 2012, at 2:06 AM, pragmaik wrote:

> Hi! 
> 
> I am trying to parse #line directives within expressions and statements, so
> I can tag the nodes in the AST with the line numbers in the #line
> directives. For example 
> 
> #line 10 
> if ( 
> #line 20 
> x 
> #line 30 
>> 
> #line 40 
> 0 
> ) 
> 
> would lead to an AST where the 'if' node is tagged with 10 and the 'x' node
> is tagged with 20. 
> 
> First, I thought about writing a preprocessor, but this won't help, I think,
> because the preprocessor has nothing to do with the AST. Adding this
> behavior to the grammar isn't easy either, because the grammar had to accept
> '#line INTLITERAL' nearly everywhere. 
> 
> Did anybody solve a similar problem and could offer any help? 
> 
> Cheers, 
> Maik 
> 
> --
> View this message in context: http://antlr.1301665.n2.nabble.com/How-to-intersperse-line-directives-into-expressions-and-statements-tp7578122.html
> Sent from the ANTLR mailing list archive at Nabble.com.
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list