How To Obtain Abstract Syntax Trees

XT -- A Bundle of Program Transformation Tools
Task

How to obtain abstract syntax trees

Description

Given a concrete term over some language L, an abstract syntax tree for that term is obtained by:

  1. generating a parse table from the grammar of L
  2. parsing the concrete term using this parse table
  3. imploding the parse tree to an abstract syntax tree
In order for the parse tree implosion to work properly, the grammar of L should be annotated with cons(...) attributes.

Examples

Assuming L.def is a grammar for L, and term.l is a concrete term over language L, an abstract syntax tree is obtained as follows: # sdf2table -i L.def -o L.tbl # sglr -p L.tbl -i term.l -o term.l.asfix # implode-asfix -i term.l.asfix -o term.l.ast

See also

implodeasfixGT, sglrSGLR, Sdf.Sdf2TablePGEN.