Hello, programming geeks. Today’s topic is something we’re not mostly concerned about for running the code we wrote. I’d like to ask you a question before starting the subject. Did you know that before running the code, the source code should somehow be converted to machine code and there are two main ways to that? Also, make sure to check out other articles of mine to grasp the concepts of programming in an uncomplicated way.
Programing Languages can be implemented by 3 general methods. Translating programs to machine languages is called compiler implementation, which has the advantages of very fast execution and a complete translation process. However, the translation process itself is very slow and time-consuming. The language the compiler translates is called the source language. So what happens exactly? The compiler goes through that source code and creates a separate file, which contains the machine code. The file is called an executable file as it can directly be executed/run. Let’s not forget that the source program has to go through several phases to generate and result in output.
The lexical analyzer collects the characters of the source program into lexical units, which are identifiers, special words, operators, and punctuation symbols. Syntax analyzer uses the lexical units and creates a parse tree to illustrate the syntactic structure of the program. The intermediate code generator produces a program between the source program and the final output of the compiler (the machine language program). The semantic analyzer is a fundamental part of the code generator and checks for errors, such as type errors. The code generator translates optimized code to an equivalent machine language program.
With an interpreted language, the source code is not compiled beforehand. Instead, a copy of it is sent to be interpreted by the machine whenever the program runs. The whole process differs from the compilation. A pure interpretation has the advantage of easy implementation, yet the disadvantage outweighs the advantages. Since it is decoding high-level language statements, the execution time is 10–100 times slower compared to the compiler. Another drawback of pure interpretation is the amount of space it takes.
Last but not least, there’s a hybrid implementation system, which is a compromise between compilers and pure interpreters. Their job is to translate high-level programs to an intermediate language designed to allow easy interpretations. It’s worth mentioning that hybrid implementation is faster compared to pure interpretation.
Thank you very much for your attention, I hope you deepened or refreshed your knowledge. Peace ✌🏼
- Sebesta, R. W. (2019). Examples of Multiple Selectors. In Concepts of programming languages. NY, NY: Pearson.