views:

274

answers:

2

Is there any (E)BNF parser out there which is able to generate XML trees of the AST?

Rephrasing: what is the quickest way to compile an (E)BNF defined language into some sort of XML?

Bonus: Using Javascript :-)

A: 

Not free, but generates XML: DMS Software Reengineering Toolkit. Available with a variety of predefined langauge defintions (C, C++, C#, Java, COBOL, Javascript, XML, ...).

The question is, what will you do with that? If you are processing some langauge seriously, you need much more than just the AST (almost always you need a symbol table).

Ira Baxter
The problem is that I'm trying to interoperate with a system which has an XML DSL, with lots of redundancies, and barely human readable. I assume if I can get a XML AST, a XSLT will solve my problem (though I didn't thought about the symbol table :-\)
Hugo S Ferreira
The point of a DSL is to make it readable for people. I almost want to cry when I hear people say "DSL" and "XML" in the same breath. The point of parsers is to read what people write, and make it into something the machine can process. XML DSLs are shorthand for "I'm too lazy to write a parser".
Ira Baxter
You misunderstood my point. The DSL is not XML, but the Interpretation Engine only accepts XML. I'm trying to make a human-readable DSL which, after compilation, outputs a verbose XML that the engine can read.
Hugo S Ferreira
OK, yes I misunderstood. The phrase "XML DSL" seemed like pretty deadly evidence, sorry. So... there's an existing interpreter that accepts XML? It must accept a *specific* XML DTD in which the tags mean something, or it won't know what to do. So what you need is not a parser for your DSL that produces an XML parse tree, but one that produces something the existing XML interpretation engine can interpret. You need a translator, not a parser, and that's a LOT harder, because it may require an arbitrary map between your DSL semantics and the existing interpretation engine.
Ira Baxter
True! I've taken for granted that a XSLT would do the trick in the end, but it revealed far more intricate than what I expected. I ended using AntLR and the StringTemplate for this, with a lot of logic intertwined in the grammar.
Hugo S Ferreira
+1  A: 

It seems my best bet so far is to use AntLR and the StringTemplate Interface. It also supports a JavaScript target.

Hugo S Ferreira