0% found this document useful (0 votes)
96 views

L1 - Overview of Compiler Construction

The document provides an overview of compiler construction, including the motivation for studying compilers and their various components. It discusses how compilers map a program's specifications to architectural details using techniques from various computer science domains. The key stages covered are lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. The goal is to generate efficient machine code from the source code.

Uploaded by

fufyipufye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

L1 - Overview of Compiler Construction

The document provides an overview of compiler construction, including the motivation for studying compilers and their various components. It discusses how compilers map a program's specifications to architectural details using techniques from various computer science domains. The key stages covered are lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. The goal is to generate efficient machine code from the source code.

Uploaded by

fufyipufye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Complier Construction: Motivation and

Overview
Shashank Gupta
BITS Pilani Assistant Professor
Pilani Campus
Department of Computer Science and Information Systems
Key Points to be Covered
• Motivation for Studying the Compiler
• Overview of Compiler
• Organisation of the Course

CS F363 Compiler Construction 2


BITS Pilani, Pilani Campus
Motivation for Studying the
Compiler
• Numerous Applications for Compiler Technology.

Parsers Interpreters

Machine
S/W
Code
Engineering
Generation

Suspicious Designing of
Code Computer
Detection Architectures
3
CS F363 Compiler Construction BITS Pilani, Pilani Campus
Complexity of Compiler
Technology

The complexity of a compiler arises from the fact that it is


required to map a program specifications to architectural details.

Uses algorithms and techniques from different domains of


Computer Science.

Emphasizes on Tool Building.

4
CS F363 Compiler Construction BITS Pilani, Pilani Campus
Nature of Compiler Algorithms

Finite Pushdown Graph Greedy Dynamic Complex Data


Automata Automata Algorithms Algorithms Programming Structures
• Lexical • Parsing • Dead Code • Register • Instruction • Symbol
Analysis Elimination Allocation Selection Tables, Parse
Trees,

5
CS F363 Compiler Construction BITS Pilani, Pilani Campus
Language Processing System

6
CS F363 Compiler Construction BITS Pilani, Pilani Campus
Overview of Compiler

7
CS F363 Compiler Construction BITS Pilani, Pilani Campus
Compilers vs Interpreters

Compilers generate machine code, whereas


interpreters interpret intermediate code.

Interpreters are easier to write.

Perl, Python, Unix Shell, etc. are all Interpreter-


based languages.
CS F363 Compiler Construction 8
BITS Pilani, Pilani Campus
Translation Overview of Lexical
Analysis

9
CS F363 Compiler Construction BITS Pilani, Pilani Campus
Lexical Analysis (LA)

LA can be generated automatically from regular


expression specifications.

LEX and flex are two tools that works as a lexical


analyzer.

LA is a Deterministic Finite State Automaton.

CS F363 Compiler Construction 10


BITS Pilani, Pilani Campus
Translation Overview of Syntax
Analysis

11
CS F363 Compiler Construction BITS Pilani, Pilani Campus
Parsing or Syntax Analysis

Syntax analyzers can be generated


automatically from Context-Free Grammar.

Parsers are Deterministic Push-down


Automata.

It cannot handle context-sensitive features of


programming languages.

CS F363 Compiler Construction 12


BITS Pilani, Pilani Campus
Translation Overview of Semantic
Analysis

13
CS F363 Compiler Construction BITS Pilani, Pilani Campus
Semantic Analysis

Type Checking

Stores type information in the


symbol table or the syntax tree.

Type Variables, function


parameters, array dimensions, etc.

CS F363 Compiler Construction 14


BITS Pilani, Pilani Campus
Translation Overview of
Intermediate Code Generation

15
CS F363 Compiler Construction BITS Pilani, Pilani Campus
Types of Intermediate Code
Generation

Quadruples, triples, indirect triples, Abstract Syntax


Trees (AST) are the classical forms.

Static Single Assignment Form (SSA) is a recent


form and enables more effective optimizations.

Program Dependence Graph (PDG) is useful in


automatic parallelization, instruction scheduling, etc.

CS F363 Compiler Construction 16


BITS Pilani, Pilani Campus
Intermediate Code Generation

Generating machine code directly from source code


is possible, but it includes two problems:
• With p languages and q target machines, we need to write p *q
compilers.
• The code optimizer is one of the largest and very difficult to
write component of any compiler cannot be reused.
By converting source code to an intermediate code, a
machine independent code optimizer may be written.

CS F363 Compiler Construction 17


BITS Pilani, Pilani Campus
Translation Overview of Code
Optimization

CS F363 Compiler Construction 18


BITS Pilani, Pilani Campus
Machine-Independent Code
Optimization

Intermediate Code Generation


introduces many inefficiencies.

Extra copies of variables, using


variables instead of constants, etc.

Code Optimization removes such


inefficiencies and improves code.

CS F363 Compiler Construction 19


BITS Pilani, Pilani Campus
Examples of Machine-Independent
Optimizations

Common sub-expression elimination

Loop invariant
Copy Propagation
code motion

Partial Induction
Strength
redundancy Variable
Reduction
elimination Elimination
CS F363 Compiler Construction 20
BITS Pilani, Pilani Campus
Translation Overview of Code
Generation

CS F363 Compiler Construction 21


BITS Pilani, Pilani Campus
Code Generation

Converts intermediate code into machine code.

Must handle all aspects of machine architecture.

Storage Allocation Decisions are also done here.

CS F363 Compiler Construction 22


BITS Pilani, Pilani Campus
Machine Dependent Optimization

Peephole Optimizations
• Analyze sequence of instructions in a small
window (peephole) and using preset patterns,
replace them with a more efficient sequence.
• Redundant Instruction Elimination
• Eliminate “Jump to Jump” Instruction.

CS F363 Compiler Construction 23


BITS Pilani, Pilani Campus
Thank You

13
CS F363 Compiler
BITS Pilani, Pilani Campus

You might also like