Many of us heard of the term 'compiler' when working with computer programming. Just as any programmer may know, many high level programming languages like Java and C++ require special compilers to run the source code. So what is a compiler? And how does it work?
When writing a Java code for example, the code is written using a high level language, simply a plain English language. High level language uses variables and arithmetic expressions to direct the computer to perform the required operations. It is referred to as high level language because it is of a higher abstraction from the machine language. Think of an English speaker trying to communicate with a French speaker. Both are considered of high level language because both need a way to understand each other. This is exactly what happens when writing a code with a high level language, the computer cannot directly 'understand' what is being 'said' to it, so it needs a 'translator' to help it do so.
It is that simple. A compiler is a translator that helps the programmer and the computer communicate with each other and understand each other. It collects the instructions given by the programmer, analyzes them as one piece, convert them into a lower level language, or machine language, the language that the computer 'talks' and understands. In other words, low-level-language is the native machine language.
Typically the programmer uses a text editor, such as Notepad, to write the code, saves it in a special file extension appropriate for the targeted language such as filename.java, and runs the appropriate compiler on it. Because this file is the original source for the instructions given to the computer, it is called the source code. When it is finally executed, the final code, or the output of the source code, is called the object code.
The compiler reads the source code and checks it for syntax correctness. If all code statements are syntactically correct, legal in terms of programming language, the compiler executes the code creating the object code. However, if there is any illegal use of statements it signals that there is an error and generates error messages. Errors caused by illegal use of statements in the source code are called syntax errors, or compile time errors.
In conclusion a compiler is a computer program that works as an interface between the programmer and the computer, and helps translates the code written in a high level language into a low-level-language that can be executed by the computer.
References:
Compiler. (2006). In Webopedia, The Free Encyclopedia. Retrieved October 11, 2006, from http://www.webopedia.com/TERM/C/compiler.html
Compiler. (2006). In Wikipedia, The Free Encyclopedia. Retrieved October 11, 2006, from http://en.wikipedia.org/w/index.php?title=Compiler&oldid=80383765
Compiler. (2000). www.whatis.com. Retrieved October 11, 2006, from http://searchwinit.techtarget.com/sDefinition/0,,sid1_gci211824,00.html