[antlr-interest] serialization and IOStreams

Ric Klaren klaren at cs.utwente.nl
Mon Dec 9 06:08:48 PST 2002


Hi,

On Mon, Dec 09, 2002 at 12:52:09PM -0000, gurkowsky2000 <murat.oezcan at isis-papyrus.com> wrote:
> i am currently developing a small language in C++, where the parser
> is generated by antlr, and the commands are my classes which are
> based on the BaseAST. since these are small programs in a distributed
> environment, i need to get the generated trees serialized. is there
> anybody who did something like this and would be ready to share
> experiences with me?

> i must add, that i am trying to avoid altering the base classes which
> are delivered with antlr. this would make it difficult for me to keep
> with the newer versions of antlr. perhaps this could be included in
> the base classes as an extension? at least the operators "<<"
> and ">>" could be overriden- perhaps the easiest way of enabling a
> generic serialization (?)

There's some rough-ish stuff to write out trees in XML in the classes.
Compile with ANTLR_SUPPORT_XML defined then in your derived classes
override the toStream methods to customize your output.

operator<< works by calling the derived classes toStream methods (pretty
common way to do these kindoff things).

operator>> is a bit of a different problem. Think it's not possible to
implement reading in the sense of a operator>> since things have to got
through the ASTFactory to work in the most general heterogenous AST case.
Look at ASTFactory::LoadAST and friends. In practice the XML stuff mostly
works but it still needs work/docu for the general case. 

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  "You know how to use that thing?" [pointing to the sword]
  "Sure.. The pointy end goes into the other guy."
  --- The Mask of Zorro


 

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



More information about the antlr-interest mailing list