[antlr-interest] DoubleLinkedTree

Alexander Gängel alexander at gaengel.de
Thu Mar 1 23:46:13 PST 2007


How can I tell Antlr to use my TreeAdapter I didn't find anything in the
wiki.

Alexander

David Holroyd schrieb:
> On Thu, Mar 01, 2007 at 05:07:38PM +0100, Alexander G?ngel wrote:
>   
>> Can anybody give me hint how to get DoublelinkTrees  to work?
>>     
>
> You have to tell the Parser to use a TreeAdapter implementation that
> you've created that can construct and manipulate the custom class that
> you've implemented.
>
> 'ASTLabelType' only controls the creation of local variable
> declarations, and typecasting in the generated parser code, I think.
>
> Sorry I've I've missunderstood, or you are already doing this.
>
>
>   
>> Alexander G?ngel schrieb:
>>     
>>> The exception comes when call the parser.Rule
>>>
>>> 19        CharStream input = new ANTLRFileStream(args[0]);
>>> 20        oclLexer lex = new oclLexer(input);
>>> 21        CommonTokenStream tokens = new CommonTokenStream(lex);
>>> 22
>>> 23        oclParser parser = new oclParser(tokens);
>>> 24        oclParser.start_return r = parser.start();
>>>
>>>
>>> Exception in thread "main" java.lang.ClassCastException:
>>> org.antlr.runtime.tree.CommonTree
>>>     at ocl_parser.oclParser.ocl(oclParser.java:186)
>>>     at ocl_parser.oclParser.start(oclParser.java:122)
>>>     at tests.ImBaumsuchen.main(ImBaumsuchen.java:24)
>>>
>>> (oclParser.java:122)
>>> 117        try {
>>> 118            // src/ocl_parser/ocl.g:102:9: ( ocl -> ^( OCL ocl ) )
>>> 119            // src/ocl_parser/ocl.g:102:9: ocl
>>> 120            {
>>> 121            pushFollow(FOLLOW_ocl_in_start193);
>>> 122            ocl1=ocl();
>>> 123            _fsp--;
>>> 124            if (failed) return retval;
>>> 125            if ( backtracking==0 ) list_ocl.add(ocl1.getTree());
>>>
>>> (oclParser.java:186)
>>> 182        try {
>>> 183            // src/ocl_parser/ocl.g:105:2: ( ( package_decl | context
>>> )+ )
>>> 184            // src/ocl_parser/ocl.g:105:2: ( package_decl | context )+
>>> 185            {
>>> 186            root_0 = (OclAst)adaptor.nil();
>>> 187
>>> 188            // src/ocl_parser/ocl.g:105:2: ( package_decl | context )+
>>> 189            int cnt1=0;
>>> 190            loop1:
>>> 191            do {
>>>
>>> I tried to make myAst extend DoublelinkTree or Commontree both with same
>>> effect
>>>
>>> when I use Commontree in my Grammar everything works fine.
>>>
>>> Alexander
>>>
>>> Terence Parr schrieb:
>>>   
>>>       
>>>> Where does it get the exception?  Is it for the UP and DOWN nodes?
>>>> Ter
>>>> On Feb 20, 2007, at 2:50 AM, Alexander G?ngel wrote:
>>>>
>>>>     
>>>>         
>>>>> Can Somebody give me a hint how to use DoubleLinkTrees.
>>>>>
>>>>> I tried it this way:
>>>>>
>>>>> I have
>>>>> ASTLabelType=MyAst; in my V3 Grammar
>>>>>
>>>>> I created a Class MyAst extends DoubleLinkTree
>>>>>
>>>>> I Implemented the Abstract functions from BaseTree like in CommonTree
>>>>>
>>>>> but when I try to use the Grammar I get Exception in thread "main"
>>>>> java.lang.ClassCastException: org.antlr.runtime.tree.CommonTree
>>>>>           
>
>   

-- 
Alexander Gängel
Hirschberger Allee 39
68526 Ladenburg

Tel. : +49 (6203) 936399
Handy: +49 (177) 7692314

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070302/36c0a112/attachment.html 


More information about the antlr-interest mailing list