[antlr-interest] how to access rule attributes in a tree grammar in release 3.1

Gerard van de Glind g.vandeglind at beinformed.nl
Fri Aug 8 04:12:24 PDT 2008


Hi Mark, Johannes and all,

Thanks Mark that fixed most of my problems!
With the transition from 3.0 to 3.1 I lost that option somehow :-( My fault, sorry!

Regards, Gerard


Hi Gerard, Johannes,

It seems to work, maybe ASTLabelType=CommonTree might help.
Something like:

tree grammar mytreegrammar;
options {
   tokenVocab = mygrammar;
   ASTLabelType=CommonTree;
   output=template;
}

Regards, Mark

On Fri, 8 Aug 2008 12:43:39 +0200
Gerard van de Glind <g.vandeglind at beinformed.nl> wrote:

> Hi Johannes and all,
>
> That would mean that I have to cast everything in the code blocks of
> my grammar, right? (Drawbacks: I have to know to which class to cast
> and my grammar get's tied to the implementation of ANTLR).
>
> Or I have to adjust the generated Java code, which is even more ugly.
> Is there no other solution to access attributes in 3.1 (see also the
> little example that used to work)?
>
> Regards, Gerard
>
> PS Example (see text attribute):
>
> | ^(BOOLEAN_IDENTIFIER IDENTIFIER)
>         {
>         String strKey   = $IDENTIFIER.text;
>                 ...
>         }
>
>
> Gerard van de Glind schrieb:
> > Hey hello,
> >
> > I updated to the ANTLR 3.1b2 release to try it out for the upcoming
> > 3.1 release. Btw when will 3.1 be released, is that already known?
> >
> > It seems that quite a lot has changed since the 3.0 release. Also,
> > I get a lot of errors now when I generate Java code from my grammar.
> >
> > In the Changes.txt I read the following:
> >
> > match() returns Object matched now (parser, tree parser) so we can
> > set labels on token refs properly after single token ins/del error
> > recovery.
> >
> > And a close examination of the generated Java code reveals that many
> > things have now become a direct instance of class Object.
> >
> > However, this causes problems if I want to access the predefined
> > ANTLR attributes (see 6.4 of the Definitive ANTLR Reference).
> >
> > Is there a new notation to access these?
> >
> > Thanks a lot!
> >
> > Regards, Gerard
>
> Can't you simply downcast the Object to the correct type?
>
> Johannes


--


More information about the antlr-interest mailing list