4

I am building an XML serializer of JavaScript Abstract Syntax Trees with ANTLR. The generator is quite complete but I would like to know if there are any conventions about some issues such as:

  • how handle angle brackets in strings or regular expressions?
  • how to translate if-then-else (e.g. will the else node be inside the if one or not)?

More generally: does such a translator already exist? Is there any existing XSD for this XML-based language?

EDIT

I am currently interested in free tools only.

Federico Bellucci
  • 623
  • 2
  • 7
  • 26
  • I don't understand "quite complete ... but how to handle if-then-else" in the same breath. If you have the AST, exporting an XML version of it is pretty trivial: walk the AST, spit out node and children descriptors. If you do that, your question about "how to handle if-then-else" vanishes, as you must have already solved it in building the AST. – Ira Baxter Jul 21 '11 at 18:49
  • You ask, "does such a translator exist?". If the question is, "does this exist in ANTLR?" then I suspect you'll find the answer at the ANTLR.org site. My company has exactly such a translator with all the issues resolved; if you'd like to see an output sample as an answer here I'll produce one for you specifically for JavaScript. Here's a link to an XML output for Java: http://stackoverflow.com/questions/6376662/how-a-ast-for-an-object-oriented-programming-language-would-look-like/6378997#6378997 – Ira Baxter Jul 21 '11 at 18:59
  • "Quite complete" = the translator actually produces XML code from JavaScript but I would like to know some state-of-the-art similar work to make a comparison about its quality. The if-then-else issue was just an example and my question stressed about _conventions_: should I translate it in or in or in ... – Federico Bellucci Jul 22 '11 at 08:43
  • 1
    "Conventions"? The simplest conventions are best. Produce XML that matches the shape of the AST you have. I'd expect an tag with 3 children. – Ira Baxter Jul 22 '11 at 13:49

1 Answers1

0

Parsers which perform code generation from XML and generate XML from code are readily available:

You ask, "does such a translator exist?". If the question is, "does this exist in ANTLR?" then I suspect you'll find the answer at the ANTLR.org site. My company has exactly such a translator with all the issues resolved; if you'd like to see an output sample as an answer here I'll produce one for you specifically for JavaScript.

Here's a link to an XML output for Java: What would an AST (abstract syntax tree) for an object-oriented programming language look like?

References

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265