[antlr-interest] Inheritance of BaseAST class
FC
tangfc2001 at yahoo.com
Mon Mar 14 21:37:44 PST 2005
I am now working on transforming the AST parsed on
java code to xml file. I use the example of java
parser in Antlr-2.7.3 package as follows.
//JavaRecognizer is a subclass of class
//antlr.LLkParser
JavaLexer lexer = new JavaLexer(r);
lexer.setFilename(f);
JavaRecognizer parser = new JavaRecognizer(lexer);
parser.setFilename(f);
parser.compilationUnit();
//JavaAST is extended from BaseAST, and the XML
//serialization methods in BaseAST are overriden
JavaAST t = (JavaAST)parser.getAST();
Writer w = new OutputStreamWriter(System.out);
t.xmlSerialize(w);
w.write("\n");
w.flush();
But there is run-time error:
parser exception: java.lang.ClassCastException at line
of "JavaAST t = (JavaAST)parser.getAST();", that is,
the AST object can not be casted to my subclass
JavaAST. How can I solve this problem?
thanks
Ted
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
More information about the antlr-interest
mailing list