[antlr-interest] Serialization of ANTLR tree

Jim Idle jimi at temporal-wave.com
Thu Mar 18 09:06:35 PDT 2010


Are you sure that you have defined the correct requirement here? You parse the source text and create tokens and the tree (which all reference back in to the original source text), then you are going to send a text representation of the tree over the wire and re-assemble it. Just send the original source text and parse it in to the AST at the receiving end.

You can certainly produce a text representation of the AST, but in order not to lose information, the format would quite likely end up being larger than the original input. So my answer would be "Doctor doctor, I broke my arm in 3 places! Don't go to those 3 places again!" ;-)

Jim



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Rune Glerup
> Sent: Thursday, March 18, 2010 8:55 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Serialization of ANTLR tree
> 
> We have a small language implemented with ANTLR 3.2.
> 
> We need to transmit a tree through RMI and therefore the tree
> needs to be serializable. I am very curious to learn what the
> best approach to serializing an ANTLR tree is.
> 
> I have noticed that BaseTree or CommonTree are does not
> implement Serializable, while, in ANTLR2, BaseAST does implement
> Serializable. - What is the rationale behind this?
> 
> - Is it "better" (in terms of performance and robustness) to:
>   (a) rely on the default Java serialization mechanism that uses
>       the internal representation of the AST nodes to serialize
>       the AST, or
>   (b) serialize to a text format and then use an ANTLR parser to
>       parse that format upon deserialization, or
>   (c) something clever I haven't thought of?
> 
> Thanks! :)
> 
> --
> Rune Glerup
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list