what is Compiler and interpreter?

 what is compiler and interpreter?

as we know that computer only understands machine language.it can't understand any other language. And high-level programming languages is not understandable by computer system. Therefore, in order to communicate with computer system, we need a translator. Which translate high level programming languages into machine language.in order to translate high level programming languages into machine language we use compiler and interpreter as a translator.

a compiler and interpreter are a tool which is used to translate high level programming languages into machine language.

what is Compiler and Interpreter?

what is compiler?

a compiler is a program that translate source code (the code which is written in programming language) into machine code. This source code is written in high level programming language like c,c++,java etc. which is easily understandable by the programmer. But computer is not understanding this source code.an compiler translate entire code and after this it create an object file.

how does compiler work:

compilation process consists of various phases:

  • lexical analysis:  it is the first phase of compilation process.during this phase,the compiler splits source code into fragments called lexemes.alexemes is an abstracts unit of a specific language's lexicalsystem.

  • syntax analysis: it is the second phase of compilation process.during this phase,the compiler uses  a sequence of tokens generated in the first phase.tokens are use to create a structure called abstract synatax tree.which is a tree that represents the logical structure of a program.gernally an syntax analysis check the sorce code for any synatx error and it generates abstract syntax tree that the next stage uses.
  • sementic analysis: it is the third phase of compilation process .in this phase ,the compiler uses an abstract syntax tree to detect any sementic errors .ex: assigning the wrong type to a variable,using an undeclared variable.sementic analysis contain three checkings i.e type checking,flow checking,label checking.
  • I.R. code generation: after the code passes through all three phases, the compiler generates an intermediate representation (I.R.) of the source code. The I.R. code makes it easier to translate the source code into a different format.
  • optimization: the compile optimizes the I.R. code in preparation of the final code generation. The type and extent of optimization depends on the computer.

what is interpreter?


an interprator is a program that directly executes the instructions in a high level language,without converting it into machine code.in programming,we can execute a program in two ways.firstly through compilation and secondly,through an interprater.


types of an interpreters:

  • bytecode interpreters: in this type of interpreter the source code firstly converted to bytecode. Bytecode is a compressed and optimized representation of a source code.but,it is not the machine code. The bytecode interpreters the execute this compiled code. Compiler and interpreters then execute this compiled code. Compilers and interpreter both are used hence, the name 'completers'. An interpreter has up to 256 instructions.
  • threaded code interprets: similar to bytecode interpreters buttery use pointers. Each instruction is a word acting as a pointer. This pointer points to a function or instruction sequence. There is no restriction on the number of instructions.
  • abstract syntax tree interpreters: it converts the source code to an abstract syntax tree (AST). then it executes the program according to this tree. Each sentence is parsed just once. The program structure and the relation between statements remain the same. Provides better analysis during run time.
  • self-interpreters: these are a special type of interpreters. They are programming language interpreters written in a programming language that can interpret itself.an example can be a BASIC interpreter written in BASIC. Self-interpreters are created in case if no compiler exists for a language. Their creation requires the implementation of that language in a host language. this host language can be another programming language.



Post a Comment

Previous Post Next Post