[antlr-interest] ANTLR Questions

Johannes Luber jaluber at gmx.de
Tue Jan 20 22:52:47 PST 2009


Bruno Marc-Aurele schrieb:
> Hello everyone,
> 
> I am currently working on a project where I need to translate files (mainly
> code) from one technology to another. I already have a LL(*) grammar for the
> source language and I am considering rewriting this grammar using ANTLR to
> benefit from C# generation target.
> 
> I have used JavaCC a lot in the past and I have some questions about ANTLR, a
> tool that I find really promising for my project. I read the documentation, but
> some things just still are unclear.
> 
> 1) If I want to generate a parse tree, do I HAVE to use a tree grammar or will a
> combined one work?

You create an AST via a parser grammar. A tree grammar parses only
created ASTs and may rewrite it, too.
> 
> 2) About the generated tree, what will be the types of the nodes? Will each rule
> have its type (ex, rule test would have a Test() type node) or are all the nodes
> the same type (NodeType, for example)?

Usually, the used class is BaseTree, but can be changed via a grammar
option. Heterogenous are also supported, but I have never used them, so
I can't answer the last question.

Johannes
> 
> 2.1) I read the section about heterogenous nodes (using the <X> syntax), but all
> the examples seem applied on token calls (ex: ID<V> and 'id'<V>). Does it work
> on rule calls (ex: rule<V>)?
> 
> Your answers might spark new questions from me, but for now it's all I need to
> know.
> 
> Thanks a lot for your support,
> Bruno Marc-Aurèle.
> 
> 
> 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 



More information about the antlr-interest mailing list