[antlr-interest] Re: C++ grammar

cppljevans jcampbell3 at prodigy.net
Thu Jun 13 11:31:06 PDT 2002

--- In antlr-interest at y..., Terence Parr <parrt at j...> wrote:
> Folks,
> A number of people are playing with a C++ front end for ANTLR
> from scratch or by converting old PCCTS grammar forward to ANTLR). 
> might be putting some effort behind making a standard C++ parser for 
> ANTLR and could use any head start people have.  So, who's been
> what? :)
I'm trying to convert Lilley's parser to a pretty printer for c++.
I'm planning on using c++, and might current focus is getting
the lexer to work.  The main problem is passing the "expanded"
tokens to the parser; yet, just printing the "unexpanded" tokens.
By "expanded" token, I mean the tokens that are the result of 
either #include <file> or processing a preprocessor macro.

I haven't coded anthing yet (except converting some of Lilley's
data structures to stl), but I'm thinking of merging some of
the ideas in http://www.antlr.org/doc/streams.html with 
Lilley's macro expansion methods ( see void
CPreParserImp::ExpandTokenList in cpre_expand.cpp).

To be more specific, I'm thinking of the lexer as a stack of
iterators, where each iterator corresponds either to a file or
a macro invocation.  The output tokens would only come from the
bottom of the stack, whereas the parser would always read from
the top.  Since the bottom corresponds to the original source file,
only tokens from the original source would be output.

For example, given the following code in test.cpp:

#define DECLB  int b
int a;
int c;

Then the lexer stack, just before the read of b, would contain:

    int b
    int a ; DECLB ; int c ;

Where each pair of lines above represents the state of an 
iterator on the stack.  The ^ points to the next token to
be read from the iterator.  The next token sent to the parser would
be that from the top iterator, i.e. the one pointing to
    int b
Then "unexpanded tokens are in those in the bottom iterator, or line.
I'm thinking that the comments would be accessed just like they
are in the above cited streams.html page.

I'd appreciate any feedback on this design.



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list