How To Set Up AStratego Package

Stratego -- Strategies for Program Transformation
[under construction -- EelcoVisser - 16 May 2003]

A full fledged Stratego application does more than transform an ATerm into another ATerm. To transform programs it is necessary to parse the input program, turn the parse tree into a an abstract syntax tree, apply several transformations, and pretty print? the output program. These separate operations should also be glued together into a complete transformation system. The StrategoXT tools support the creation and composition of components for all aspects of transformation systems. Since the tool set is very flexible and programmable, there are many possibilities for using it.

This page provides a guideline for setting up a typical Stratego application. The application is developed as a package under the control of AutoMake? and AutoConf? using the AutoXT abstractions developed for StrategoXT.

As an example we examine the prolog-tools package, which provides basic support for transforming Prolog programs.

Structure of the Package

A source-to-source transformation system consists of a parser, several transformation components, and a pretty-printer. These components are specified in subdirectories of the package. The following directories are standard in a package providing support for one or more languages:

  • syn -- syntax definitions
  • sig -- signatures describing abstract syntax trees
  • pp -- pretty-print tables
  • xtc -- tool compositions
  • tests -- unit and integration tests

In addition a package can contain several directories for transformation componens.

Configuration

It is customary to develop Stratego packages using the AutoMake? and AutoConf? in order to make packages easiliy portable to many (Unix compatible) platforms. If you are not familiar with these tools please check out their documentation.

Configure.in

From the configure.in file, the build-time configure script is generated. It takes configuration parameters such as external packages and substitutes them in makefiles and other source files. The USE_XT_PACKAGES macro can be used in order to get parameterization of the StrategoXT packages.

https://svn.strategoxt.org/repos/StrategoXT/prolog-tools/trunk/configure.in

---------------------------------
 __Note:__  Included topic [[https:..svn.strategoxt.org.repos.StrategoXT.prolog-tools.trunk.configure.in]] does not exist yet
---------------------------------

bootstrap

In order to generate the configure script and instantiate the makefile templates several tools from the autoX family should be applied. The bootstrap script calls these tools in the right order. One unusual tool is autoxt, which installs AutoMake? macros supporting the use of StrategoXT tools. The bootstrap script assumes that autoxt can be found in the path.

---------------------------------
 __Note:__  Included topic [[https:..svn.strategoxt.org.repos.StrategoXT.prolog-tools.trunk.bootstrap]] does not exist yet
---------------------------------

Makefile.am

Each directory in the package should have a Makefile. These Makefiles are generated by automake and autoconf from a declarative Makefile.am. The top-level Makefile just declares its subdirectory such that navigation code can be generated. The Makefile.xt is installed by autoxt and contains standard make rules for applying StrategoXT tools. It should be included in each makefile in the package.

---------------------------------
 __Note:__  Included topic [[https:..svn.strategoxt.org.repos.StrategoXT.prolog-tools.trunk.Makefile.am]] does not exist yet
---------------------------------

The AC_CONFIG_FILES macro defines all files that should be created by configure.

Other Required Files

Automake/conf require the following files to exist in the package:

  • README -- name and purpose of the package
  • AUTHORS
  • ChangeLog -- fine grained log of changes
  • NEWS -- course grained description of changes

Configuring the Package

Once the basic configuration is set up you can configure the package with the following sequence of commands:

   > ./bootstrap
   > ./configure  --prefix=/installation/directory  --with-xt=/usr

Assuming that the StrategoXT, ATerm, and SDF distributions have been installed in /usr. Now it should be possible to make and install the components in the package using the commands:

   > make
   > make install

Exported components are installed in subdirectories of the /installation/directory.

Syntax Definition (syn)

The syntax definition of the language under consideration (Prolog in this case) is defined in directory syn/. The directory contains the following files:

The Makefile.am defines which parse tables to make (.tbl extension):

---------------------------------
 __Note:__  Included topic [[https:..svn.strategoxt.org.repos.StrategoXT.prolog-tools.trunk.syn.Makefile.am]] does not exist yet
---------------------------------

Signature (sig)

The algebraic signature defines the abstract syntax of a language. The signature of Prolog abstract syntax is defined in the Prolog.str:

  • Prolog.str -- signature of Prolog abstract syntax

The signature can be derived automatically from a syntax definition using the tool sdf-to-sig. The make rules in Makefile.xt invoke this tool based on the dependency of .str files on .def files. The Prolog.def file is made available via a symbolic link to the ../syn/ directory.

---------------------------------
 __Note:__  Included topic [[https:..svn.strategoxt.org.repos.StrategoXT.prolog-tools.trunk.sig.Makefile.am]] does not exist yet
---------------------------------

Pretty-Printer (pp)

A pretty-printer renders an abstract syntax tree as text. The GPP package in StrategoXT provides tools for rendering ASTs as ascii text, html, and latex. The translation works by first translating an AST to a Box term, which declares formatting independently of the target device and the source language. A Box can be formatted in different ways. The translation from AST to Box can be done in two ways. GPP supports pp-tables which define a mapping from AST constructors to Box terms. The pp-gen? tool generates a default pp-table from a syntax definition. Alternatively one can program the translation from AST to Box in a Stratego program. Although the latter is more work, it may be necessary when more sophisticated formatting is required. The Prolog package uses both methods.

  • Prolog.pp -- default pretty-print table for Prolog
  • Prolog2abox.str -- Stratego transformation from Prolog abstract syntax to Box

---------------------------------
 __Note:__  Included topic [[https:..svn.strategoxt.org.repos.StrategoXT.prolog-tools.trunk.pp.Makefile.am]] does not exist yet
---------------------------------

Tool Composition (xtc)

---------------------------------
 __Note:__  Included topic [[https:..svn.strategoxt.org.repos.StrategoXT.prolog-tools.trunk.xtc.Makefile.am]] does not exist yet
---------------------------------

Tests (tests)

---------------------------------
 __Note:__  Included topic [[https:..svn.strategoxt.org.repos.StrategoXT.prolog-tools.trunk.tests.Makefile.am]] does not exist yet
---------------------------------