A self-applicable partial evaluator for term rewriting systems

  • Anders Bondorf
Part of the Lecture Notes in Computer Science book series (LNCS, volume 352)


This paper describes a fully self-applicable partial evaluator developed for equational programs in the form of term rewriting systems. Being self-applicable, the partial evaluator is able to generate efficient compilers from interpreters as well as a compiler generator automatically.

Earlier work in partial evaluation of term rewriting systems has not achieved self-applicability due to the problem of partially evaluating pattern matching. This problem is overcome by developing an intermediate language for being able to express pattern matching at an appropriate level of abstraction.

We describe the intermediate language and partial evaluation of it. Binding time analysis, a well-known preprocessing technique, is used. We introduce further preprocessing to deal efficiently with our intermediate language.

The system has been implemented and compilers for small languages as well as a compiler generator have been generated with satisfactory results.


Decision trees functional languages pattern matching elementary matching operations binding time analysis abstract interpretation partially static structures 


  1. [Augustsson 85]
    Lennart Augustsson: “Compiling pattern matching”, Conference on Functional Programming Languages and Computer Architecture (ed. J.-P. Jouannaud), Nancy, France 1985, Lecture Notes in Computer Science 201, 368–381, Springer-Verlag 1985.Google Scholar
  2. [Baeten, Bergstra, & Klop 87]
    J. C. M. Baeten, J. A. Bergstra, and J. W. Klop: “Term rewriting systems with priorities”, Rewriting Techniques and Applications (ed. Pierre Lescanne), Bordeaux, France 1987, Lecture Notes in Computer Science 256, 83–94, Springer-Verlag 1987.Google Scholar
  3. [Bonacina 88]
    Maria Paola Bonacina: “Partial evaluation in functional rewrite programming”, AICA Annual Conference, Cagliari, Italy 1988.Google Scholar
  4. [Bondorf 88]
    Anders Bondorf: “Towards a self-applicable partial evaluator for term rewriting systems”, in [PEMC 88].Google Scholar
  5. [Bondorf, Jones, Mogensen, & Sestoft 89]
    Anders Bondorf, Neil D. Jones, Torben Æ. Mogensen, and Peter Sestoft: “Binding time analysis and the taming of self-application”, submitted for publication.Google Scholar
  6. [Bulyonkov 88]
    M. A. Bulyonkov: “A theoretical approach to polyvariant mixed computation”, in [PEMC 88].Google Scholar
  7. [Consel 88]
    Charles Consel: “New insights into partial evaluation: the SCHISM experiment”, ESOP '88 (ed. Harald Ganzinger), Nancy, France 1988, Lecture Notes in Computer Science 300, 236–247, Springer-Verlag 1988.Google Scholar
  8. [Dershowitz 85]
    Nachum Dershowitz: “Computing with rewrite systems”, Information and Control 65, 122–157, 1985.CrossRefGoogle Scholar
  9. [Ershov 82]
    Andrei P. Ershov: “Mixed computation: potential applications and problems for study”, Theoretical Computer Science 18, 41–67, 1982.CrossRefGoogle Scholar
  10. [Fuller & Abramsky 88]
    David A. Fuller and Samson Abramsky: “Mixed computation of Prolog programs”, in [PEMC 88].Google Scholar
  11. [Futamura 71]
    Yoshihiko Futamura: “Partial evaluation of computing process — an approach to a compiler-compiler”, Systems, Computers, Controls 2, 5, 45–50, 1971.Google Scholar
  12. [Hoffmann & O'Donnell 82]
    Christoph M. Hoffmann and Michael J. O'Donnell: “Programming with equations”, ACM Transactions on Programming Languages and Systems 4, 1, January 1982.Google Scholar
  13. [Huet & Levy 79]
    Gérard Huet and Jean-Jacques Levy: “Computations in Nonambiguous Linear Rewriting Systems”, Technical report no. 359, INRIA, Rocquencourt, France, 1979.Google Scholar
  14. [Huet & Oppen 80]
    Gérard Huet and Derek C. Oppen: “Equations and rewrite rules, a survey”, Formal Language Theory, Perspectives and Open Problems (ed. Ronald V. Book), 349–405, Academic Press, 1980.Google Scholar
  15. [Jones 87]
    Neil D. Jones: “Flow analysis of lazy higher-order functional programs”, in Abstract Interpretation of Declarative Languages (eds. Samson Abramsky and Chris Hankin), Ellis Horwood Series in Computers and their Applications, 1987.Google Scholar
  16. [Jones 88]
    Neil D. Jones: “Re-examination of automatic program specialization”, in [PEMC 88].Google Scholar
  17. [Jones, Sestoft, & Søndergaard 85]
    Neil D. Jones, Peter Sestoft, and Harald Søndergaard: “An experiment in partial evaluation: The generation of a compiler generator”, Rewriting Techniques and Applications (ed. J.-P. Jouannaud), Dijon, France 1985, Lecture Notes in Computer Science 202, 124–140, Springer-Verlag 1985.Google Scholar
  18. [Jones, Sestoft, & Søndergaard 88]
    Neil D. Jones, Peter Sestoft, and Harald Søndergaard: “Mix: a self-applicable partial evaluator for experiments in compiler generation”, LISP and Symbolic Computation 1 3/4, 1988.Google Scholar
  19. [Kahn 87]
    Gilles Kahn: “Natural Semantics”, INRIA, Centre Sophia Antipolis, France, Rapport de Recherche No 601, 1987.Google Scholar
  20. [Klop 87]
    J. W. Klop: “Term rewriting systems: a tutorial”, Bulletin of the European Association for Theoretical Computer Science 32, 1987.Google Scholar
  21. [Launchbury 88]
    John Launchbury: “Projections for specialisation”, in [PEMC 88].Google Scholar
  22. [Mogensen 88]
    Torben Æ. Mogensen: “Partially static structures in a self-applicable partial evaluator”, in [PEMC 88].Google Scholar
  23. [Mogensen 89]
    Torben Æ. Mogensen: “Binding time analysis for higher order polymorphically typed languages”, this volume.Google Scholar
  24. [PEMC 88]
    D. Bjørner, A. P. Ershov, and N. D. Jones (eds.): “Workshop on Partial Evaluation and Mixed Computation”, Gl. Avernæs, Denmark, October 1987. North-Holland 1988.Google Scholar
  25. [Peyton Jones 87]
    Simon L. Peyton Jones: “The Implementation of Functional Programming Languages”, Prentice-Hall, 1987, in particular ch. 5, 78–103: “Efficient compilation of pattern-matching” by Philip Wadler.Google Scholar
  26. [Romanenko 88]
    Sergei A. Romanenko: “A compiler generator produced by a self-applicable specialiser can have a surprisingly natural and understandable structure”, in [PEMC 88].Google Scholar
  27. [Sestoft 86]
    Peter Sestoft: “The structure of a self-applicable partial evaluator”, Programs as Data Objects (eds. Neil D. Jones and Harald Ganzinger), Copenhagen, Denmark 1985, Lecture Notes in Computer Science 217, 236–256, Springer-Verlag 1986.Google Scholar
  28. [Sestoft 88]
    Peter Sestoft: “Automatic call unfolding in a partial evaluator”, in [PEMC 88].Google Scholar
  29. [Turchin 86]
    Valentin F. Turchin: “The concept of a supercompiler”, ACM Transactions on Programming Languages and Systems 8, 3, July 1986.Google Scholar
  30. [Turchin 88]
    Valentin F. Turchin: “The algorithm of generalization”, in [PEMC 88].Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1989

Authors and Affiliations

  • Anders Bondorf
    • 1
  1. 1.DIKU, University of CopenhagenCopenhagen ØDenmark

Personalised recommendations