[antlr-interest] ANTLR Questions

Bruno Marc-Aurele bruno.marc-aurele at polymtl.ca
Wed Jan 21 04:55:06 PST 2009


Thanks a lot Johannes.

Has anyone used heterogenous trees? I would like to know how customisable my AST
can be... I will rewrite my question concerning this so you don't need to look
for it in the previous messages:

Q: 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>)?

Another question pops for me: can I define new attributes for a node in semantic
actions? For example, if I write the following rule:

rule: ID subrule {$subrule.newAttribute = 1;} INT;

... will my node object have a "newAttribute" property (C# target) when
generated?

Thanks a lot,
Bruno M-A.
--
Bruno Marc-Aurèle
courriel Poly: bruno.marc-aurele at polymtl.ca
courriel perso: bruno.m-a at hotmail.com


Selon Johannes Luber <jaluber at gmx.de>:

> 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