Compiler Course File
Compiler Course File
SESSION:2023-24
Faculty Details
Name of the Faculty: Miss Neha Saifee
&Engineering
Course Details
Name of the Programme: B.Tech. Batch: 2021-2025
SESSION: 2023-24
Index
Semester: 5th
SESSION: 2023-24
Vision of Institute
To emerge as one of the world's leading institute through continuing to the highest
academic standards, by forging strong industry-academia bond and playing a
pioneering role in research & development, so as to serve society by way of
shaping professionals to conquer the present and future challenges to the socio-
economic fabric of our society by dissemination relevant knowledge through
structured learning system.
Mission of Institute
To build & nurture a new generation of well-rounded professionals who can
work as positive change agents in the new millennium.
To help the Indian industries attain and sustain global leadership.
It will be our endeavour to assimilate and disseminate practical strategies to
future professionals and to encourage their understanding of strategic perception
to fulfil the mission of the organization in the fastchanging global business
environment.
To make a significant contribution by providing an opportunity to the deserving
candidates.
To imbibe the feeling of fraternity and patriotism.
`4
SESSION: 2023-24
Vision &Mission of
Department Semester:5th
SESSION: 2023-24
Program Education
Objectives Semester: 5th
PEO 1: To prepare students for successful careers in industry that meet the needs of
Indian and multinational companies.
PEO 2: To develop the ability among students to synthesize data and technical
concepts for application to product design.
PEO 4: To provide students with a sound foundation in the mathematical, scientific and
engineering fundamentals necessary to formulate, solve and analyze engineering
problems and to prepare them for graduate studies.
PEO 5: To promote student awareness of the life-long learning and to introduce them to
professional ethics and codes of professional practice.
`6
SESSION: 2023-24
Program Outcomes
Semester:5th
Program Outcomes
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization for the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, research literature, and analyses complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural
sciences, and engineering sciences.
4. Conduct investigations of complex problems: Use research based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of
information to provide valid conclusions.
5. 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.
6. 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.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. 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.
`7
SESSION: 2023-24
PSO1: Students will achieve excellence in solving complex engineering problems in product
design, thermal engineering and manufacturing system by acquiring knowledge in
mathematics, science and engineering principles.
PSO2: Students will be able to identify, visualize, formulate and solve the real life Computer
Science problems.
PSO3: Students will develop an approach to solve multidisciplinary industrial problems to find
out cost effective optimal solution for sustainable growth.
PSO4: Students will learn managerial skills to work effectively in a team by exhibiting the
highest ethical and professional standards and will respond to the demand of the society
by engaging in lifelong learning.
`8
SESSION: 2023-24
Academic Calendar
Semester:5th
`9
SESSION: 2022-23
SEMESTER-V
End
Subject Periods Evaluation Scheme
Sl. Subject Semester Total Credit
No.
Codes L T P CT T Total PS TE PE
A
1 KCS501 Database Management 3 1 0 30 20 50 100 150 4
System
2 KCS502 Compiler Design 3 1 0 30 20 50 100 150 4
Design and
3 KCS503 3 1 0 30 20 50 100 150 4
Analysis of
Algorithm
Deptt.
4 Departmental Elective-I 3 0 0 30 20 50 100 150 3
Elective-I
Deptt.
5 Departmental Elective-II 3 0 0 30 20 50 100 150 3
Elective-II
Database Management
6 KCS551 0 0 2 25 25 50 1
System Lab
Design and
8 KCS553 0 0 2 25 25 50 1
Analysis of
Algorithm Lab
Mini Project or
9 KCS554 0 0 2 50 50 1
Internship
Assessment*
Constitution of India,
10 KNC501/K Law and Engineering 2 0 0 15 10 25 50
NC502 / Indian Tradition,
Culture and Society
MOOCs (Essential
11
for Hons.Degree)
Total 17 3 8 950 2
2
*The Mini Project or internship (4 weeks) conducted during summer break after IV semester and will be
assessed
during V semester.
`10
SESSION: 2023-24
DETAILED 3-0-0
SYLLABUS
Unit Topic Proposed
Lecture
Introduction to Compiler: Phases and passes, Bootstrapping, Finite state machines and regular expressions
and their applications to lexical analysis, Optimization of DFA-Based Pattern Matchers implementation of
I lexical analyzers, lexical-analyzer generator, LEX compiler, Formal grammars and their application to syntax 08
analysis, BNF notation, ambiguity, YACC. The syntactic specification of programming languages: Context
free grammars, derivation and parse trees, Capabilities of CFG.
Basic Parsing Techniques: Parsers, Shift reduce parsing, operator precedence parsing, top down parsing,
II predictive parsers Automatic Construction of efficient Parsers: LR parsers, the canonical Collection of LR(0)
items, constructing SLR parsing tables, constructing Canonical LR parsing tables, Constructing LALR 08
parsing tables, using ambiguous grammars, an automatic parser generator, implementation of LR parsing
tables.
Syntax-directed Translation: Syntax-directed Translation schemes, Implementation of Syntax-directed
Translators, Intermediate code, postfix notation, Parse trees & syntax trees, three address code, quadruple &
triples, translation of assignment statements, Boolean expressions, statements that alter the flow of control,
III
postfix translation, translation with a top down parser. More about translation: Array references in arithmetic 08
expressions, procedures call, declarations and case statements.
Symbol Tables :Data structure for symbols tables, representing scope information. Run-Time Administration:
IV Implementation of simple stack allocation scheme, storage allocation in 08
blockstructuredlanguage.ErrorDetection&Recovery:LexicalPhaseerrors,syntacticphaseerrors
Semantic errors.
Code Generation: Design Issues, the Target Language. Addresses in the Target Code, Basic Blocks and
V Flow Graphs, Optimization of Basic Blocks, Code Generator. Code optimization: Machine-Independent 08
Optimizations, Loop optimization, DAG representation of basic blocks, Value numbers and algebraic laws,
Global Data-Flow analysis.
Textbooks:
1. Aho,Sethi&Ullman,"Compilers:Principles,TechniquesandTools”,PearsonEducation
2. K.Muneeswaran, Compiler Design, First Edition, Oxford University Press
3. J.P.Bennet,“IntroductiontoCompilerTechniques”,SecondEdition,McGraw-Hill,2003.
4. HenkAlblasandAlbertNymeyer,“PracticeandPrinciplesofCompilerBuildingwithC”,PHI,2001.
5. VRaghvan,“Principles ofCompilerDesign”,McGraw-Hill,
6. Kenneth Louden,” Compiler Construction”,CengageLearning.
7. CharlesFischerandRicardLeBlanc,”CraftingaCompilerwithC”,PearsonEducation
`11
SESSION: 2023-24
Syllabus
SESSION: 2023-24
Course Outcomes
Semester: 5th
COURSE OUTCOMES
Once the student has successfully completed this course, he/she will be able:
KCS Define phases of compiler and also define the LEX and YACC compiler.
502.1
KCS What do you mean by parser? How to create parsing table for LR,SLR,
502.2 CLR and LALR parser?
KCS Explain SDD and also define types of SDD. What do you mean by 3
502.3 address code ?
KCS Discuss the stack allocation and heap allocation strategies of the
502.4 runtime environment with an example.
KCS Explain in detail about loop optimization. Define a DAG. Construct a DAG for
502.5 the expression:
p+p*(q-r)+(q-r)*s
`15
SESSION: 2023-24
Course Plan
Delivery Methods: Chalk& Talk, Power Point Presentation, Tutorials Assignments.
Coverage of
Unit 1 by: - Chalk & Talk, Power Point Presentation, discussions and Tutorials & Assignments.
Unit 2 by: -Chalk & Talk, Power Point Presentation, discussions and Tutorials & Assignments.
Unit 3 by: -Chalk & Talk, Power Point Presentation, discussions and Tutorials & Assignments.
Unit 4 by: -Chalk & Talk, Power Point Presentation, discussions and Tutorials & Assignments.
Unit 5 by: -Chalk & Talk, Power Point Presentation, discussions and Tutorials & Assignments.
`16
SESSION: 2023-24
Mapping
Semester: 5th
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
KCS502.1 3 2
KCS 502.2 3 2
KCS 502.3 2 1
KCS 502.4 2 1
KCS 502.5 2 1 1 2 2 2 3
KCS 502 2.5 1.4 1 2 2 2 3
SESSION: 2023-24
Time Table
Semester: 5th
WED Web Design Compiler Design DBMS Lab HCI N Aptitude DAA DBMS
Compiler Communication
THU
Design (NS)
DBMS
Skills
Web Design C Aptitude DAA Lab DAA
Compiler
FRI
Design
Web Design DBMS HCI H Library DAA Compiler Lab
Compiler
SAT DBMS DBMS Lab Web Design STUDENT ACTIVITY
Design
`18
SESSION: 2023-24
Lecture Plan
&
Course Coverage Semester: 5th
Total Period: 50
statements
1. Aho,Sethi&Ullman,"Compilers:Principles,TechniquesandTools”,PearsonEducation
2. K.Muneeswaran,CompilerDesign,FirstEdition,OxfordUniversityPress
3. J.P.Bennet,“IntroductiontoCompilerTechniques”,SecondEdition,McGraw-Hill,2003.
4. HenkAlblasandAlbertNymeyer,“PracticeandPrinciplesofCompilerBuildingwithC”,PHI,2001.
5. VRaghvan,“PrinciplesofCompilerDesign”,McGraw-Hill,
6. KennethLouden,”CompilerConstruction”,CengageLearning.
7. CharlesFischerandRicardLeBlanc,”CraftingaCompilerwithC”,PearsonEducation
NEHA SAIFEE
SESSION: 2023-24
Tutorial – 1
Semester:5th
Tutorial 1 [CO - 1]
Coverage
Sr. No. of Topics/Sub Topics Date
Sign
No. Periods
1. 1 Compiler Design 27/09/2023
How Compiler does compilation process ? also write down role of Regular expression and
finite Automata in Compiler design.
What do you mean by token and lexme? Also write down name of any 5 token and their
Regular expression.
Define Context Free Grammar and ambiguous grammar for the given production
E -> E*E/id
W = id + id * id
Check the grammar is ambiguous or not. Also find out left most derivation & right most derivation. If
grammar has left recursion then remove it.
NEHA SAIFEE
SESSION: 2022-23
Tutorial – 2
Semester: 5th
Tutorial 2 [CO - 2]
Coverage
Sr. No. of Topics/Sub Topics Date
Sign
No. Periods
1. 1 Basic Parsing Techniques 09/10/2023
S -> (L)/a
L ->L,S/S
W -> (a,(a,a))
E ->
TE’ E’ ->
+TE’
T -> FT’
T’ -> *FT’/ε
F -> a/b
F -> (E)/id
-> CC
C ->
Cc C ->
d
`24
->AC/Cb
A ->
Da B -
>g
`25
C -> f/ε
NEHA SAIFEE
SESSION: 2023-24
Tutorial – 3
Semester:5th
Tutorial 3 [CO - 3]
Coverage
Sr. No. of Topics/Sub Topics Date
Sign
No. Periods
1. 1 Syntax-directed Translation schemes 20/11/2023
SESSION: 2023-24
Tutorial – 4
Semester:5th
Tutorial 4 [CO - 4]
Coverage
Sr. No. of Topics/Sub Topics Date
Sign
No. Periods
1. 1 Data structure for symbol stables 04/12/2023
what are lexical phase errors, syntactic phase errors and semantic phase errors?
`28
SESSION: 2023-24
Tutorial – 5
Semester:5th
Tutorial 5 [CO - 5]
Coverage
Sr. No. of Topics/Sub Topics Date
Sign
No. Periods
1. 1 Code Generation 20/12/2023
blocks: a:=b+c
b:=b-d
c:=c+d
e:=b+c
`29
SESSION: 2023-24
ASSIGNMENT – 1
Semester: 5th
DATE – 06/10/2023
SUBMISSION DATE –
10/10/2023
How Compiler does compilation process ? also write down role of Regular expression and
finite Automata in Compiler design.
What do you mean by token and lexme? Also write down name of any 5 token and their
Regular expression.
Define Context Free Grammar and ambiguous grammar for the given production
E -> E*E/id
W = id + id * id
Check the grammar is ambiguous or not. Also find out left most derivation & right most derivation. If
grammar has left recursion then remove it.
SESSION: 2023-24
ASSIGNMENT – 2
Semester: 5th
DATE – 18/10/2023
6. Write down the short note on symbol table and error hander.
`31
SESSION: 2023-24
ASSIGNMENT – 3
Semester: 5th
Explain the three address code and write the three address code for the Boolean expression.
Draw Syntax tree for the arithmetic expression: a*(b+c)-d/2. Also write the given
expression in postfix notation.
: a+b=b-c*a/e^f*p
{ if (a>b)
{ a=a+b;
While (p>q)
SESSION: 2023-24
SESSION: 2023-24
SESSION: 2023-24
List of Students
Semester: 5th
SESSION: 2023-24
Record of Monthly
Semester: 5th
Attendance
September 2023
Tot.
S. No. Name Roll Number (P) (A) Tot.
(%age)
1 Aastha Chaurasiya 2103190100001 11 06 17 75
2 Aman Gupta 2103190100002 12 05 17 83
3 Aryan Saxena 2103190100005 14 03 17 69
4 Bachitar Singh 2103190100006 07 10 17 64
5 Brij Kishor 2103190100007 10 07 17 55
6 Love Gupta 2103190100008 08 09 17 57
7 Mohammad Rizwan 2103190100009 13 04 17 57
8 Nandini Saxena 2103190100011 14 03 17 84
9 Pankaj Verma 2103190100012 09 08 17 60
10 Prabhat Bhardwaj 2103190100013 08 09 17 44
11 Prashant Singh 2103190100015 10 07 17 56
12 Sadiq Ali Khan 2103190100020 05 12 17 34
13 Shivang Chauhan 2103190100021 13 04 17 77
14 Sohil Dilshad 2103190100022 03 14 17 11
15 Swati 2103190100023 12 05 17 66
16 Tushar 2103190100024 10 07 17 65
17 Amit Singh 2203190109001 00 17 17 0
18 Ayush Srivastav 2203190109002 13 04 17 79
19 Devendra Waliya 2203190109003 14 03 17 64
20 Nishij Yadav 2203190109004 00 17 17 0
21 Udit Kumar Varshney 2203190109005 00 17 17 0
22 Vicky Srivastav 2203190109006 00 17 17 18
23 Vishal Sahu 2203190109007 12 05 17 56
`36
SESSION: 2023-24
Record of Monthly
Semester: 5th
Attendance
October 2023
Tot.
S. No. Name Roll Number (P) (A) Tot.
(%age)
1 Aastha Chaurasiya 2103190100001 15 06 21 75
2 Aman Gupta 2103190100002 20 01 21 83
3 Aryan Saxena 2103190100005 12 09 21 69
4 Bachitar Singh 2103190100006 19 2 21 64
5 Brij Kishor 2103190100007 10 11 21 55
6 Love Gupta 2103190100008 13 08 21 57
7 Mohammad Rizwan 2103190100009 10 11 21 57
8 Nandini Saxena 2103190100011 18 03 21 84
9 Pankaj Verma 2103190100012 14 07 21 60
10 Prabhat Bhardwaj 2103190100013 06 15 21 44
11 Prashant Singh 2103190100015 11 10 21 56
12 Sadiq Ali Khan 2103190100020 09 12 21 34
13 Shivang Chauhan 2103190100021 17 04 21 77
14 Sohil Dilshad 2103190100022 02 19 21 11
15 Swati 2103190100023 13 08 21 66
16 Tushar 2103190100024 14 07 21 65
17 Amit Singh 2203190109001 00 21 21 0
18 Ayush Srivastav 2203190109002 18 03 21 79
19 Devendra Waliya 2203190109003 12 09 21 64
20 Nishij Yadav 2203190109004 00 21 21 0
21 Udit Kumar Varshney 2203190109005 00 21 21 0
22 Vicky Srivastav 2203190109006 07 14 21 18
23 Vishal Sahu 2203190109007 10 11 21 56
`37
SESSION: 2023-24
Record of Attendance
Semester: 5th
Tot.
S. No. Name Roll Number
(%age)
1 Aastha Chaurasiya 67
2103190100001
2 Aman Gupta 74
2103190100002
3 Aryan Saxena 2103190100005 64
15 Swati 2103190100023 51
16 Tushar 2103190100024 59
SESSION: 2023-24
Section – A
Section – B
E→E(T)/T
T→T(F)/F
F→id
Section – C
switch a+b
Case1: x=x+1
Case2: y=y+2
Case3: z=z+3
default : c=c-
Construct LR(1) Parsing table . also draw the LALR table from the derived
SESSION: 2023-24
Section A
Q1. Attempt All questions. (2 × 10 = 20 Marks)
a)Mention the role of semantic analysis.
b) What is YACC? Discuss about it.
c) Explain the problems associated with top-down Parser.
d) Differentiate Parse tree and Syntax tree with an example.
e) Consider the following grammar:
S→B|SabS, B→bB|ε Compute FOLLOW(B)
f) List down the conflicts during shift-reduce parsing.
g) What is phrase level error recovery?
h) Discuss about shift-reduce parsing.
i) Discuss about designing issues of code generator.
j) What is induction variable?
Section B
Q2. Attempt any three questions. (3 × 10 = 30 Marks)
a) What is an activation record? Draw diagram of general activation
record and explain the purpose of different fields of an activation record.
b) Construct the SLR parsing table for the following Grammar. S→ 0S0,
S→ 1S1, S→ 10
c) Construct the CLR parse table for the following Grammar:
A->BB, B->cB, B->d
d) Check whether given grammar is ambiguous or not. If ambiguous
then convert it into unambiguous grammar: E→E+E|E*E|id
e) Explain in detail the process of compilation for the statement a=b+c*70.
Section C
Q3. Attempt any two questions. (1 × 10 = 10 Marks)
a) Explain in detail about loop optimization.
b) Discuss the stack allocation and heap allocation strategies of
the runtime environment with an example.
{
case 1: x=x+1
case 2: y=y+2
case 3: z=z+3
default: c=c-1
}
Q6. Attempt any one question. (1 × 10 = 10 Marks)
a) Find the precedence and function table of the following grammar
by using operator precedence technique. P→SR|S, R→bSR|bS,
S→WbS|W, W→L*W|L, L→id
b) How do we represent the scope information? Explain scope by
number and scope by location.
Q7. Attempt any one question. (1 × 10 = 10 Marks)
a) Define Symbol table? Explain about the data structures used for
symbol table.
b) (i). Explain the function of error handling phase of a compiler.
(ii). Write short note on scoping.
`59
`60
`61
`62
`63
`64
`65
`66
`67
`68
`69
`70
`71
`72
`73
`74
`75
`76
`77
`78
`79
`80
`81
`82
`83
`84
SESSION: 2023-24
UT – 1 PUT
S. No. Name Roll Number
Attendance Attendance
SESSION: 2023-24
Attendance
S. No. Name Roll Number
(%)
SESSION: 2023-24
UT – 1
S. No. Name Roll Number PUT (100)
(50)
SESSION: 2023-24
UT – 1
S. No. Name Roll Number PUT (100)
(50)
(1) A question bank based on the previous years’ question papers, is provided to the students for
better preparation.
(2) Regular monitoring of their progress is done by observing their performance in lectures,
tutorials and labs.
(3) Separate special classes for weak students are arranged. It helps in clarifying the doubts and
re-explaining of difficult topics to such students.
`88
SESSION: 2023-24
UT – 1
S. No. Name Roll Number PUT (100)
(50)
(1) Students are encouraged to enhance their skills by joining NPTEL/MOOC or any other
special training course based on their area of interest.
(2) Questions of competitive exam level regularly taught to students.
(3) Strong monitoring of self-learning activities of students.
(a) Students are encouraged to read different books and present various topics
as Seminar in order to enhance the presentation and communication skills.
(b) Students are encouraged to prepare their own notes of each topics.
`89
SESSION: 2023-24
Previous Year Question
Papers Semester: 5th
B.TECH.
(SEM V) THEORY EXAMINATION 2022-23
COMPILER DESIGN
Time:3Hours TotalMarks:100
Note: Attempt all Sections. If require any missing data; then choose suitably.
SECTION-A
SECTION-B
While
a<b do if
c<d then
x=y*zel
se
x=y+z
(b) Discuss the stack allocation and heap allocation strategies of the run
time environment with an example.
(c) What do you mean by attributed grammars? Discuss the translation
scheme for converting an infix expression to its equivalent postfix
form.
(d) Construct the NFA and DFA for the following regular expression.
(0+1)*(00+11)(0+1)*
(e) Explain the lexical analysis and syntax analysis phases of the compiler
with a suitable example. Explain the reporting errors in these two
phases as well.
SECTION C
`91
BCb
Bd
(g) Construct the SLR parsing table for the following Grammar.
S→0S0
S→1S1
S→10
4) Attempt any one part of the following: 10x1=10
(h) Whatisbackpatching.GeneratethreeaddresscodeforthefollowingBool
eanexpressionusingbackpatching:
a<b or c>d and e<f
(i) What is top down parsing? What are the problems in top
down parsing? Explain each with suitable example.
Semester: 5th
B.TECH.
(SEM V) THEORY EXAMINATION 2023-24
COMPILER DESIGN
`94
89