Computer Science Canada

Compilers & Interpreters

Author:  shorthair [ Mon Feb 16, 2004 3:47 pm ]
Post subject:  Compilers & Interpreters

What is a compiler You ask


Compilers compile program source code into runnable programs (or "binaries"). Some programming languages, such as C and its brother C++, have to be compiled before they will run on most computers. (It's possible that someone has created a C interpreter, but they are certaily not in common use.) Compilation means reading the source code - which, while not English by any stretch, is comparatively easy for humans to read - and translating it into raw machine code - zeroes and ones that the computer's specific CPU chip can understand and run quickly. Frequently, the same source code can be compiled on machines with different CPUs and produce two different binaries, neither of which would run on the other machine unaltered. (This is part of why so much Unix software is distributed as source - with an OS that runs on so many different kinds of chips, any other distribution method would be unwieldy.)

It's a bit like baking bread. The source code is the dough - humans can still alter its composition, but it's not really edible yet. It has to be put in the oven - the compiler - before it's ready for consumption. (This metaphor is not really so great, but I like it because some languages, notably Java and Python, can be compiled part way, into a "bytecode" language that isn't specific to any one chip, and then finished by a "just-in-time" compiler when it's time to run them. It's just kind of satisfying to call a program "half-baked" for no reason.)




Whats an interpreter You ask



Interpreters are like Turing, or scripting languages in games, or browsers loading HTML pages. There is source code, and a program reads it and does stuff with it, but doesn't actually compile.
Stolen from these people

Quote:
C++ Programming For Beginners wrote:

...However, there are some languages that do not need such a compiler, called interpreted languages. These languages are executed by a program called an interpreter, which executes the program as it runs, instead of first having to compile it. One advantage to this type of language is that you don't need to recompile your program each time you make a change to it.

Turing is kind of half and half. I mentioned it, though, because it is used mostly for interpreting code instead of compiling, and because of the time (version 4.0, I believe) when for some reason the makers decided not to add functionality to compile programs into stand alone executables.

Interpreters Contributed by Mazer

Author:  recneps [ Mon Feb 16, 2004 4:14 pm ]
Post subject: 

An interpeter is like a compiler, but it translates the code into machine langusage one line at a time, and does not create an exe file Smile am i close? Very Happy (it runs it line by line as it is converted.)

Author:  shorthair [ Mon Feb 16, 2004 4:18 pm ]
Post subject: 

Keep going, you both have good points , lets put em together mabye add a little metaphore or somthing to make it easy to understand ( hence why this thread exists so people can learn )

Author:  Mazer [ Mon Feb 16, 2004 5:29 pm ]
Post subject: 

Interpreters are like Turing, or scripting languages in games, or browsers loading HTML pages. There is source code, and a program reads it and does stuff with it, but doesn't actually compile.
Stolen from these people

C++ Programming For Beginners wrote:

...However, there are some languages that do not need such a compiler, called interpreted languages. These languages are executed by a program called an interpreter, which executes the program as it runs, instead of first having to compile it. One advantage to this type of language is that you don't need to recompile your program each time you make a change to it.

Turing is kind of half and half. I mentioned it, though, because it is used mostly for interpreting code instead of compiling, and because of the time (version 4.0, I believe) when for some reason the makers decided not to add functionality to compile programs into stand alone executables.

Author:  Tony [ Mon Feb 16, 2004 5:34 pm ]
Post subject: 

eh... turing is actually more like 2-in-1. It uses an interpreter to traslate turing not into machine code, but into C++ and then it also has its own compiler Laughing

An example of interpriter would be Java's VM 8)

Author:  shorthair [ Mon Feb 16, 2004 5:48 pm ]
Post subject: 

Well it lookslike Mazer has completed teh tutorial , andthis adds to his i owe you bits fund , your account is now worth 130 BITS

Author:  shorthair [ Mon Feb 16, 2004 10:29 pm ]
Post subject: 

Unless mazer , Do you want those Bits ?

Author:  Maverick [ Mon Feb 16, 2004 10:32 pm ]
Post subject: 

Hey if he doesnt want em ill take em Smile

Author:  Mazer [ Tue Feb 17, 2004 7:50 am ]
Post subject: 

Maybe we should just stick to the I.O.U. plan for now.

Author:  rizzix [ Tue Feb 17, 2004 3:12 pm ]
Post subject: 

tony wrote:
An example of interpriter would be Java's VM 8)

that's a half lie. Actually java is a hybrid system. It is an interpreter and a compiler.

Java uses the JIT (Just In Time) technology. Its pretty simple. First you compile your .java source files into bytecode (.class files) using javac. When you run the program, the JVM interprets the .class files and passes it to the JIT compiler, which then compiles it into native code.

This is one of the reasons java is sooo COOL and faster than most interpreters.

Examples of an interpreted language are usually scripting languages (like perl/python/tcsh/VBScript etc..) and web-programming languages (like php) except for java (once again), or maybe a few others (.NET for ex).

Author:  rizzix [ Tue Feb 17, 2004 3:19 pm ]
Post subject: 

tony wrote:
eh... turing is actually more like 2-in-1. It uses an interpreter to traslate turing not into machine code, but into C++ and then it also has its own compiler Laughing


ditto! turing is a 2-in-1 but, turing is not a hybrid system.

Author:  recneps [ Tue Feb 17, 2004 3:44 pm ]
Post subject: 

shorthair wrote:
Keep going, you both have good points , lets put em together mabye add a little metaphore or somthing to make it easy to understand ( hence why this thread exists so people can learn )


Lol, a little tired there shorthair? Smile There was only one reply above what you posted. Wink Laughing

Author:  Cervantes [ Tue Feb 17, 2004 7:26 pm ]
Post subject: 

actually I posted my definition but then deleted it because I realized that he wanted us to PM him the reply to keep the thread clean, seeing as how he would add it to his initial post.

you lose! Razz

Author:  recneps [ Wed Feb 18, 2004 5:21 pm ]
Post subject: 

You just "dirtied" it! hahahah lol. I still dont see the point between the two. i mean why not just make it an exe and run it? instead of converting piece by piece

Author:  jonos [ Wed Feb 18, 2004 5:46 pm ]
Post subject: 

cause it takes too long to make a .exe then run it, while if it would just run while in the program, then that would be quicker.

Author:  shorthair [ Wed Feb 18, 2004 7:07 pm ]
Post subject: 

errors are harder to find aswell, and DEBUG , dont even go there

Author:  wtd [ Wed Feb 18, 2004 7:10 pm ]
Post subject: 

recneps wrote:
You just "dirtied" it! hahahah lol. I still dont see the point between the two. i mean why not just make it an exe and run it? instead of converting piece by piece


In a sense you are creating an executable. It's just an executable for a different machine. In this case a machine that exists only in software.

The JIT just translates one format into another. The advantage of this approach is portability. You can distribute one *.class file to users on any platform with a Java Virtual Machine. Those whose JVMs can create native code will see a speed-up. Those who can't won't, but they'll still be able to run the file.


: