[antlr-interest] grammars, tree grammars and parse trees, Oh my!

Naim Kingston naim.kingston at gmail.com
Tue Mar 10 05:40:19 PDT 2009


I've been going through the antlr wiki and FAQ for a couple of days now and
I'm having some problems in understanding exactly what I need to do if I
want to create a parse tree.
I'm not sure if our (mine and yours) definitions of a parse tree are the
same, but with boost::spirit in C++, I've been implementing a small
scripting language, and I've gotten very used to having a tree that I can
traverse, with each node describing what grammar rule it represents, and
only some of the nodes (integers, operators and other grammar rules that
correspond directly to input) have text associated with the tree node.

This is the kind of thing that I'm looking at doing in C# for a smaller
calculator-like side project. I'm generating a parser and lexer for my
language using antlr 3.1.2. Is a 'parse tree' the structure I'm looking for?

I've been generating an AST, but that just has the token type in each node,
and that won't always help in understanding the context of the token.

I've been looking at creating a tree grammar, but are the 'actions' that you
define simply the code that you insert in the tree node definitions? In
fact, are the rules in a tree grammar the content of each of the nodes in
the tree? If I'm not planning on re-ordering anything, or putting in any
actions (I want to do most things code-side apart from the parse tree
construction) do I need to create the tree grammar, or can I just use the
normal grammar I wrote?

Any help you guys can give in helping me understand antlr and how to use it
would be great. I can see it being a very useful tool for me in the future,
but I need to get over the hump of not knowing how to use it :D

-Naim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090310/f0a462d4/attachment.html 


More information about the antlr-interest mailing list