Interpreter Vs Compiler




            By : Aya Yakout Alkhamese



                      Compiler
                           4th
Dept : Computer Science & Information Technology
    Faculty of Science – Portsaid Univeristy
• Interpreter Vs Compiler

 Programming languages can be divided into two major categories: low level and
  high level. “Assembly language” and “machine language” are called low-level
  languages because they more than others “speak” the language the computer
  understands. On the other hand, C, C++, Pascal,Python, Visual Basic, Java,
  and COBOL are high-level languages because they require more manipulation by
  the computer, a process called compiling.



    When writing programs in a high level language, the computer will not be able
    to understand it. So that it will be usable, you need to convert it into
    something that a computer understands. This is where compilers and
    interpreters come in as they both do the same function – convert a high level
    language (like C, Java) instructions into the binary form which is
    understandable by computer hardware. They are the software used to execute
    the high level programs and codes to perform various tasks. Specific
    compilers/interpreters are designed for different high level languages.
    However both compiler and interpreter have the same objective but they
    differ in the way they accomplish their task



 An interpreter :

 reads the source code one instruction or line at a time, converts this line into
  machine code and executes it. The machine code is then discarded and the next line
  is read. executing each line as it is "translated," much the way a foreign language
  interpreter would translate a book, by translating one line at a time.
 The interpreter takes one statement then translates it and executes it and then
  takes another statement.
 interpreter stops translating after the first error.
 Programming Steps for Interpretion :
                      •   Edit the Program
                      •   No linking
                      •   No object code generated
                      •   Source statements executed line by line
 The advantage of this is that :
                    • Interpreters however are easier to use, particularly for
                         beginners, since errors are immediately displayed, corrected
                         by the user, until the program is able to be executed.
                    • you can interrupt it while it is running, change
                         the program and either continue or start again.




   The disadvantage of this is that :
                      • every line has to be translated every time it is executed,
                         even if it is executed many times as the program runs.
                         Because of this interpreters tend to be slow. that
                         interpreted programs run much slower than compiled
                         programs. As much as 5-10 times slower as every line of
                         code has to be re-read, then re-processed.
                      • interpreted programs can only run on computers that also
                         have the interpreter.



    Examples of interpreters are Basic on older home computers, and script
    interpreters such as JavaScript, and languages such as Lisp and Forth.




A compiler :
 reads the whole program (called source code) written in some high level language
  and translates code of a programming language in machine code "binarycode,", also
  called object code. The object code can be executed directly on the machine where
  it was compiled.
    a special program that analyses all the statements in a program (called source
    code) written in some high level language and links the code (using libraries) to
    produce an executable. To run the program you submit the executable which would
    produce some output. To make changes in the program you must repeat these
    steps .
 the compiler translates the entire program in one go and then executes it.
 Compilers, on the other hand, analyse the entire program, taking note of where
  errors have occurred, and places these in an error/diagnostic file. If errors have
  occurred then the program cannot run. Programmers must then use the error
  messages to identify and remove the errors in the source code. Some compilers
  assist by adding line numbers to the source listing to help pinpoint errors .
  compilers offer programmers some advantages. compiled programs make the
  programmer wait until the program is complete.



Programming Steps for Compilation :
 Edit the Program
 parses or analyzes all of the language statements syntactically in a sequential
  manner and then, in one or more successive passes, builds the output code, ensuring
  that statements that refer to other statements are referenced correctly in the
  final code.
 Link the Machine code files into a runnable program (also known as an exe).
 Debug or Run the Program



 The advantage of this is that :
                    • the translation is done once only and as a separate process.
                         The program that is run is already translated into machine
                         code so is much faster in execution.
                    • compiled programs can run on any computer



 The disadvantage of this is that :
                    •    you cannot change the program without going back to the
                        original source code, editing that and recompiling (though
                        for a professional software developer this is more of an
                        advantage because it stops source code being copied, so
                        there’s an element of security built in to compiled
                        programs.).



 Examples of compilers are Visual Basic, C, C++, C#, Fortran, Cobol, Ada, Pascal and
  so on.
 A compiler works with what are sometimes called 3GL and higher-level languages
  (3rd-generation languages, such as Java and C
compiler vs interpreter

compiler vs interpreter

  • 1.
    Interpreter Vs Compiler By : Aya Yakout Alkhamese Compiler 4th Dept : Computer Science & Information Technology Faculty of Science – Portsaid Univeristy
  • 2.
    • Interpreter VsCompiler  Programming languages can be divided into two major categories: low level and high level. “Assembly language” and “machine language” are called low-level languages because they more than others “speak” the language the computer understands. On the other hand, C, C++, Pascal,Python, Visual Basic, Java, and COBOL are high-level languages because they require more manipulation by the computer, a process called compiling.  When writing programs in a high level language, the computer will not be able to understand it. So that it will be usable, you need to convert it into something that a computer understands. This is where compilers and interpreters come in as they both do the same function – convert a high level language (like C, Java) instructions into the binary form which is understandable by computer hardware. They are the software used to execute the high level programs and codes to perform various tasks. Specific compilers/interpreters are designed for different high level languages. However both compiler and interpreter have the same objective but they differ in the way they accomplish their task  An interpreter :  reads the source code one instruction or line at a time, converts this line into machine code and executes it. The machine code is then discarded and the next line is read. executing each line as it is "translated," much the way a foreign language interpreter would translate a book, by translating one line at a time.  The interpreter takes one statement then translates it and executes it and then takes another statement.  interpreter stops translating after the first error.  Programming Steps for Interpretion : • Edit the Program • No linking • No object code generated • Source statements executed line by line
  • 3.
     The advantageof this is that : • Interpreters however are easier to use, particularly for beginners, since errors are immediately displayed, corrected by the user, until the program is able to be executed. • you can interrupt it while it is running, change the program and either continue or start again.  The disadvantage of this is that : • every line has to be translated every time it is executed, even if it is executed many times as the program runs. Because of this interpreters tend to be slow. that interpreted programs run much slower than compiled programs. As much as 5-10 times slower as every line of code has to be re-read, then re-processed. • interpreted programs can only run on computers that also have the interpreter.  Examples of interpreters are Basic on older home computers, and script interpreters such as JavaScript, and languages such as Lisp and Forth. A compiler :  reads the whole program (called source code) written in some high level language and translates code of a programming language in machine code "binarycode,", also called object code. The object code can be executed directly on the machine where it was compiled.  a special program that analyses all the statements in a program (called source code) written in some high level language and links the code (using libraries) to produce an executable. To run the program you submit the executable which would produce some output. To make changes in the program you must repeat these steps .
  • 4.
     the compilertranslates the entire program in one go and then executes it.  Compilers, on the other hand, analyse the entire program, taking note of where errors have occurred, and places these in an error/diagnostic file. If errors have occurred then the program cannot run. Programmers must then use the error messages to identify and remove the errors in the source code. Some compilers assist by adding line numbers to the source listing to help pinpoint errors . compilers offer programmers some advantages. compiled programs make the programmer wait until the program is complete. Programming Steps for Compilation :  Edit the Program  parses or analyzes all of the language statements syntactically in a sequential manner and then, in one or more successive passes, builds the output code, ensuring that statements that refer to other statements are referenced correctly in the final code.  Link the Machine code files into a runnable program (also known as an exe).  Debug or Run the Program  The advantage of this is that : • the translation is done once only and as a separate process. The program that is run is already translated into machine code so is much faster in execution. • compiled programs can run on any computer  The disadvantage of this is that : • you cannot change the program without going back to the original source code, editing that and recompiling (though for a professional software developer this is more of an advantage because it stops source code being copied, so there’s an element of security built in to compiled programs.).  Examples of compilers are Visual Basic, C, C++, C#, Fortran, Cobol, Ada, Pascal and so on.  A compiler works with what are sometimes called 3GL and higher-level languages (3rd-generation languages, such as Java and C