Re: Compiler vs. Translator

Martin Ward <Martin.Ward@durham.ac.uk>
30 May 2004 13:19:11 -0400

          From comp.compilers

Related articles
Compiler vs. Translator postmaster@paul.washington.dc.us (Paul Robinson) (2004-05-16)
Re: Compiler vs. Translator dido@imperium.ph (2004-05-24)
Re: Compiler vs. Translator gah@ugcs.caltech.edu (glen herrmannsfeldt) (2004-05-24)
Re: Compiler vs. Translator richard@imagecraft.com (Richard F. Man) (2004-05-24)
Re: Compiler vs. Translator Martin.Ward@durham.ac.uk (Martin Ward) (2004-05-30)
Re: Compiler vs. Translator gah@ugcs.caltech.edu (glen herrmannsfeldt) (2004-05-30)
Re: Compiler vs. Translator hannah@schlund.de (2004-06-06)
Re: Compiler vs. Translator jburgy@hotmail.com (2004-06-15)
| List of all articles for this month |

From: Martin Ward <Martin.Ward@durham.ac.uk>
Newsgroups: comp.compilers
Date: 30 May 2004 13:19:11 -0400
Organization: Compilers Central
References: 04-05-051 04-05-058
Keywords: translator, comment
Posted-Date: 30 May 2004 13:19:11 EDT

On Monday 24 May 2004 5:21 am, dido@imperium.ph wrote:
> There is no real difference between writing a compiler or a language
> translator, actually. If you think about it, they're really the same
> animal. What you'd call a compiler is actually a translator from your
> high-level language into assembly language or straight machine code.


In theory, yes. In practice there is a huge difference. ("The
difference between theory and practice is that in *theory* there is no
difference between theory and practice, but in *practice* there is").


A translator usually has to generate nice, structured, maintainable
code in the target language which makes use of idioms in the target
language where possible. A compiler can generate any code it likes,
however ugly, which is syntactically valid for the target language.


A compiler has to cope with any valid syntax in the source language,
and generate semantically equivalent code in the target language. A
translator usually has a fixed body of code that it is required to
translate, and may have some leeway over rarely used idioms which are
hard to translate automatically (generating a "FIXME" comment with
manual intevention required to complete the task).


A compiler usually has to do optimisation. A translator can rely on
the compiler for the target language to do optimisation: in fact, it
should *not* do optimisations which affect readability of the code.


A compiler is translating from a higher level language to a lower
level language (or to a low level subset of the target language). A
translator is usually translating from a high level language to
another high level language, or from a low level language to a high
level language. For example, translating from assembler language to C
or COBOL (see http://www.cse.dmu.ac.uk/~mward/martin/papers/ for
example).


--
Martin
Martin.Ward@durham.ac.uk http://www.cse.dmu.ac.uk/~mward/
[I agree that they're different, but contrary to what one might hope,
a translator is certainly no easier to write. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.