What is a "Compiler"

For everything that's not in any way related to PureBasic. General chat etc...
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

What is a "Compiler"

Post 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?
@}--`--,-- A rose by any other name ..
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Well, "compiler" is fairly generic and can mean several things..

http://en.wikipedia.org/wiki/Compiler
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: What is a "Compiler"

Post 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".)
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

true i didnt get that with me.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post 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.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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.
@}--`--,-- A rose by any other name ..
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

All compilers are translators.
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

What is an interpreter?
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post 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.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post 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.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Interpreter usually also needs a runtime file or two. I think?
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

lol @ blueznl
:D
@}--`--,-- A rose by any other name ..
Post Reply