Compiler Construction Lecture 1
Compiler Construction Lecture 1
Introduction to Compiler
What is Compiler?
A compiler is a computer program that transforms code written in a high-
level programming language into the machine code. It is a program
which translates the human-readable code to a language a computer
processor understands (binary 1 and 0 bits). The computer processes the
machine code to perform the corresponding tasks.
A compiler should comply with the syntax rule of that programming
language in which it is written. However, the compiler is only a program
and cannot fix errors found in that program. So, if you make a mistake,
you need to make changes in the syntax of your program. Otherwise, it
will not compile.
What is Interpreter?
An interpreter is a computer program, which coverts each
high-level program statement into the machine code. This
includes source code, pre-compiled code, and scripts. Both
compiler and interpreters do the same job which is
converting higher level programming language to machine
code. However, a compiler will convert the code into
machine code (create an exe) before program run.
Interpreters convert code into machine code when the
program is run.
Key Difference
Correctness
Speed of compilation
Preserve the correct the meaning of the code
The speed of the target code
Recognize legal and illegal program constructs
Good error reporting/handling
Code debugging help
Why use a Compiler?
Compiler verifies entire program, so there are no syntax or semantic errors
The executable file is optimized by the compiler, so it is executes faster
Allows you to create internal structure in memory
There is no need to execute the program on the same machine it was built
Translate entire program in other language
Generate files on disk
Link the files into an executable format
Check for syntax errors and data types
Helps you to enhance your understanding of language semantics
Helps to handle language performance issues
Opportunity for a non-trivial programming project
The techniques used for constructing a compiler can be useful for other purposes
as well
History of Compiler