After looking at a large number of messages about the difference between compilers and interpreters, I still cannot understand the difference in their construction and internal mechanism.
The most common difference that I read is that the compiler creates a target program that is executable (meaning machine code as its output) that can work on the system and be served using input. While the interpreter simply starts entering line by line {what exactly is happening here?} And it produces the result.
My main doubts:
1) The compiler consists of a lexical analyzer, analyzer, intermediate code generator and code generator, but what are the parts of the interpreter?
2) Who provides support during the execution of interpreted languages, I mean, who manages the heap and stacks for recursive functions?
3) This is specific to the Python language:
Python includes a compiler stage, as well as an interpreter stage, the compiler creates some bytecode, and this bytecode is interpreted by its virtual machine. if I were to create only a compiler for Python (Python -> bytecode)
a) will I need to manage the memory {write code to control the stack and heap} for it?
b) how does this compiler differ from the traditional compiler or does the interpreter say?
I know this is a lot to ask here, but I really want to understand these smallest details.
I mean the compiler book Alfred W. Aho
Based on reviews and some additional research, I think I should change my question
The compiler should not output only machine code as output
But one question is still listening to me. Let's say I want to create a compiler (Python-> bytecode), and then the bytecode will be interpreted by the virtual machine. (Correct me if I am wrong).
Then I will have to write a lexical analyzer for Python, and then a parser that will generate some kind of abstract syntax tree. After that, do I need to generate some intermediate code (the 3-address code mentioned in the book of dragons) or a direct bytecode (which, I believe, will be given in the VM documentation)?
Do I have to write code to handle the stack to provide support for recursion and scope?