A compiler for natural semantics

  • Mikael Pettersson
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 1060)


Natural semantics is a formalism used for specifying both semantics and implementations of programming languages. Until recently, no practical implementation of the formalism existed. We have defined the Relational Meta-Language, RML, as an executable specification language for natural semantics. After a brief outline of the language, we describe the compilation strategy used by our rml2c compiler: transformations are applied to minimize non-determinism, and a continuationpassing style form is produced and simplified. Finally the CPS is emitted as low-level C code, using an efficient technique for implementing tailcalls. We also present performance measurements that support our choice of compilation strategy.


natural semantics determinacy continuations tailcalls 


  1. 1.
    A. V. Aho, R. Sethi, and J. D. Ullman. Compilers Principles, Techniques, and Tools. Addison-Wesley, 1986.Google Scholar
  2. 2.
    Hassan Aït-Kaci. Warren's Abstract Machine: A Tutorial Reconstruction. The MIT Press, 1991.Google Scholar
  3. 3.
    Andrew W. Appel. Compiling with Continuations. Cambridge University Press, 1992.Google Scholar
  4. 4.
    Isabelle Attali and Didier Parigot. Integrating natural semantics and attribute grammars: the Minotaur system. Research report N∘ 2339, INRJA, September 1994.Google Scholar
  5. 5.
    Henry G. Baker. CONS should not CONS its arguments, part II: Cheney on the M.T.A. ACM SIGPLAN Notices, 30(9):17–20, September 1995.Google Scholar
  6. 6.
    Takashi Chikayama, Tetsuro Pujise, and Daigo Sekita. A portable and efficient implementation of KL1. In Hermenegildo and Penjam [16], pages 25–39.Google Scholar
  7. 7.
    Philippe Codognet and Daniel Diaz. wamcc: Compiling Prolog to C. In Leon Sterling, editor, Proceedings of the Twelfth International Conference on Logic Programming, pages 317–331, Tokyo, Japan, 1995. The MIT Press.Google Scholar
  8. 8.
    Fabio Q. B. da Silva. Towards a formal framework for evaluation of operational semantics. Technical Report ECS-LFCS-90-126, University of Edinburgh, 1990.Google Scholar
  9. 9.
    Joëlle Despeyroux. Proof of translation in natural semantics. In Proceedings of the 1st Symposium on Logic in Computer Science, LICS'86, pages 193–205. IEEE, 1986.Google Scholar
  10. 10.
    Thierry Despeyroux. Executable specification of static semantics. In Gilles Kahn, editor, Semantics of Data Types, volume 173 of LNCS, pages 215–233. Springer-Verlag, 1984.Google Scholar
  11. 11.
    Marc Feeley. Gambit-C version 2.2. Available by anonymous ftp from, May 1995.Google Scholar
  12. 12.
    Jean H. Gallier. Logic for Computer Science. John Wiley & Sons, 1987.Google Scholar
  13. 13.
    David Gudeman, Koenraad De Bosschere, and Saumya K. Debray. jc: An efficient and portable sequential implementation of Janus. In Krzysztof Apt, editor, Proceedings of the Joint International Conference and Symposium on Logic Programming, pages 399–413, Washington, USA, 1992. The MIT Press.Google Scholar
  14. 14.
    John Hannan. Investigating a proof-theoretic meta-language for functional programs. Report 91/1, DIKU Copenhagen, 1991. PhD thesis.Google Scholar
  15. 15.
    Bogumil Hausman. Turbo Erlang: Approaching the speed of C. In E. Tick and G. Succi, editors, Implementations of Logic Programming Systems, pages 119–135. Kluwer Academic Publishers, 1994.Google Scholar
  16. 16.
    M. Hermenegildo and J. Penjam, editors. Proceedings of the 6th International Symposium on Programming Language Implementation and Logic Programming, PLILP'94, volume 844 of LNCS. Springer-Verlag, 1994.Google Scholar
  17. 17.
    I. Jacobs. The Centaur 1.2 Manual, 1992. Available from INRJA-Sophia Antipolis.Google Scholar
  18. 18.
    Gilles Kahn. Natural semantics. In P. J. Brandenburg, G. Vidal-Naquet, and M. Wirsing, editors, Proceedings of the Symposium on Theoretical Aspects of Computer Science, STAGS'87, volume 247 of LNCS, pages 22–39. Springer-Verlag, 1987.Google Scholar
  19. 19.
    David Kranz, Richard Kelsey, Jonathan A. Rees, Paul Hudak, James Philbin, and Norman I. Adams. Orbit: an optimizing compiler for Scheme. In Proceedings of the ACM SIGPLAN '86 Symposium on Compiler Construction, pages 219–233. ACM Press, 1986.Google Scholar
  20. 20.
    Robin Milner, Mads Tofte, and Robert Harper. The Definition of Standard ML. The MIT Press, 1990.Google Scholar
  21. 21.
    Mikael Pettersson. A term pattern-match compiler inspired by finite automata theory. In U. Kastens and P. Pfahler, editors, Compiler Construction, 4th International Conference, CC'92, volume 641 of LNCS, pages 258–270. Springer-Verlag, October 1992.Google Scholar
  22. 22.
    Mikael Pettersson. RML — a new language and implementation for natural semantics. In Hermenegildo and Penjam [16], pages 117–131.Google Scholar
  23. 23.
    Mikael Pettersson. Compiling Natural Semantics. PhD thesis, Department of Computer and Information Science, Linköping University, December 1995.Google Scholar
  24. 24.
    Simon L. Peyton Jones. Implementing lazy functional languages on stock hardware: the spineless tagless G-machine. Journal of Functional Programming, 2(2):127–202, April 1992.Google Scholar
  25. 25.
    Gordon D. Plotkin. A structural approach to operational semantics. Report DAIMI FN-19, Computer Science Department, Aarhus University, Denmark, September 1981.Google Scholar
  26. 26.
    Zoltan Somogyi, Fergus James Henderson, and Thomas Charles Conway. The implementation of Mercury, an efficient purely declarative logic programming language. In Koen De Bosschere, Bart Demoen, and Paul Tarau, editors, ILPS'94 Post-Conference Workshop on Implementation Techniques for Logic Programming Language, pages 31–58, 1994.Google Scholar
  27. 27.
    Guy L. Steele Jr. Rabbit: a compiler for Scheme (a study in compiler optimization). MIT AI Memo 474, Massachusetts Institute of Technology, May 1978. Master's Thesis.Google Scholar
  28. 28.
    David R. Tarditi, Peter Lee, and Anurag Acharya. No assembly required: Compiling Standard ML to C. ACM LOPLAS, 1(2):161–177, June 1992.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1996

Authors and Affiliations

  • Mikael Pettersson
    • 1
  1. 1.Department of Computer and Information ScienceLinköping UniversityLinköpingSweden

Personalised recommendations