You are here

Code generators--Part 2

Amr M. Kamel's blog - Fri, 17/08/2007 - 10:41am
Hi again, today's post will explain what is an interpreter and how its functionality is much different than the compiler's, and I will end this post by a simple comparison of both code generation methods. To refresh your memory I recommend reading the previous post in this series.

An Interpreter is a computer program that executes high-level programs line by line.

As you see in the above animated diagram, the source code is fed to the interpreter, which in turn reads it line by line and produce its corresponding Native/Machine code and execute it. Interpreters detect errors during run-time and if it read a line that causes an error it will stop and state which line caused this error.

Interpreters can work in two modes:
  1. By passing source code to the interpreter e.g. python
  2. Interactive/Active mode, where programmers enter code line by line and see the result of entering each line e.g Interactive shells of Ruby, Python, and Groovy ...etc.
Note: Some people think that interpreted programming and scripting language are the same, but this is a misconception. Now almost modern scripting languages use the Hybrid model "which I will explain in my next post of this series" and are not purely interpreted.

Also another note: I have used Python, Ruby, and Groovy terms just for illustration purposes, this doesn't mean they are pure interpreted languages.

Compilers VS. Interpreters:
Here is a brief comparison between compiled and interpreted languages:
  • Compiled programs have much better run-time performance "simply because its Native/Machine code".
  • Compiled programs are machine and operating system specific, while interpreted ones are machine independent "some times operating system independent".
  • Interpreted programs can be easily debugged.
  • Interpreted languages lead to faster development process "prototyping", while compiled languages are best suited for production use.
The next post "last part" will discuss the Hybrid model, and how these models overcome disadvantages of both code generators while taking advantages of both of them.