‘Stupid’ Question 3: What is a compiler and an interpreter, and what is the difference?
Yes! I asked this! I thought I knew, but wanted to make sure I really knew- so I asked this question again :) OMG. Now lets move on to the answer.
So both are basically programs that do the same thing, only in different ways. But the purpose is the same. They implement a language, and by this I mean that they take source-code (the set of readable instructions that we write as programmers) and translates this to executable machine code.
The difference is how they do it, the compiler takes the whole thing and translates it and saves this as an file that can be executed later, the interpreter translates line by line as you go, without saving to a file. (This of course means there are pros and cons for both ways of translating)
A simple diagram, but there is more magic than this happening ;)
I wont get into the different steps of compiling (Lexical analysis, Syntax analysis, Code generation, Linking)- but this is the very simple answer. Nonetheless, I don’t consider this question fully answered, there is much more to it,- once you get into the details. But I’ll ask separate questions for that, such as How does a compiler work? And are all languages compiled the same way? Please add some comments, and ideas! I read and appreciate all comments :)
Last modified on 2012-07-20