[antlr-interest] ast or not...
Gavin Lambert
antlr at mirality.co.nz
Mon Dec 29 13:14:27 PST 2008
At 06:59 30/12/2008, Pady Srinivasan wrote:
>I am a beginner with antlr and dynamic languages. I am reading
>terence's antlr book. The language I am trying to develop is a
>simple if-elseif language and some actions based on that.
[...]
>So given this situation, would I need to be developing an
>ast/tree grammer etc ? For simple interpreted languages, is
>an ast/tree grammer etc really needed ?
You never *need* an AST and/or tree grammar, and using the former
does not imply you need to use the latter (though you can't use
the latter without the former). They're just options available
for use if they are more convenient or tidier than the
alternatives.
When I first started using ANTLR, I carried out all the actions in
the parser directly, since I found that simpler to work with and I
didn't have to worry about figuring out how ASTs and tree grammars
worked. Now that I'm more experienced with ANTLR, I tend to
favour using ASTs and tree grammars, mostly because it leaves the
parser grammar looking a bit tidier, and it opens up some
possibilities for doing tree manipulation to locate or rearrange
some constructs (which admittedly I haven't made much use of as
yet, but the theory sounds cool).
But basically: just use whatever you're most comfortable with.
More information about the antlr-interest
mailing list