Page 1 of 2

What is a "Compiler"

Posted: Thu Oct 06, 2005 12:19 pm
by Dare2
Just interested to know what your definition of a compiler is.
  • 1: AsmSrc -> Assembler -> binary (exe,dll,obj,etc)
    2: PureSrc -> PureBasic -> asmSrc -> Assembler -> binary
    3: BcxSrc -> Bcx -> cSrc -> cCompiler -> binary
    4: langASrc -> langA -> binary
    5: langBSrc -> langB -> PureSrc -> PureBasic -> asmSrc -> Assembler -> binary
Which is a compiler? Which is a translator? Which is a preprocessor?

Posted: Thu Oct 06, 2005 3:41 pm
by Karbon
Well, "compiler" is fairly generic and can mean several things..

http://en.wikipedia.org/wiki/Compiler

Posted: Thu Oct 06, 2005 4:31 pm
by thefool
preprocessors are runned before compilers.
A compiler is basically just a program that changes:
LanguageA -> LanguageB

In many instances its LanguageA -> Assembler

Read Karbons link to understand it.

Re: What is a "Compiler"

Posted: Thu Oct 06, 2005 4:34 pm
by Trond
Dare2 wrote:Which is a compiler? Which is a translator?
A compiler is a translator for translating input in one programming language into another programming language. The second language can be as high-level as you want, provided the first language is even more high-level. (So a compiler translates "down".)

Posted: Thu Oct 06, 2005 4:44 pm
by thefool
true i didnt get that with me.

Posted: Thu Oct 06, 2005 5:45 pm
by rsts
I like dictionary.com's definition better than wiki because it's much closer to how i was taught and how I've always viewed them.

compiler

<programming, tool> A program that converts another program
from some source language (or programming language) to
machine language (object code). Some compilers output
assembly language which is then converted to machine
language by a separate assembler.

A compiler is distinguished from an assembler by the fact that
each input statement does not, in general, correspond to a
single machine instruction or fixed sequence of instructions.
A compiler may support such features as automatic allocation
of variables, arbitrary arithmetic expressions, control
structures such as FOR and WHILE loops, variable scope,
input/ouput operations, higher-order functions and
portability of source code.

AUTOCODER, written in 1952, was possibly the first primitive
compiler. Laning and Zierler's compiler, written in
1953-1954, was possibly the first true working algebraic
compiler.

Posted: Fri Oct 07, 2005 12:35 am
by Dare2
Hi guys,

Thanks for the comments and opinions.

My initial thought was that a compiler was something that took something at least vaguely human-readable and converted it to something machine readable - that is, executable - and that most compilers today were in fact only a part of the compilation process, relying on at least a linker for the last step.

However I heard a rather heated conversation on this and so thought I would find out what others thought.

My take at the mo is that most compilers nowadays are in fact translators.

Posted: Fri Oct 07, 2005 9:35 am
by Trond
All compilers are translators.

Posted: Fri Oct 07, 2005 9:51 am
by Bonne_den_kule
What is an interpreter?

Posted: Fri Oct 07, 2005 10:02 am
by GedB
Heres my attempt to put it all in a context.

At the bottom of the pile is the Machine code.

Machine Code is a numeric code understood by the processor itself. Each command is a separate opcode which has a specific value.

Assembly is a set of short codes that relate to the machine code opcodes, called mnemonics.

So all an assemler has to do is take the source code and translate the mnemonics into their numeric equivalents. They usually do some other stuff, like resolve addresses for labels and constant numeric expressions. The important thing is that the ASM source will be in the exact same structure as the final machine code executed by the Assembler.

Assembly makes machine code accessible to humans, the code is still written for the convenience of the processor.

A compiler accepts a high level language, which is written in an entirely different structure to the final machine code. The structures in a high level language, such as IFs, SELECTs and PROCEDURES have no equivalent in machine code.

The compiler therefore has the job of translating not just the words, but also the concepts expressed in the language. The machine code output may not reflect the origianl program structure very closely.

A preprocessor is used by both Compilers and Assemblers. It transforms the text of a code following some templating syntax. So called High Level Assemblers, such as FASM and HLA, use this to implement MACROs that enable them to emulate high level structures.

Posted: Fri Oct 07, 2005 10:03 am
by GedB
An interpreter doesn't produce machine code at all.

Instead it runs as a program, reading in the source code and then taking action based on what it reads.

Posted: Fri Oct 07, 2005 10:44 am
by GeoTrail
Interpreter usually also needs a runtime file or two. I think?

Posted: Fri Oct 07, 2005 11:15 am
by thefool
not usually. its very different. The final result might even be a single exe file!
But then its just the interpretter, with the script attached in the end.

Posted: Fri Oct 07, 2005 11:32 am
by blueznl
a COMPILER: someone who collects totally useless company data

an ASSEMBLER: an engineer who puts together the v12 jaguar that one of his students took apart so carelessly

Posted: Fri Oct 07, 2005 12:42 pm
by Dare2
lol @ blueznl
:D