Automatically generating ASTs with XML markup

Manuel Collado <mcollado@fi.upm.es>
29 Dec 2004 01:46:07 -0500

          From comp.compilers

Related articles
Automatically generating ASTs with XML markup mcollado@fi.upm.es (Manuel Collado) (2004-12-29)
Re: Automatically generating ASTs with XML markup dido@imperium.ph (Rafael 'Dido' Sevilla) (2004-12-30)
Re: Automatically generating ASTs with XML markup Juergen.Kahrs@vr-web.de (=?ISO-8859-1?Q?J=FCrgen_Kahrs?=) (2004-12-30)
Re: Automatically generating ASTs with XML markup demakov@ispras.ru (Alexey Demakov) (2004-12-30)
Re: Automatically generating ASTs with XML markup jones@cs.ua.edu (Joel Jones) (2004-12-30)
| List of all articles for this month |

From: Manuel Collado <mcollado@fi.upm.es>
Newsgroups: comp.compilers
Date: 29 Dec 2004 01:46:07 -0500
Organization: Compilers Central
Keywords: parse, question
Posted-Date: 29 Dec 2004 01:46:07 EST

I'm trying to grab the abstract syntax of several code samples in
several different languages by using an XML representation. Example
(Modula-2):


From


      MODULE Hello;
      IMPORT InOut;
      BEGIN
            InOut.WriteString("Hello, world");
            InOut.WriteLn;
      END Hello.


get something like


      <program>
          <name>Hello</name>
          <import>
              <name>InOut</name>
          </import>
          <body>
              <call>
                  <name>InOut.WriteString</name>
                  <expression>"Hello, world"</expression>
              </call>
              <call>
                  <name>InOut.WriteLn</name>
              </call>
          </body>
      </program>


Perhaps this could be done by an automatic tool just by writing the
appropriate grammar (EBNF or similar):


      <program> ::= MODULE <name>; <import>* <declaration>* <body>
      <import> ::= IMPORT <name>;
      <body> ::= BEGIN (<assign>|<call>|<if>|...)* END <name> .
      <call> ::= <name> [ "(" <expression>, <expression>* ")" ]
      ...


Does anybody know such an automatic tool?


Of course, there are a lot of parser/compiler generators:
- yacc/lex
- bison/flex
- antlr
- asf+sdf
- coco/r
- javacc
- jjforester
- codeworker
- goldparser
- adagoop
- front/doggy
- elkhound
- etc. ...


I've attempted to use some of them, but it seems they require writing
specific AST printing code, in addition to the grammar. I wonder it the
whole process could be automated by just writing the grammar.


Thanks in advance.
--
------------------------------------------------------------------------
Manuel Collado Machuca | Facultad de Informatica UPM
Universidad Politecnica de Madrid | Campus de Montegancedo
Dep. LSIIS | Boadilla del Monte
Tel.+34-91-336.74.57 Fax.+34-91-336.74.12 | 28660 MADRID - SPAIN


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.