[antlr-interest] Using a different Tree class

Harald Mueller harald_m_mueller at gmx.de
Sat Dec 8 02:47:42 PST 2007


Hi - 

you must also change the AST node factory - see http://www.antlr.org/wiki/display/ANTLR3/Interfacing+AST+with+Java

ASTLabelType=XQFTTree only changes the *declarations* in the code generated by ANTLR, but not the *behavior* of the AST generation.

Regards
Harald

-------- Original-Nachricht --------
> Datum: Fri, 7 Dec 2007 20:13:51 +0100
> Von: "Andreas Ravnestad" <andreas.ravnestad at gmail.com>
> An: "Antlr Interest" <antlr-interest at antlr.org>
> Betreff: [antlr-interest] Using a different Tree class

> Hi!
> 
> How can I make Antlr use a different Tree class (not CommonTree)?
> 
> Currently I have this in the grammar:
> 
>   grammar XQFT;
>   options {
>       output=AST;
>       ASTLabelType=XQFTTree;
>   }
> 
> Where XQFTTree extends CommonTree. And then, this is the test program:
> 
>   XQFTParser.module_return result = parser.module();
>   XQFTTree tree = (XQFTTree)result.getTree();
> 
> And that will currently produce this error:
> 
> Exception in thread "main" java.lang.ClassCastException:
> org.antlr.runtime.tree.CommonTree cannot be cast to
> no.ntnu.xqft.parse.XQFTTree
>         at no.ntnu.xqft.parse.XQFTParser.module(Unknown Source)
>         at no.ntnu.xqft.test.TreeTest.execute(Unknown Source)
>         at no.ntnu.xqft.test.TreeTest.main(Unknown Source)
> 
> I'm sure I'm just missing a small detail here.
> 
> Thanks,
> Andreas

-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser


More information about the antlr-interest mailing list