[antlr-interest] Trying to keep whitespace in an AST
Matt Benson
gudnabrsam at yahoo.com
Thu Feb 7 20:16:07 PST 2008
Are you trying to pretty-print all the source, or just
what you've augmented? Does this wiki entry approach
what you're looking for:
http://www.antlr.org/wiki/pages/viewpage.action?pageId=1752
?
-Matt
--- Jamie Penney <jpen054 at ec.auckland.ac.nz> wrote:
> Hi all,
> I am trying to work out how to create a grammar that
> will build an AST
> that keeps both comments and some whitespace.
> Basically the output will
> be formatted code, but we need the semantic
> information provided by the
> AST for other parts of the system. Any comments and
> blank lines need to
> be kept in the output code. Is it possible to have
> rewriting and AST
> generation turned on at the same time, or do I have
> to write two
> separate grammars? I am new to ANTLR so sorry if I
> have the wrong idea
> about anything.
> To give a concrete example, say I have a language
> that represents basic
> C style statements like so:
>
> int a = 0;
> int b = 1;
> int c = 2;
>
> // reassign a
> a = b + c;
>
> What I need is the semantic information provided by
> an AST (whether a
> statement is a declaration, assignment, ect), but I
> need to transform
> the language partially too. I need to format the
> individual elements
> consistently, so each would be of the form a = b +
> c; but I also need to
> retain the newlines and comments between elements.
>
> If anyone could point me in the right direction I
> would be very grateful.
>
> Thanks,
> Jamie Penney
>
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
More information about the antlr-interest
mailing list