AST to XML in MPS

  • 31
  • 5

Hello,
I want to translate some language (like Pascal or C) into XML. Something like: <for from="0" to="10"><if ...></for>... I see some approaches for this, but they are language-specific. Is MPS general solution of this problem. And how can I do this using MPS?
Hello, Mikhail

I think, the most general solution is the model format:
...
  <node role="statement" type="ForStatement" etc...
...

Otherwise, sure it depends on the current language.

I want to implement xslt post-processing, so in my case format is not significant, the main purpose is to save all information about code in xml format. Is MPS the right choice for me? or plain ANTLR - is better?

I'm not sure that xslt is the best technique for C code modification. It's nice for xml transformation;)

Are you going to serialize the transformed xml back to the C code? If so, why don't you use the MPS' smodel language to modify the C language model without those intermediate transformations to xml and back?

The aim is to translate some code(really not only C) to some other language. The part which reads xml and writes code of target language is done. Now I need to get XML from code. As I understand MPS is not the appropriate tool for it. Am I right? Do you know some tools like srcML(http://www.sdml.info/projects/srcml/) written in java?

I think, MPS is not the best way to do this. As all you want is an AST written as XML file, maybe it would be better to use some parser-generators. As far as I remember, even the Lex+YACC is able to construct the AST, so, I think, all parser-generators are. Just convert it to XML structure while constructing - and you get what's required.

Regards,
Mihail