[antlr-interest] how to create an AST?

Dennis Benzinger Dennis.Benzinger at gmx.net
Tue Sep 9 00:51:15 PDT 2008


Hi!

Am 08.09.2008 22:24, Potje rode kool schrieb:
> Hi,
> 
> I am playing now for some time with antlr and I am trying to build an AST
> but that seems to be quit hard.
> 
> I am try to parse a package declaration like this:
> 
> package org.something.more;
> 
> Seems that I have to use two .g files.
> One that creates CommonTree objects and the other one to build an AST from
> that.
> 
> Anyone knows how to get the stuff working?
> [...]

You don't need two grammars. You can use one grammar like the example
I've attached. The ID rule is not the correct rule for Java but you'll
get the idea.

Have a look at:
http://www.antlr.org/wiki/display/ANTLR3/FAQ+-+Tree+construction


HTH,
Dennis Benzinger


More information about the antlr-interest mailing list