What is the difference between interpreter and compiler ?
Hi Gary, this is my (rough) understanding. in a compiled language your source code needs to be translated in machine-language before it can be executed. Roughly, the compiler needs to read the program completely, to be able to parse it, and to build an object that can be executed. In an interpreted language this step ("traduction in machine-language") is done in a sequential way, so to say instruction-by-instruction. This is why you can interact with your shell in Python, and you cannot in C++, for instance. (This said, the advantage of a compiled language is that the memory resources can be allocated much more efficiently, so the program usually speeds up in execution time.)
Here is my understanding: 1. One can create an interpreter for any high-level programming language. (C/C++ interpreter do exist today.) 2. One can create an interpreter for any low-level machine language (code) as well. The difference between a compiler and interpreter is: -- a compiler : statically sperate a program into code (read-only) or data (read-write) memory section - an interpreter: dynamically create a read-only memory section for code (or instructions). code: is a program (or instructions): load from read-only memory to instruction cache of CPU) data: is in a read-write memory area (load into data cache of CPU) (For more info: read TLB (Translation lookaside buffer), or two level TLB.)
An interpreter translates the program as it runs, a compiler translates it before it runs. An interpreter allows you to easily make a language cross-platform (like java), a compiler allows you to make the programs faster (as they run as normal executables).
Join our real-time social learning platform and learn together with your friends!