Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compiler vs interpreter ( on basis of construction and design )

Tags:

People also ask

What is compiler design and construction?

Compiler Design and Construction. The design and construction of a computer program (or set of programs) that translates text written in a computer language (the source language) into another computer language (the target language).

What is compiler in construction?

Compiler construction is a complex task. A good compiler combines ideas from formal language theory, from the study of algorithms, from artificial intelligence, from systems design, from computer architecture, and from the theory of programming languages and applies them to the problem of translating a program.

What are the advantages of compiler over interpreter in order to design or construction?

Advantages: Compiler over Interpreter An intermediate code is also known as the Object code generated which can then be used each time the program is to be run, thus eliminating the need for compiling the source program each time. Compiling a program is usually faster than interpreting it.


After viewing lots of posts about the difference between compilers and interpreters, I'm still not able to figure out the difference in their construction and internal mechanism.

The most common difference I read was that a compiler produces a target program which is executable { means machine code as its output } which can run on a system and than be fed with input. Whereas an interpreter simply runs the input line by line { what exactly is happening here ?} and produces the output.

My main doubts are :

1) A compiler consists of a lexical analyzer, parser, intermediate code generator and code generator but what are the parts of an interpreter?

2) Who gives the run-time support to interpreted languages, I mean who manages the heap and stacks for recursive functions?

3) This is specific to the Python language:
Python comprises of a compiler stage and than interpreter stage as well compiler produces some byte-code and and than this byte-code is interpreted by its Virtual Machine.
if I were to design only the compiler for Python (Python -> bytecode)

a) will I have to manage memory { write code to manage stack and heap } for it?

b) how will this compiler differ from the traditional compiler or say interpreter?

I know this is a whole lot to ask here but I really want to understand these minute details.

I'm referring the compiler book by Alfred V. Aho


Based on the feedback and some further study I think I should modify my question

A compiler need not produce only machine code as its output

But one question is still bugging me Let say I want to design a ( Python->bytecode ) compiler and then bytecode will be interpreted by the virtual machine.. (correct me if I'm wrong ).
Then I'll have to write a lexical analyzer for Python and then a parser which will generate some sort of abstract syntax tree.. after this do I have to generate some intermediate code (3 address code as mentioned in the dragon book) or direct bytecode instructions ( which I suppose will be given in the VM's documentation ) ?

Will I have to write code for handling stack as well to provide support for recursion and scope ?