Related articles |
---|
Using Functional Programming in C/C++ Compilers vdbent@mail.com (Kees & Annette van der Bent) (2000-04-03) |
Re: Using Functional Programming in C/C++ Compilers torbenm@diku.dk (2000-04-05) |
Re: Using Functional Programming in C/C++ Compilers dbm@research.bell-labs.com (Dave MacQueen) (2000-04-05) |
Re: Using Functional Programming in C/C++ Compilers joachim.durchholz@halstenbach.com.or.de (Joachim Durchholz) (2000-04-14) |
From: | torbenm@diku.dk (Torben AEgidius Mogensen) |
Newsgroups: | comp.compilers |
Date: | 5 Apr 2000 22:25:26 -0400 |
Organization: | Department of Computer Science, U of Copenhagen |
References: | 00-04-036 |
Keywords: | functional |
Kees & Annette van der Bent <vdbent@mail.com> writes:
>Who is willing to share his/her opinions on using functional
>programming languages for developing C/C++ compilers/linkers/...?
>* What language(s) and why?
>* What part(s) best done in FP?
>* Combining FP language and C/C++?
>* Performance issues?
>* Sofware engineering issues (maintenance, teaching C/C++ developers, ...)
>* ...
>* References?
There is a tool called "ckit"
(http://cm.bell-labs.com/cm/cs/what/smlnj/doc/ckit/index.html) which
is basically a parser for C written in SML. The output is a
representation of the abstract syntac tree. If I was to write a C
compiler today, I would start from this.
SML has several features that makes it very well suited for writing
compilers:
1) Recursive datatypes with pattern matching.
2) Automatic memory management (GC).
3) A good module system.
4) A type system that catches many errors at compile-time that would
not be caught at all by C.
5) Exceptions.
6) A wide range of compilers, so you can develop on a fast compiler
and run your final code through an optimizing compiler.
You can see Andrew Appel's book "Modern Compiler Implementation in ML"
for examples of compiler-code written in SML. You can even compare
with how the same things are done in C or Java by also looking at
"Modern Compiler Implementation in C" and "Modern Compiler
Implementation in Java" by the same author.
As for maintenance, the module system and the type system are really
aids for maintenance. Most ML implementations have some kind of
intelligent recompilation scheme.
In all, the major problem may be social: C/C++ programmers may be
reluctant to learn a new (and radically different) language. The
language itself is fairly easy to learn (we teach it as the first
language at DIKU) but it takes a while for a programmer who thinks in
objects and state to wrap his mind around a different way of
expressing things.
Torben Mogensen (torbenm@diku.dk)
Return to the
comp.compilers page.
Search the
comp.compilers archives again.