[antlr-interest] AST to XML serialization.

Bharath Sundararaman bharath.sundararaman at starthis.com
Tue Nov 30 08:44:38 PST 2004


Hi all,

 

I am trying to convert my AST to XML format. I have my own AST class
which extends antlr.CommonAST and I used the following code from
http://www.antlr.org/doc/trees.html#AST%20Serialization in the ANTLR
reference manual:

 

MyAST t = (MyAST) parser.getAST( ); // MyAST extends CommonAST

Writer w = new OutputStreamWriter(System.out);
t.xmlSerialize(w);
w.write("\n");
w.flush();

 

My understanding is that this code should serialize the AST into XML and
print it on my console (System.out) but I get a NullPointerException of
this form:

 

parser exception: java.lang.NullPointerException

java.lang.NullPointerException

      at antlr.BaseAST.encode(BaseAST.java:401)

      at antlr.BaseAST.xmlSerializeRootOpen(BaseAST.java:454)

      at antlr.BaseAST.xmlSerialize(BaseAST.java:474)

 

 

Also, when I try to print my AST to the console,

System.out.println(t.toStringList( )); , it works just fine.

 

I guess it has to do with character encoding but I am not sure what the
exact problem is. Any thoughts/suggestions/comments are welcome.

 

Thanks in advance!



Bharath.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20041130/388c8e8f/attachment.html


More information about the antlr-interest mailing list