Philosophical musings: interpreters vs. compilers

Jim Little jiml@inconnect.com
Sat, 04 Sep 1999 15:40:47 -0600


This is part one.  It may be read independently of part two.

This email is an unpolished continuation of the thoughts I published in
"The Will and the Word: A Philosophy of Programming"
(http://www.teleport.com/~sphere/documents/0006/4/index.html).  The
fundamental concepts are:

. Programs are abstract concepts.  They are a wish that the world behave
in a certain way.
. Programs are reified as models.  A given program may be expressed by
several different models.
. Machines interpret models.  In so doing, they behave in the way the
program specifies.
. Metamodels are used to understand which program a model describes. 
Metamodels describe a set of models and the corresponding programs.
. Metamodels typically describe models which are related in some way,
and machines typically interpret all of the models in a particular
metamodel.


An interpreter and a compiler are two fundamentally different beasts at
one level, and yet very similar at another.

An interpreter is a virtual machine for a particular metamodel.  A
compiler is a metaprogram which isomorphically transforms a program
model from one metamodel to another.  Typically, the second metamodel is
some form of machine code, but this isn't necessarily the case.  For
example, the Java compiler emits Java byte code.  Some copmilers emit C
source code.

Many interpreters (REXX, Perl) are in fact compilers AND interpreters. 
They first compile the source model into a bytecode, then interpret the
bytecode.

I could argue that compilers are also VM's.  (In fact, I could argue
that any program which takes input is a VM, and any machine which takes
input is programmable.)  The reasoning is that the compiler is
interpreting the source code to produce its output.

The crucial difference, though, is that the VM is not isomorphic.  (I'm
not sure if that's the correct term for this case.)  Basically, although
the compiler is a VM, it is not interpreting the model in the way its
metamodel specifies.  It is considering the model to be part of a
DIFFERENT metamodel than the one actually intended.

This is getting complex, but I think it's a crucial point.  When a model
is executed by a machine, virtual or otherwise, the machine interprets
the model in the context of a particular metamodel.  Normally, I would
think that using the wrong metamodel would result in an incorrect
system.  But in the case of a compiler, the wrong metamodel is
INTENTIONALLY being used in order to achieve a specific result.


Jim Little
jiml@inconnect.com