[antlr-interest] ANTLR Examples StdCParser.g

mzukowski at bco.com mzukowski at bco.com
Fri Nov 9 06:24:38 PST 2001


Both StdCParser and GnuCParser expect preprocessed input.

PreprocessorInfoChannel is for holding #line and #pragma directives so that
when the tree is emitted as code you can reconstruct the proper preprocessor
information.  The GCC preprocessor and compiler will generate nested
includes so that it can print a message that "a.h" included "b.h" included
"c.h" which has this error...

PreprocessorInfoChannel works in concert with the lexer which assigns every
non-SKIP token a unique monotonically increasing number.  Every preprocessor
directive that the lexer finds is associated with the token number that is
followed.  When emitting source code the PreprocessorInfoChannel keeps track
of what has already been given out, and you can ask for all of the
preprocessor directives which preceeded a particular line.  Note that this
strategy breaks down if your tree manipulation shuffles nodes in the tree.
If all you do is add new nodes or remove nodes than this strategy will work.

So, do you intend to emit C code that will be compiled?  If so you probably
want to preserve the #line directives so your compiler can report errors
properly.  If you have no use for #line or #pragma or any other
preprocessing directives then you don't need the PreprocessorInfoChannel.

Monty

> -----Original Message-----
> From: David Wigg [mailto:wiggjd at sbu.ac.uk]
> Sent: Friday, November 09, 2001 5:31 AM
> To: antlr-interest at yahoogroups.com; zjg1964 at yahoo.com
> Subject: [antlr-interest] ANTLR Examples StdCParser.g
> 
> 
> I am trying to convert the Java version of the StdCParser in the
> examples folder to run under C++ (only) (if successful, I 
> will make this
> available to the ANTLR community).
> 
> Where necessary, I am converting Java modules to C++.
> 
> I have done CToken and LineObject.
> 
> I am now wondering if I actually need 
> PreprocessorInfoChannel. There is
> a hint in main.java that it might only be needed for GnuParser.g. 
> 
> If this is so, can I delete all references to it in the C++ version?
> (since I am only converting for running under C++)
> 
> If I do need it in the C++ version please could someone let 
> me know what
> it does in general terms?
> 
> On second thoughts I am now wondering whether the current Java version
> of the StdCParser parses raw C++ source code (and therefore includes a
> pre-processing phase?) or whether it parses pre-processed .i files?
> (which is what we normally do with ANTLR 1.33).
> 
> If it does include a preprocessing phase, where is the code for this?
> 
> On the other hand I would really prefer to parse pre-processed code
> (which I mentioned above, is what we do now with 1.33) and then I
> wouldn't need a pre-processing phase.
> 
> Thanks for your help.
> 
> David
> Research Fellow
> South Bank University
> London, UK.
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/ 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20011109/1ddd788b/attachment.html


More information about the antlr-interest mailing list