+ 43

Compilers and interpreters

I've just started learning python after c++ and found out that python uses interpreters instead of compilers Now I'm curious about the difference between them

1st May 2018, 8:31 AM
Danny Rosso
Danny Rosso - avatar
33 Réponses
+ 43
Compiling checks the code before runtime, interpreting at runtime. This makes compiled languages faster at runtime and most of the time compiled languages are more typesafe. That said it is faster to develop most of the times in a interpreted language like python, with less characters.
1st May 2018, 8:33 AM
***
*** - avatar
+ 34
Compilers convert the entire program into machine level code at once if there aren't any errors. And informs you of the errors beforehand (before executing the program). Where as Interpreters convert and execute the instructions line by line and inform you of the errors in the intermediate lines during execution of the program. In simple terms, compiler is like stuffing an entire pan cake into your mouth and interpreter is like eating the pan cake bits by bits! 😂 Hope my answer was helpful... :)
2nd May 2018, 3:34 PM
G P
G P - avatar
+ 31
Interpreter➡️ Translates program one statement at a time. compiler➡️ Scans the entire program and translates it as a whole into machine code. interpreter➡️ It takes less amount of time to analyze the source code but the overall execution time is slower. compiler➡️ It takes large amount of time to analyze the source code but the overall execution time is comparatively faster. interpreter➡️ No intermediate object code is generated, hence are memory efficient. compiler➡️ Generates intermediate object code which further requires linking, hence requires more memory. interpreter➡️ Continues translating the program until the first error is met, in which case it stops. Hence debugging is easy. compiler➡️ It generates the error message only after scanning the whole program. Hence debugging is comparatively hard.
2nd May 2018, 3:34 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 26
compiler compile whole program at a time. interpreter checks line by line
2nd May 2018, 3:07 PM
Harshakumar T P
+ 15
compiler:-compile whole program and then executes used in C,C++ interpreter:- compiles instructions by instructions. used in Python and Ruby
2nd May 2018, 3:20 PM
Elliot
Elliot - avatar
+ 13
Compilers, assemblers and interpreters are all programs that take the source code of a programming language, written by a programmer, and make it run on a computer. Computer CPUs are too primitive to directly run the commands of any language that a human would actually use. They can only run a thing called ‘machine code’, which is the binary ones and zeroes that everybody thinks of, when we say ‘computer’. The lines between the three are quite blurred, these days. Traditionally, it went like this: A compiler is a program which coverts the source code of a programming language into executable machine code for a CPU.An assembler does the same thing, except it works on the assembly language used to describe the machine code of a CPU. This is a much simpler language, and so an assembler is far simpler to write than a compiler.An interpreter takes each line of source code of a programming language, and executes it there and then. It goes on to do the same for the next line afterwards. In this traditional view of the world, interpreters run programs more slowly than compiled or assembled ones. But in the modern world, it’s no longer quite true. Take Java, for example. Java source code is compiled by a program called javac. But it does not produce executable machine code for a CPU. It produced ‘byte code’, which is a kind of universal machine code. Because byte code does not run natively on nearly all CPUs, it must be run on some other program which converts it. in java, this is the Java Virtual Machine, or JVM. So you had compiled Java->Bytecode, which was then interpreted. Modern JVMs take the bytecode, and profile which parts are run most often, then compile the bytecode into actual machine code for that CPU. So they are cross between a compiler and an interpreter, and a virtual CPU. Microsoft .NET technologies are similar to this. The details seem a bit confusing, but just remember - they all turn what programmers write into something a computer can actually run.
2nd May 2018, 3:42 PM
MsJ
MsJ - avatar
+ 13
Danny Rosso , compiler and interpreters is a big topic in computer science but i will write some brief about it compiler :as we know about symbol table creation,Laxical analysis,syntax analysis, semantic analysis,and then semantic tree to assembly level code conversation is done for particular cpu architecture assembly. Then assembly code is converted into machine level that we call as like assembly to machine code.every machine(computer) has its architecture based assembly instruction set and this instruction code has some hex representation.and we know computer understand everything into binary so hex code now converted into binary. Some compiler optimized the assembly code to save time and space(time-space tradeoff). This above mentioned desc is about how machine can understand your high level language input program.this all things happen in background within nanosecond or nth part of nanosecond. now we know that compiler has two part front end ,back end. In front end all the lexical analysis to semantic analysis part is done.in back end part all the data structure related work is done.and how engine control this things is available in back end. Compiler have 2 pass to run the program. Pass-I: generate the symbol table for our program. (Give Error like :forward reference,related to syntax and all that. Pass-II: using symbol table help and with our source code ,actually source code converted into token and token converted into lexemas. And lexemas to syntax tree and all the task is perform one by one untill end of the file(in souce code) and the output is we show on the screen or console. like c,c++,....etc interpreter: in one pass the all work is done that we mentioned above. the statement is main entity to work in interpreter. process goes on statement by statement. like python,java(bytecode runtime (ji)......etc Thank you for your question. if you find any bug ,please comment i will correct it soon. ☕☕ Asif Bilakhiya
3rd May 2018, 1:45 AM
ASIF BILAKHIYA
ASIF BILAKHIYA - avatar
+ 12
compiler checks the whole program and then shows error and interpreter checks the program line by line and then shows error
4th May 2018, 5:41 AM
Prabhat
Prabhat - avatar
+ 8
A compiler takes in a source code and spits out an executable file (e.g .exe)... A interpreter takes in a source code and runs it line by line, without any extra executable created (like Python and perl and almost ever other language that starts with "P")...
2nd May 2018, 3:48 PM
David Ajaba
David Ajaba - avatar
+ 8
the compiler takes the whole code as input but interpreter takes only one line at a time so that is why the compiler is efficient but the interpreter is memory efficient.debugging is very easy in the interpreter because when any error hits so it stops the execution
2nd May 2018, 9:09 PM
Gourav raghuwanshi
Gourav raghuwanshi - avatar
+ 8
If I remember well a compiler first translates the code into machine language then it executes the code whereas an interpreter "translates" and executes a line before repeating the same process until the last line of code.Therefore (little remark)a compiled language is generally faster then an interpreted one :is like reading a book after translating it from a foreign language into inglish. You read it faster then if you'd translate and read immediately after each line(count only the reading time not the translation time).
2nd May 2018, 11:49 PM
Uni
Uni - avatar
+ 8
The compiler compiles the program, i.e. before running the program it checks the code for errors and transforms it to the machine code. The interpreter interprets the code, i.e. during the runtime reads a line by line and in the event of an errors, it stops the program.
3rd May 2018, 9:18 AM
Piotr
Piotr - avatar
+ 5
In my understand, a compiler check if the program is correct in sintaxis and logical, then links every part of the program and then it's executed. When the program is compiled it can be executed in almost every machine without needed compiler or interpreter. indifference with the compiler the interpreter need to be installed in the computer in use. If you don't have any interpreter of the program, you can't use your program. If I'm not wrong, I believe that is the way of working compiler and interpreter.
2nd May 2018, 6:05 PM
David Rueda 🇪🇸
David Rueda  🇪🇸 - avatar
+ 5
Compiler: 👉It can check program in one go. 👉All the errors are reflected after checking entire program at last. 👉First time during execution of program compiler is required. 👉Compiler is faster and generally used for expert programming. Interpreter: 👉It convert program line by line checking the errors in each line. 👉It reflects the error after checking each line and it will not go to the next line until the error is corrected. 👉Interpreter must be present in memory each time program is executed. 👉Interpreter is better if chances of errors are more. 👉👉The combination of interpreter and compiler is best.
3rd May 2018, 10:20 AM
Mani Tiwari
Mani Tiwari - avatar
+ 4
Compiler: a program that converts instructions into a machine-code or lower-level form so that they can be read and executed by a computer. Intepreter: computer program that directly executes, i.e. performs, instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program.
3rd May 2018, 3:37 AM
Hardik
Hardik - avatar
+ 4
The differences between Compilers and Interpreters. Compilers : 1) Compilers translates the entire program code into machine code. That is a Compiler translates instructions directly into machine code. Therefore the Compiler produces faster programs. 2) Compilers require more memory because of the object code produced. 3) Compiler displays all errors and warnings making debugging harder. Interpreters : 1) Translates program one statement of code at a time, therefore taking some time to translate entire program. 2 ) No object code, therefore more memory efficient. 3) Debugging is easier because interpreter stops at very first error.
3rd May 2018, 6:38 AM
Rick Zalman
+ 4
compiler complies the whole program at a time while interpreter complies the code line by line
3rd May 2018, 1:05 PM
Tanishka Vaidya
Tanishka Vaidya - avatar
+ 3
Just to remember , the python interpreter is written in the C language. 😉😊
2nd May 2018, 5:53 PM
Shubham Sharma
Shubham Sharma - avatar
+ 3
compiler are used to convert the program from HLL to machine language in one go. They report all the errors same time and help in fast execution On the other hand interpreter convert HLL to machine language and report errors line by line in a sequential manner They are good in accuracy of programme
3rd May 2018, 6:55 AM
Amit Kumar
Amit Kumar - avatar
+ 3
Great Explanation🙏✌👏😊thanks
3rd May 2018, 9:13 AM
Saeed Mozaffari
Saeed Mozaffari - avatar