Compilation vs Interpretation in Programming

SubstantiveHarmonica avatar
SubstantiveHarmonica
·
·
Download

Start Quiz

Study Flashcards

8 Questions

What is the output of a compiler?

Object code

What is the role of the scanner in a compiler?

To read in the source program and break it into tokens

What is the brain of the compiler?

Parser

What is the main difference between a compiler and an interpreter?

A compiler translates the entire program at once, while an interpreter translates line by line

Which of the following is an example of an interpreted language?

JavaScript

What is the role of the parser in a compiler?

To know the syntax and semantics of the source language

What is the equivalent of the code generator in an interpreter?

Executor

What is the purpose of the code generator in a compiler?

To generate object code

Study Notes

Compilation and Interpretation of Programs

  • A compiler translates a high-level language program into an intermediate form called object code, which can be directly executed by the machine.
  • An interpreter does not produce object code, but translates the source program line by line into machine language.

Examples of Compiled and Interpreted Languages

  • Examples of compiled languages include: C, C++, C#, Ada, ALGOL, Java, COBOL, Visual Basic, Lisp, FORTRAN, Pascal
  • Examples of interpreted languages include: QBASIC, JavaScript, PHP, ASP, APL

How a Compiler Works

  • The parser is the brain of the compiler, knowing the syntax and grammatical rules of the source language.
  • The parser uses a scanner to read in source program statements and break them into a sequence of tokens (words, numbers, identifiers, operators, etc.).
  • The parser calls the code generator to produce object code, which performs the operation specified by the instruction.
  • The process continues until the entire program has been read in and translated.

How an Interpreter Works

  • An interpreter also has a parser that controls it, with a scanner that does the same job as the compiler's scanner.
  • Instead of a code generator, an interpreter has an executor that directly executes the translated code.
  • The interpreter translates the source program line by line into machine language, without producing object code.

Learn about the difference between compilation and interpretation in programming languages, including examples of compiled languages such as C, C++, and Java.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser