Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Important Definitions for Mid

Lecture#1

What is Compiler?

A program that translates the source program to an executable


program (machine program) is called compiler.

OR

A compiler is a special program that translates a programming


language's source code into machine code, byte-code or another
programming language.

Examples:

 Gcc
 clang
 javac
 go (compiler)

What is Compiler and interpreter and Assembler?


Compiler:
A compiler is a software program that follows the syntax rule of
programming language to convert a source code to machine code. A
compiler converts complete source code into machine code at once.
And finally, your program get executes.
Interpreter:
An interpreter is also a software program that translates a source code
into a machine language. However, an interpreter converts high-level
programming language into machine language line-by-line while
interpreting and running the program.
Assembler:
An Assembler is a software program that translates an assembly level
code to machine readable code. Assembler generally does not convert
complete code at one time. The output of assembler is binary code.

Write the Six phases of Compiler.

All 6 phases of Compiler are:

 Lexical/Sequential/Linear Analysis or Scanning


 Syntax/Hierarchical Analysis or Parsing
 Semantic Analysis
 Intermediate Code Generation
 Code Optimization
 Target/Final Code Generation

Write the classification of Compiler.

 Single pass compiler passes each compilation unit only once


translating each part immediately into its final machine code
 Multi-pass compiler processes the source code or abstract syntax
tree of a program several times
 Load & Go produces absolute code that is executed immediately
upon compilation or object code. Load & Go compiler uses a
number of passes to translate the source program into absolute
code

• Debugger helps to identify errors. Debuggers are required as run


time errors do not give very helpful information.

Lecture#2

Explain the phases of Compiler.

The compilation process contains the sequence of various phases. Each phase takes
source program in one representation and produces output in another representation.
Each phase takes input from its previous stage.
There are the six phases of compiler:

Lexical Analysis:

Lexical analyzer phase is the first phase of compilation process. It takes


source code as input. It reads the source program one character at a
time and converts it into meaningful lexemes. Lexical analyzer
represents these lexemes in the form of tokens.

Syntax Analysis

Syntax analysis is the second phase of compilation process. It takes


tokens as input and generates a parse tree as output. In syntax analysis
phase, the parser checks that the expression made by the tokens is
syntactically correct or not.

Semantic Analysis

Semantic analysis is the third phase of compilation process. It checks


whether the parse tree follows the rules of language. Semantic analyzer
keeps track of identifiers, their types and expressions. The output of
semantic analysis phase is the annotated tree syntax.

Intermediate Code Generation

In the intermediate code generation, compiler generates the source


code into the intermediate code. Intermediate code is generated
between the high-level language and the machine language. The
intermediate code should be generated in such a way that you can
easily translate it into the target machine code.
Code Optimization

Code optimization is an optional phase. It is used to improve the


intermediate code so that the output of the program could run faster
and take less space. It removes the unnecessary lines of the code and
arranges the sequence of statements in order to speed up the program
execution.

Code Generation

Code generation is the final stage of the compilation process. It takes


the optimized intermediate code as input and maps it to the target
machine language. Code generator translates the intermediate code
into the machine code of the specified computer.

Example:
What is Symbol Table ?

Symbol table is an important data structure used in a compiler.

Symbol table is used to store the information about the occurrence of


various entities such as objects, classes, variable name, interface,
function name etc. it is used by both the analysis and synthesis phases.
It is used to implement type checking by verifying assignments and
expressions in the source code are semantically correct.

What is Error Handling?

Detection of different Errors which Correspond to All Phases. An Error is


the blank entries in the symbol table. Errors in the program should be
detected and reported by the parser. Whenever an error occurs, the
parser can handle it and continue to parse the rest of the input.

What Kinds of Errors Are Found During the Analysis Phase?

A program may have the following kinds of errors during analysis


phase:

Lexical: name of some identifier typed incorrectly. 

Syntactical: missing semicolon or unbalanced parenthesis. 

Semantical: incompatible value assignment.

What Happens When an Error Is Found?

Compilation error refers to a state when a compiler fails to compile a


piece of computer program source code, either due to errors in the
code, or, more unusually, due to errors in the compiler itself. A
compilation error message often helps programmers debugging the
source code.

You might also like