CuriouSTEM

View Original

What Are The Roles Of Compilers And Interpreters?

The concepts of compilers and interpreters seem to be complicated enough to scare the aspiring computer science student, due to their emphasis on efficiency and complicated structures to boot. Nevertheless, these concepts aren’t something to be afraid of, and it is essential for any programmer to understand them at a basic level.

A compiler is a separate program that is used to transform code from a high-level to a low-level language. I’m sure we have all heard that computers “think” in 1’s and 0’s. What this means is that code written must be converted to long binary messages. These messages are sometimes referred to as “machine code” or “assembly language”. The compiler converts the code to binary during runtime.

Different programs may use different syntax (words written to tell the computer what to do) to convey the same meaning. This is why there are C compilers, Java compilers, and Python compilers. Ultimately, syntax is in the control of the user, so it is important to pay attention to your code. While many programs nowadays attempt to show errors in your program, this involves a lossy transmission (or “message that is frequently inaccurate”) between the executed code and your development environment.

Interpreters play a separate role yet are similar in many ways. They also work to convert high-level code to machine code. The main difference is that while compilers create executable files (.exe) before beginning to convert code, interpreters convert code while the program is running. This means no separate file is created when using an interpreter.

C++ uses a compiler while Python uses an interpreter. Java uses a combination of the two. The compiler creates “bytecode” as an intermediary file and then an interpreter (called the Java Virtual Machine) converts this into binary. To understand why we must look into Java’s history briefly. Java was known for many innovations, such as the introduction of object-oriented programming. One of the main goals of Java was to create a truly portable language that could be used on macOS, Windows, and Linux (the three most dominant operating systems in the 90’s and today). In order to compensate for these and any other future systems, the developers of Java decided to make different interpreters for each system and keeping the same compiler.

Using all these different forms of program design for each of the chosen methods for converting code has allowed programmers to use languages tailored to their specific needs. As the variety of choices in programming increases, the same effects can be seen to a greater degree as our programs become more complex and unique.

Picture Source: ecomputernotes.com