+ 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
33 Answers
+ 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.
+ 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... :)
+ 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.
+ 26
compiler compile whole program at a time.
interpreter checks line by line
+ 15
compiler:-compile whole program and then executes
used in C,C++
interpreter:- compiles instructions by instructions.
used in Python and Ruby
+ 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.
+ 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
+ 12
compiler checks the whole program and then shows error and interpreter checks the program line by line and then shows error
+ 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")...
+ 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
+ 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).
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 4
compiler complies the whole program at a time while interpreter complies the code line by line
+ 3
Just to remember , the python interpreter is written in the C language. šš
+ 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
+ 3
Great Explanationšāššthanks