# Compiler generation from denotational semantics

## Abstract

A methodology is described for generating provably correct compilers from denotational definitions of programming languages. An application is given to produce compilers into STM code (an STM or state transition machine is a flow-chart-like program, low-level enough to be translated into efficient code on conventional computers). First, a compiler ϕ: LAMC → STM from a lambda calculus dialect is defined. Any denotational definition Δ of language L defines a map \(\bar \Delta\): L → LAMC, so \(\bar \Delta ^ \circ \varphi\) compiles L into STM code. Correctness follows from the correctness of ϕ.

The algebraic framework of Morris, ADJ, etc. is used. The set of STMs is given an algebraic structure so any \(\bar \Delta ^ \circ \varphi\) may be specified by giving a derived operator on STM for each syntax rule of L.

This approach yields quite redundant object programs, so the paper ends by describing two flow analytic optimization methods. The first analyzes an already-produced STM to obtain information about its runtime behaviour which is used to optimize the STM. The second analyzes the generated compiling scheme to determine runtime properties of object programs in general which a compiler can use to produce less redundant STMs.

## Keywords

Transition Rule Parse Tree Abstract Interpretation Denotational Semantic Entry State## References

- [ADJ79]Thatcher, J.W., Wagner, E.G., and Wright, J.B. More Advice on Structuring Compilers and Proving Them Correct, 6th Colloquium, Automata, Languages, and Programming, Graz, Austria, 1979, Springer Lecture Notes in Computer Science 71.Google Scholar
- [AhU72]Aho, A.V., and Ullman, J.D. The Theory of Parsing, Translation, and Compiling, Prentice-Hall, Englewood Cliffs, N.J. 1972.Google Scholar
- [BAC78]Backus, J. Can Programming Be Liberated from the von Neumann Style? Comm. ACM 21-8, 1978, 613–641.CrossRefGoogle Scholar
- [BER76]Berkling, K.J. Reduction Languages for Reduction Machines, Rpt. ISF-76-8, Gesellschaft für Mathematik und Datenverarbeitung MbH, Bonn, 1976.Google Scholar
- [COU77]Cousot, P., and Cousot, R. Abstract Interpretation: A Unified Lattice Model for Static Analysis of Programs by Con-Struction or Approximation of Fixpoints, 4th ACM Symposium onPrinciples of Programming Languages, Los Angeles, 1977, 234–252.Google Scholar
- [ERS78]Ershov, A.P. On the Essence of Compilation, in Formal Description of Programming Language Concepts, E.J. Neuhold, ed., North-Holland, Amsterdam, 1976, 391–420.Google Scholar
- [GAN79]Ganzinger, H. Some Principles for the Development of Compiler Descriptions from Denotational Language Definitions, Tech. Rpt., Technical University of Munich, 1979.Google Scholar
- [GOR79]Gordon, M.J.C. The Denotational Description of Programming Languages, Springer-Verlag, Berlin, 1979.Google Scholar
- [KIT80]Kitchen, C. Compiling State Transition Machines into Machine Language, M.S. Thesis, University of Kansas, forthcoming.Google Scholar
- [McC63]McCarthy, J. Towards a Mathematical Science of Computation, in IFIP 62, C.M. Poppelwell, ed., North-Holland, Amsterdam, 21–28.Google Scholar
- [MiS76]Milne, R., and Strachey, C. A Theory of Programming Language Semantics, Chapman and Hall, London, 1976.Google Scholar
- [MOR73]Morris, F.L. Advice on Structuring Compilers and Proving Them Correct, 1st ACM Symposium on Principles of Programming Languages, Boston, 1973, 144–152.Google Scholar
- [MOS75]Mosses, P.D. Mathematical Semantics and Compiler Generation, Ph.D. Thesis, University of Oxford, 1975.Google Scholar
- [MOS79]Mosses, P.D. A Constructive Approach to Compiler Correctness, DAIMI IR-16, University of Aarhus, 1979.Google Scholar
- [RAS79]Raskovsky, M., and Turner, R. Compiler Generation and Denotational Semantics, Fundamentals of Computation Theory, 1979.Google Scholar
- [REY72]Reynolds, J.C. Definitional Interpreters for Higher-Order Programming Languages, Proc. of the SCM National Conference, Boston, 1972, 717–740.Google Scholar
- [REY74]Reynolds, J.C. On the Relation Between Direct and Continuation Semantics, 2nd Colloquium on Automata, Languages, and Programming, Saarbrücken, Springer-Verlag, Berling, 1974, 141–156.Google Scholar
- [SCH80]Schmidt, D.A. Compiler Generation from Lambda-Calculus Definitions of Programming Languages, Ph.D. Thesis, Kansas State University, Manhattan, Kansas, forthcoming.Google Scholar
- [STO77]Stoy, J.E. Denotational Semantics, MIT Press, Cambridge, Mass., 1977.Google Scholar