[antlr-interest] AST typecasting problem?

John D. Mitchell johnm-antlr at non.net
Tue Nov 9 17:11:25 PST 2004


>>>>> "Steve" == Steve  <stevegianvecchio at hotmail.com> writes:
[...]

> I created this file:

> public class BeliefAST extends antlr.CommonAST { List beliefList; }

> Then in a separated file:

> ...  AST t1 = parser.getAST(); BeliefAST t2 = (BeliefAST)t1;
> System.out.println("I don't get here.");

> At the second line, where the typecast takes place, my program exits
> immediately without any errors.  The following code works fine:

> ...  AST t1 = parser.getAST(); CommonAST t2 = (CommonAST)t1;
> System.out.println("I don't get here.");

> I can't think of what I'm doing wrong.  I tried replacing my BeliefAST
> file with CommonAST and just changing the text "CommonAST" to "BeliefAST"
> and got the same result.  I can't seem to figure out what is causing
> this, anyone have any ideas?

Did you actually hook your new AST/node class into the system so that it
actually gets used?

Check out the cgram/examples/Test.java file.  It uses a custom class called
TNode:
            parser.setASTNodeClass (TNode.class.getName());

Recall that the nodes are created through the astFactory and it has to know
the type of the node to create.

Hope this helps,
		John


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list