[antlr-interest] Building AST's for CSS2.1 with ANTLR

David Holroyd dave at badgers-in-foil.co.uk
Mon Oct 15 13:27:39 PDT 2007


On Mon, Oct 15, 2007 at 09:39:12AM -0400, Simon Janes wrote:
> You know, I tried that and for whatever reason, this still isn't
> working for me and I suspect its the weirdness of CSS--has anyone
> written a "best practice" for pulling AST's out of a parse tree with
> ANTLR 3.0.1?   I've been reading the ANTRv3.g and Cpp.g grammars to
> get some context.
> 
> * Do you always need to supply a token or literal token to be the
> "root" or "parent" of a AST tree/subtree?

No, you don't have to promote a node to the subtree root, but then
you're left with a flat list, which will probably look quite similar to
the original token stream from the lexer.  Creating the tree structure
is a way to keep a record of the syntactic structure that the parser has
discovered, making it easier to interrogate the AST from your application
code (or an ANTLR tree parser).

If you still have problems, post them to the list, and maybe someone can
help spot the problem (I hand-coded a CSS parser in Ruby a few years
back :)


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list