[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 03:43:39 PDT 2008


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