Unit 1
Unit 1
Unit 1
To become a renowned center of outcome based learning and work towards academic,
professional, cultural and social enrichment of the lives of individuals and communities
M1: Focus on evaluation of learning outcomes and motivate students to inculcate research
aptitude by project based learning.
M2: Identify, based on informed perception of Indian, regional and global needs, the areas of
focus and provide platform to gain knowledge and solutions.
M4: Develop human potential to its fullest extent so that intellectually capable and
imaginatively gifted leaders can emerge in a range of professions.
To become renowned Centre of excellence in computer science and engineering and make
competent engineers & professionals with high ethical values prepared for lifelong learning.
Problem analysis: Identify, formulate, research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural
sciences, and engineering sciences.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations. The engineer and society: Apply reasoning informed
by the contextual knowledge to assess societal, health, safety, legal and cultural issues and the
consequent responsibilities relevant to the professional engineering practice.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
COURSE OUTCOME
CO1: Compare different phases of compiler and design lexical analyzer. CO2: Examine syntax
and semantic analyzer by understanding grammars.
CO4: Analyze code optimization, code generation & compare various compilers.
CO-PO Mapping
PO2
Semester
Subject
Code
L/T/P
CO
PO1
PO3
PO4
PO5
PO6
PO7
PO8
PO9
PO10
PO11
PO12
L 1. Compare
different phases of
compiler and
design lexical
analyzer. 3 3 3 3 2 1 1 1 1 2 1 3
L 2. Examine syntax
and semantic
analyzer and
illustrate storage
allocation and its
organization 3 3 3 3 1 1 1 1 1 2 2 3
L 3. Analyze symbol
COMPILER DESIGN
table organization,
code optimization
and code generator 3 3 3 3 2 1 1 1 1 2 2 3
5CS4 - 02
L 4.Compare and
evaluate various
3 3 3 3 2 1 1 1 1 2 1 3
compilers and
analyzers
V
V
PROGRAM EDUCATIONAL OBJECTIVES:
PSO
PSO1. Ability to interpret and analyze network specific and cyber security issues, automation in
real word environment.
PSO2. Ability to Design and Develop Mobile and Web-based applications under realistic
constraints.
SYLLABUS
LECTURE PLAN:
Subject: Compiler Design (5CS4 – 02) Year/Sem: III/V
Unit
No./
Total Topics Lect. Req.
lec.
Req.
Compiler, Translator, Interpreter definition, Phase of compiler 1
Introduction to one pass & Multipass compilers, Bootstrapping 1
Unit-1
Review of Finite automata lexical analyzer, Input, buffering, 2
(6)
Recognition of tokens, Idea about LEX:, GATE Questions 1
A lexical analyzer generator, Error Handling, Unit Test 1
Review of CFG Ambiguity of grammars, Introduction to parsing 2
Bottom up parsing Top down Parsing Technique 5
Shift reduce parsing, Operator Precedence Parsing 2
Recursive descent parsing predictive parsers 1
Unit-2
(17) LL grammars & passers error handling of LL parser 1
Conical LR & LALR parsing tables 3
parsing with ambiguous grammar, GATE Questions 2
Introduction of automatic parser generator: YACC error handling in LR parsers, Unit
Test
1
1 1
UNIT-1
OVERVIEW OF LANGUAGE PROCESSING SYSTEM
TRANSLATOR:
• Translating the high Level language program input into an equivalent
machine language program.
1 2
1 3
Preprocessor
1 4
COMPILER
1 5
ASSEMBLER:
programmers found it difficult to write or read programs in machine
language. They begin to use a mnemonic (symbols) for each
machine instruction, which they would subsequently translate into
machine language. Such a mnemonic machine language is now
called an assembly language. Programs known as assembler were
written to automate the translation of assembly language in to
machine language. The input to an assembler program is called
source program, the output is a machine language translation (object
program).
Ex: MOV A,B
1 6
INTERPRETER:
1 7
Advantages:
Disadvantages:
1 8
DIFFERENCE BETWEEN COMPILER AND INTERPRETER
•A compiler converts the high level instruction into machine language while an interpreter converts the
high level instruction into an intermediate form.
•Before execution, entire program is executed by the compiler whereas after translating the first line, an
interpreter then executes it and so on.
•List of errors is created by the compiler after the compilation process while an interpreter stops
translating after the first error.
•An independent executable file is created by the compiler whereas interpreter is required by an
interpreted program each time.
•The compiler produce object code whereas interpreter does not produce object code. In the process of
compilation the program is analyzed only once and then the code is generated whereas source program
is interpreted every time it is to be executed and every time the source program is analyzed. hence
interpreter is less efficient than compiler.
1 9
Loader and Linker
1 10
Phases of a compiler
1 11
Syntax Analysis:-
The second stage of translation is called Syntax analysis or parsing. In this phase
expressions, statements, declarations etc… are identified by using the results of lexical
analysis. Syntax analysis is aided by using techniques based on formal grammar of the
programming language.
1 12
1
9
Semantic Analyzer:
It uses syntax tree and symbol table to check whether the given program is
semantically consistent with language definition. It gathers type information and stores it
in either syntax tree or symbol table. This type information is subsequently used by
compiler during intermediate-code generation.
1 14
Intermediate Code Generations:-
This phase bridges the analysis and synthesis phases of translation.
• Translate Tree structure into intermediate code
Code Optimization :-
This is optional phase described to improve the intermediate code so
that the output runs faster and takes less space.
Code Generation:-
The last phase of translation is code generation. A number of
optimizations to reduce the length of machine language program
are carried out during this phase. The output of the code generator is
the machine language program of the specified computer.
1 15
16
Error Handler
It detects and recover the error occurred in different
phases of compiler.
17
1 18
1 19
Single pass, Multi pass Compilers
• Pass : A pass refers to the traversal of a compiler through the entire
program.
20
Single Pass Compiler
21
Some Points about single pass compiler
1.A one pass/single pass compiler is that type of
compiler that passes through the part of each compilation
unit exactly once.
2.Single pass compiler is faster and smaller than the
multi pass compiler.
3.As a disadvantage of single pass compiler is that it is
less efficient in comparison with multipass compiler.
4.Single pass compiler is one that processes the
input exactly once.
29
30
Differences between Single Pass and Multipass
Compilers
31
32
33
34
35
Load & Go System
Load and go system is a programming language processor in which
the compilation, assembly, Loader, linker steps are not separated from
program Execution.EX: FORTRAN
36
Threaded Code Compiler
where each op-code in the virtual machine instruction
code is the
address of some (lower level) code to perform the required
operation. This kind of virtual machine can be implemented
efficiently in machine code on most processors by simply
performing an indirect jump to the address which is the next
instruction to be executed.
37
38
39
40
Bootstrapping
1 41
•The T- diagram shows a compiler SC IT for Source S, Target T,
implemented in I.
1 42
•Create a compiler LC A for language L written in a subset of L.
S
•Compile LC A
S
using the compiler SC A to
A
obtain LC A
A. L C A
A
is a
compiler for language L, which runs on machine A and produces
code for machine A.
1 43
•Create a compiler LC A for language L written in a subset of L.
S
•Compile LC A
S
using the compiler SC A to
A
obtain LC A
A. L C A
A
is a
compiler for language L, which runs on machine A and produces
code for machine A.
1 44
Review of Finite Automata
1 45
The mathematical model of finite automata consists of:
1 46
47
48
•States : States of FA are represented by circles. State names are written inside circles.
•Start state : The state from where the automata starts, is known as the start state. Start
state has an arrow pointed towards it.
•Intermediate states : All intermediate states have at least two arrows one pointing to
and another pointing out from them.
•Final state : If the input string is successfully parsed, the automata is expected to be in
this state. Final state is represented by double circles.
•Transition : The transition from one state to another state happens when a desired
symbol in the input is found. Upon transition, automata can either move to the next state
or stay in the same state. Movement from one state to another is shown as a directed
arrow, where the arrows points to the destination state. If automata stays on the same
state, an arrow pointing from a state to itself is drawn.
1 5
5
50
EXAMPLE DFA
51
52
53
54
55
56
57
Input Recognition of Tokens
1 58
Finite Automata For Recognizing Identifiers
1 59
Finite Automata For Recognizing digits
1 60
Finite Automata For Recognizing Relational operators
1 61
1 62
1 63
Role of Lexical Analyzer
1 64
1 65
Tasks Lexical Analyzer
1 66
Tokens , Pattern and Lexemes
1 67
Lexical Errors
1 68
1 69
7
6
LECTURE CONTENTS WITH A BLEND OF NPTEL CONTENTS
Parsing
Just like a natural language, a programming language also has a set of grammatical rules and hence
can be broken down into a parse tree by the parser. It is on this parse tree that the further steps of
semantic analysis are carried out. This is also used during generation of the intermediate language
code. Yacc (yet another compiler compiler) is a program that generates parsers in the C programming
language.
1 71
LECTURE CONTENTS WITH A BLEND OF NPTEL CONTENTS
Parsing
Just like a natural language, a programming language also has a set of grammatical rules and hence
can be broken down into a parse tree by the parser. It is on this parse tree that the further steps of
semantic analysis are carried out. This is also used during generation of the intermediate language
code. Yacc (yet another compiler compiler) is a program that generates parsers in the C programming
language.
1 72
REFERENCES/BIBLOGRAPHY
1 https://nptel.ac.in/courses/106/104/106104072/
2
https://www.slideshare.net/appasami/cs6660-compil
er-design-notes
3
http://www.brainkart.com/article/Recognition-of-Tok
1 7
ens_8138/ 9
NAME OF FACULTY (POST, DEPTT.) , JECRC, JAIPUR
8