Skip to main content

Compilers & Interpreters

Compilers & Interpreters

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.

topic 4.1

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.

Role of Compiler

  • Compliers reads the source code, outputs executable code
  • Translates software written in a higher-level language into instructions that computer can understand. It converts the text that a programmer writes into a format the CPU can understand.
  • The process of compilation is relatively complicated. It spends a lot of time analyzing and processing the program.
  • The executable result is some form of machine-specific binary code.

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.

topic 4.1

Role of Interpreter

  • The interpreter converts the source code line-by-line during RUN Time.
  • Interpret completely translates a program written in a high-level language into machine level language.
  • Interpreter allows evaluation and modification of the program while it is executing.
  • Relatively less time spent for analyzing and processing the program
  • Program execution is relatively slow compared to compiler

Difference between Compiler and Interpreter

Basis of difference   

Compiler     

Interpreter

Programming Steps· Create the program.

· Compile will parse or analyses all of the language statements for its correctness. If incorrect, throws an error

· If no error, the compiler will convert source code to machine code.

· It links different code files into a runnable program(know as exe)

· Run the Program

· Create the Program

· No linking of files or machine code generation

· Source statements executed line by line DURING Execution

Advantage   The program code is already translated into machine code. Thus, it code execution time is less.Interpreters are easier to use, especially for beginners.
Disadvantage                       You can’t change the program without going back to the source code.Interpreted programs can run on computers that have the corresponding interpreter.
Machine code           Store machine language as machine code on the disk           Not saving machine code at all.
Running timeCompiled code run fasterInterpreted code run slower
Model                       It is based on language translation linking-loading model.It is based on Interpretation Method.
Program generationGenerates output program (in the form of exe) which can be run independently from the original program.Do not generate output program. So they evaluate the source program at every time during execution.
Execution                 Program execution is separate from the compilation. It performed only after the entire output program is compiled.Program Execution is a part of Interpretation process, so it is performed line by line.
Memory requirement            Target program execute independently and do not require the compiler in the memory.The interpreter exists in the memory during interpretation.
Best suited for                       Bounded to the specific target machine and cannot be ported. C and C++ are a most popular a programming language which uses compilation model.For web environments, where load times are important. Due to all the exhaustive analysis is done, compiles take relatively larger time to compile even small code that may not be run multiple times. In such cases, interpreters are better.

Comments