[antlr-interest] Problem with wrapper program

Terence Parr parrt at cs.usfca.edu
Fri Jul 7 10:07:38 PDT 2006


On Jul 7, 2006, at 7:19 AM, Amrinder Singh wrote:

> Hello,
>
> I was trying to develop a parser based on the Mantra design. I  
> wrote a wrapper
> program similar to Tool.java to run the parser. When I try to run a  
> sample
> input on it, it gives a ClassCastException when a tree is  
> constructed on the
> line root_0 = (MyAST) adaptor.nil();
> However, Mantra does not encounter this error even though it has  
> the same line
> in its code. Any idea what could be causing it? If required I could  
> send my
> grammar file.

Hi.  Did you see

     // Custom adaptor to create MantraAST node type
     static final TreeAdaptor adaptor = new CommonTreeAdaptor() {
         public Object create(Token payload) {
             return new MantraAST(payload);
         }
     };

at the top and then:

         Mantra g = new Mantra(tokens,symtab);
         g.setTreeAdaptor(adaptor);

to tell ANTLR which nodes to create?

Ter


More information about the antlr-interest mailing list