AST to XML

38 views
Skip to first unread message

Michael Mast

unread,
Feb 14, 2013, 8:37:39 PM2/14/13
to sab...@googlegroups.com

Hi.  I would like to persist the AST as XML.  I  was thinking of (manually) translating my AST grammar to an XSD that maps the individual ASTs to their respective XML elements and then using JAXB to generate the Java objects.  Then, while walking the AST, I could instantiate the JAXB object that corresponds to the particular AST node.  Once I’ve basically recreated the AST with JAXB objects, I can have JAXB stream the objects to XML.  Also, with the AST represented as JAXB objects, I could perform XSL translations against the representation of the AST.

 

What’s the best way to do this?  I was thinking maybe of tweaking the .txt template files within the SableCC jar such that the generated AST classes are JAXB classes.  Then, instead of walking the generated AST I could just “tell” the AST to stream itself into XML.

 

What do you think?

 

Thanks,

 

Mike.

 

 

Gonzalo Ortiz Jaureguizar

unread,
Feb 15, 2013, 4:33:51 AM2/15/13
to sab...@googlegroups.com
I usually store ASTs (and any other graph of objects) with XStream (http://xstream.codehaus.org/). I don't kown if you want to use JAXB for some special reason, but if don't, I think is better to use a generic system.


2013/2/15 Michael Mast <mbm...@pacbell.net>

--
-- You received this message because you are subscribed to the SableCC group. To post to this group, send email to sab...@googlegroups.com. To unsubscribe from this group, send email to sablecc+u...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/sablecc?hl=en
---
You received this message because you are subscribed to the Google Groups "SableCC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sablecc+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

peter lavalle

unread,
Feb 15, 2013, 5:37:59 AM2/15/13
to sab...@googlegroups.com
My Two Cents; (as a lurker)
So you're planning;
    sablecc:CST -> sablecc:AST -> jaxb:AST

(1)
I'd skip SableCC's CST -> AST transformation, your XSD is already emitting a "generic" AST structure, so why not construct that yourself?
 
(2)
If using sableCC's AST is required (for your coursework?) or easy (for you) I'd have SableCC and JAXB emit identically named classes (in different packages) and use java's reflection to copy one to the other

Michael Mast

unread,
Feb 16, 2013, 12:09:57 PM2/16/13
to sab...@googlegroups.com

Wow… I must’ve been living under a rock or something.  XStream looks great.  Thanks.

Reply all
Reply to author
Forward
0 new messages