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

Compiler Course File

cgjfgjjj jd

Uploaded by

amir husain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Compiler Course File

cgjfgjjj jd

Uploaded by

amir husain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 94

`1

SESSION:2023-24

Course and Faculty Details


Semester: 5th

Faculty Details
Name of the Faculty: Miss Neha Saifee

Designation: Assistant Professor –

Engineering Department: Computer Science

&Engineering

Course Details
Name of the Programme: B.Tech. Batch: 2021-2025

Branch: Computer Science Session: 2023-24

Name of Subject: Compiler Design

Subject Code: KCS 502

Category of Course: Regular


`2

SESSION: 2023-24

Index
Semester: 5th

Course & Faculty Details Page No.


Index 2
Vision & Mission of Institute 3
Vision & Mission of Department 4
Program Educational Objectives 5
Program Outcomes 6
Program Specific Outcomes 7
Academic calendar 8
Course Evaluation Scheme 9
Course Syllabus as per University 10
Syllabus adopted by the Program 11
Course Outcomes 14
Course Delivery Method 15
Mapping 16
Time Table 17
Lecture Plan & Course Coverage 18
Lecture Plan of Tutorials 25
Assignments 31
List of Students 36
Record of Monthly Attendance 37
Class Test Papers with Solutions 41
Class Test Attendance 86
List of Student having short attendance 87
Class Test Marks 88
List of Weak Students 89
List of Bright Students 90
Previous Year Question Papers 91
Question Bank
Final Internal Marks
Course Outcome Attainment
`3

SESSION: 2023-24

Vision & Mission of


Institute Semester: 5th

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

Vision of the Department


The vision of the Department of Computer Science is to be regionally, nationally
and internationally recognized in providing Computer Science education, leading
to well qualified engineers who are innovative, immediate contributors to their
profession and successful in advanced studies.

Mission of the Department


 To convey the best technical knowledge to emerging professionals and
motivate their pursuit for further enrichment of their learning.
 To produce recognized industry-oriented professionals in Computer Science
through quality education incorporating practice and project-based teaching-
learning processes.
 To become capable of conducting high-quality technological research for the
benefit of society.
 To create competent professionals to become part of the industry and research
organizations at the national and international levels.
 Developing the feeling of oneness, Social Values, Entrepreneurship skills and
Professional Ethics in the minds of Stakeholders.
`5

SESSION: 2023-24

Program Education
Objectives Semester: 5th

Program Education Objectives

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 3: To provide opportunity for students to work as part of teams on


multidisciplinary projects.

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.

3. Design/development of solutions: Design solutions for complex engineering problems and


design system components or processes that meet the specified needs with appropriate
consideration for public health and safety, and cultural, societal, and environmental
considerations.

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.

7. Environment and sustainability: Understand the impact of the professional engineering


solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.

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.

10. Communication: Communicate effectively on complex engineering activities with the


engineering community and with the society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations, and give and
receive clear instructions.

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

Program Specific Outcomes


Semester:5th

After completing their graduation, students of Computer Science will be able to –

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

Course Evaluation Scheme


Semester: 5th

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

7 KCS552 Compiler Design Lab 0 0 2 25 25 50 1

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

Course Syllabus as per


University Semester: 5th

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 Adopted by the


Program Semester:5th

Syllabus

Module 1:Introduction to Compiler: [8+2]


1. Phases and passes, Bootstrapping, Finite state machines and regular expressions and their
applications to lexical analysis
2. Optimization of DFA-Based Pattern Matchers implementation of lexical analyzers
3. Generator lexical-analyzer, LEX compiler
4. Formal grammars and their application to syntax analysis
5. BNF notation, ambiguity, YACC
6. The syntactic specification of programming languages
7. Context free grammars
8. Derivation and parse trees
9. Capabilities of CFG

- Tutorials and Assignments will be taken up in Practice Sessions or Tutorial Classes.

Module 2: Basic Parsing Techniques [8+2]


1. Parsers, Shift reduce parsing,
2. Operator precedence parsing, top down parsing
3. Predictive parsers Automatic Construction of efficient Parsers
4. LR parsers, the canonical Collection of LR(0) items, constructing SLR parsing tables
5. Constructing Canonical LR parsing tables
6. LALR parsing tables, using ambiguous grammars
7. An automatic parser generator, implementation of LR parsing tables.
- Tutorials and Assignments will be taken up in Practice Sessions or Tutorial Classes.

Module 3: Syntax-directed Translation [8+2]

1. Syntax-directed Translation schemes, Implementation of Syntax-directed Translators


2. Intermediate code, postfix notation, Parse trees & syntax trees
3. three address code, quadruple & triples, translation of assignment statements
4. Boolean expressions, statements that alter the flow of control
5. , postfix translation, translation with a top down parser
6. More about translation: Array references in arithmetic expressions, procedures call,
declarations and case statements

- Tutorials and Assignments will be taken up in Practice Sessions or Tutorial Classes.

Module 4: Symbol Tables [8+2]

1. Data structure for symbols tables, representing scope information.


2. Run-Time Administration: Implementation of simple stack allocation scheme,
`12

3. Storage allocation in block structured language.


`13

4. Error Detection & Recovery: Lexical Phase errors,


5. Syntactic phase errors
6. Semantic errors.
- Tutorials and Assignments will be taken up in Practice Sessions or Tutorial Classes.

Module 5: Code Generation: [8+2]

1. Design Issues, the Target Language.


2. Addresses in the Target Code, Basic Blocks and Flow Graphs,
3. Optimization of Basic Blocks, Code Generator.
4. Code optimization: Machine-Independent Optimizations,
5. Loop optimization,
6. DAG representation of basic blocks,
7. Value numbers and algebraic laws, Global Data-Flow analysis.
- Tutorials and Assignments will be taken up in Practice Sessions or Tutorial Classes.
`14

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 Delivery Method


Semester:5th

Name of Subject: Compiler Design

Subject Code: KCS 502

Branch: Computer Science

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

Mapping of Course Outcomes with POs & PSOs: (3 – High, 2 – Moderate, 1 –


Low)

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

CO PSO1 PSO2 PSO3 PSO4


KCS502.1 2
KCS 502.2 1
KCS 502.3 1
KCS 502.4 1
KCS 502.5 1
KCS 502 1.2
`17

SESSION: 2023-24

Time Table
Semester: 5th

TIME 12:50- 01:30- 02:20-


9:30-10:20 10:20-11:10 11:10-12:00 12:00-12:50 03:10-04:00
DAY 1:30 2:20 03:10

Compiler Constitution of Compiler


MON
Design India
DBMS Web Design L Lab
DAA Mini Project

Constitution of Communication Web Compiler


TUE DBMS
India Skills
HCI U Design
DAA
Design

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

Sr. No. of Topics/Sub Topics Reference CO Date Sign


No. Perio Books Covered Tentative Covered
ds
Module 1: Compiler Design

1. 1 Phases and passes 2,5 CO1 01/09/2 06/09/23


3

2. 1 Bootstrapping 1,2,5 CO1 02/09/2 08/09/23


3
3. 1 Finite state 1,2 CO1 04/09/2 09/09/23
machines and 3
regular expressions
and their
applications to
lexical analysis
4. 1 Optimization of 2,5 CO1 05/09/2 13/09/23
DFA-Based Pattern 3
Matcher
simplementation of
lexical analyzers
5. 1 generator lexical- 1,2,5 CO1 06/09/2 14/09/23
analyzer 3
6. 1 LEX compiler 1,2 CO1 08/09/2 15/09/23
3
7. 1 Formal grammars 2,5 CO1 09/09/2 18/09/23
and their 3
application to
syntax analysis
8. 1 BNF notation, 2,4 CO1 11/09/2 19/09/23
ambiguity 3
9. 1 YACC 3,5 CO1 12/09/2 20/09/23
3
10. 1 6. The 1,3 CO1 13/09/2 21/09/23
syntactic 3
specification of
programming
languages
11. 1 Context free 2,4 CO1 14/09/2 25/09/23
grammars 3
12. 1 Derivation and 1,5 CO1 15/09/2 26/09/23
parse trees 3
`19

13. 1 Capabilities of CFG 1,2 CO1 16/09/2 27/09/23


3
Module 2:Basic Parsing Techniques

14. 1 Parsers, Shift 2,4 CO2 18/09/2 28-29/09/23


reduce parsing 3
15. 1 Operator 2,3 CO2 19/09/2 30/09/23
precedence parsing, 3
top down parsing
16. 1 Predictive parsers 4,5 CO2 20/09/2 03-04/10/23
Automatic 3
Construction of
efficient Parsers
17. 1 LR parsers, the 1,2,5 CO2 21/09/2 05-06/10/23
canonical 3
Collection of
LR(0)items
18. 1 Constructing SLR 2,4 CO2 22/09/2 07-09/10/23
parsing tables 3
19. 1 Constructing 1,3 CO2 23/09/2 11/10/23
Canonical LR 3
parsing Tables
20. 1 Constructing LALR 1,5 CO2 25/09/2 13/10/23
parsing tables, 3
using ambiguous
grammars
21. 1 An automatic parser 2,4 CO2 26/09/2 16/10/23
generator 3
22. 1 Implementation of 1,5 CO2 27/09/2 17/10/23
LR parsing tables 3
Module 3: Syntax-directed Translation

23. 1 Syntax-directed 2,4 CO3 29/09/2 25/10/23


Translation 3
schemes
24. 1 Implementation of 1,3 CO3 30/09/2 06/11/23
Syntax-directed 3
Translators
25. 1 Intermediate code, 2,3 CO3 03/10/2 07/11/23
postfix notation 3
26. 1 Parse trees & 1 CO3 04/10/2 08/11/23
syntax trees 3
27. 1 Three addresscode, 2,4 CO3 05/10/2 16/11/23
quadruple & triples 3

28. 1 Translation of 3,5 CO3 06/10/2 17/11/23


assignment 3
`20

statements

29. 1 Boolean 1 CO3 07/10/2 20/11/23


expressions, 3
statements that alter
the flow of control

30. 1 Postfix translation, 2 CO3 09/10/2 21/11/23


translation with a 3
top down parser

Module 4: Symbol Tables

31. 1 Data structure for 1,2 CO4 10/10/2 22/11/23


symbol stables
3
32. 1 Representing scope 1,2 CO4 11/10/2 23/11/23
information
33. 1 Run-Time 1 CO4 12/10/2 24/11/23
Administration 3
34. 1 Implementation of 1,2 CO4 13/10/2 28/11/23
simple stack 3
35. 1 Storage allocation 1,3 CO4 14/10/2 29/11/23
in block structured
36. 1 Error Detection & 1,4 CO4 16/10/2 30/11/23
Recovery 3
37. 1 Lexical Phase errors 2,5 CO4 17/10/2 01/12/23

38. 1 Syntactic phase 2 CO4 18/10/2 04/12/23


errors 3
Module 5: Code Generation

39. 1 Design Issues 3,4 CO5 19/10/2 05/12/23

40. 1 The Target 3 CO5 20/10/2 06/12/23


Language 3
41. 1 Addresses in the 1 CO5 21/10/2 11/12/23
Target Code
42. 1 Basic Blocks and 2 CO5 23/10/2 13/12/23
Flow Graphs 3
43. 1 Optimization of 1,4 CO5 24/10/2 15/12/23
Basic Blocks 3
44. 1 Code Generator 1,3 CO5 25/10/2 18/12/23

45. 1 Code optimization 1 CO5 26/10/2 20/12/23


3
46. 1 Machine- 2,4 CO5 27/10/2 21/12/23
Independent
Optimizations 3
47. 1 Loop optimization 2 CO5 31/10/2 26/12/23

48. 1 DAG representation 3,4 CO5 01/11/2 27/12/23


of basic blocks
`21

49. 1 Value number sand 2 CO5 01/11/2 28/12/23


algebraic laws 3
50. 1 Global Data-Flow 1 CO5 02/11/2 29/12/23
analysis

Books and References:

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

Name & Sign. of Faculty Sign. of HOD Sign. of Director


`22

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

rules: E -> E+E,

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.

Define Cousins of Compiler.

NEHA SAIFEE

Name & Sign. of Faculty


`23

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

How to Design parsing table for LR(0) parser?

For given string apply Bottom Up and Shift Reduce parsing

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

Compute First() and Follow () Function.

Design LR Parsing table for the given grammar S

-> CC

C ->

Cc C ->

d
`24

Also check the grammar is LR(0) or not.

Design SLR Parsing table for the given grammar S

->AC/Cb

A ->

Da B -

>g
`25

C -> f/ε

NEHA SAIFEE

Name & Sign. of Faculty


`26

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

Define Syntax directed translation.

Explain Attributes. What are synthesized and inherited attributes?

What do you mean by Assignment statements?

Give the syntax directed definition for if-else statement.

Explain procedure call with example.


`27

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

Discuss symbol table with its capabilities?

Discuss how the scope information is represented in a symbol table.

Explain Activation record & scoping?

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

What is code generation? Discuss the design issues of code generation.

What is loop? Explain what constitute a loop in a flow graph.

What is DAG? Construct the DAG for the following basic

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

rules: E -> E+E,

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.

Define Cousins of Compiler.


`30

SESSION: 2023-24

ASSIGNMENT – 2
Semester: 5th

DATE – 18/10/2023

1. Eliminate the recursion from the following grammar


S→AB, A→BS/b, B→SA/a
2. For the grammar
S→aAd/Bbd/Abe, A→f, B→f
Construct LR(1) parsing table.
3. Consider the following grammar and construct E→E+E/E×E/(E)/id the SLR pasring
table.
4. Write a short note on YACC parser generator.
5. Explain non-recursive predictive parsing consider the following grammar and construct
the parsing table.
E→TE’
E→+TE/ ɛ
T→FT’
T’→*FT’/ɛ
F→F*/a/b

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.

What do you mean by types of SDT?

Draw Syntax tree for the arithmetic expression: a*(b+c)-d/2. Also write the given
expression in postfix notation.

Describe various representation of 3 address code, translate the expression

: a+b=b-c*a/e^f*p

Generate three address code for the following

code: do { for (i=1;i<=5;i++)

{ if (a>b)

{ a=a+b;

While (p>q)

Define Machine code generation .


`32

SESSION: 2023-24

Marks of Class Test 1st


Semester: 5th

S. Roll No. Student Name Marks


No.
1 2103190100001 Aastha Chaurasiya 11/30
2 2103190100002 Aman Gupta 08/30
3 2103190100005 Aryan Saxena A
4 2103190100006 Bachitar Singh A
5 2103190100007 Brij Kishor A
6 2103190100008 Love Gupta 13/30
7 2103190100009 Mohammad Rizwan A
8 2103190100011 Nandini Saxena 23/30
9 2103190100012 Pankaj Verma 05/30
10 2103190100013 Prabhat Bhardwaj A
11 2103190100015 Prashant Singh A
12 2103190100020 Sadiq Ali Khan 00/30
13 2103190100021 Shivang Chauhan 27/30
14 2103190100022 Sohil Dilshad A
15 2103190100023 Swati A
16 2103190100024 Tushar 11/30
17 2203190109001 Amit Singh A
18 2203190109002 Ayush Srivastav 20/30
19 2203190109003 Devendra Waliya A
20 2203190109004 Nishij Yadav A
21 2203190109005 Udit Kumar Varshney A
22 2203190109006 Vicky Srivastav A
23 2203190109007 Vishal Sahu A
`33

SESSION: 2023-24

Marks of Class Test 2nd


Semester: 5th

S. Roll No. Student Name Marks


No.
1 2103190100001 Aastha Chaurasiya 10/30
2 2103190100002 Aman Gupta 08/30
3 2103190100005 Aryan Saxena 11/30
4 2103190100006 Bachitar Singh 09/30
5 2103190100007 Brij Kishor A
6 2103190100008 Love Gupta 18/30
7 2103190100009 Mohammad Rizwan A
8 2103190100011 Nandini Saxena 22/30
9 2103190100012 Pankaj Verma 14/30
10 2103190100013 Prabhat Bhardwaj A
11 2103190100015 Prashant Singh 09/30
12 2103190100020 Sadiq Ali Khan 00/30
13 2103190100021 Shivang Chauhan 21/30
14 2103190100022 Sohil Dilshad A
15 2103190100023 Swati 10/30
16 2103190100024 Tushar 09/30
17 2203190109001 Amit Singh A
18 2203190109002 Ayush Srivastav 22/30
19 2203190109003 Devendra Waliya A
20 2203190109004 Nishij Yadav A
21 2203190109005 Udit Kumar Varshney A
22 2203190109006 Vicky Srivastav A
23 2203190109007 Vishal Sahu 09/30
`34

SESSION: 2023-24

List of Students
Semester: 5th

S. Roll No. Student Name


No.
1 2103190100001 Aastha Chaurasiya
2 2103190100002 Aman Gupta
3 2103190100005 Aryan Saxena
4 2103190100006 Bachitar Singh
5 2103190100007 Brij Kishor
6 2103190100008 Love Gupta
7 2103190100009 Mohammad Rizwan
8 2103190100011 Nandini Saxena
9 2103190100012 Pankaj Verma
10 2103190100013 Prabhat Bhardwaj
11 2103190100015 Prashant Singh
12 2103190100020 Sadiq Ali Khan
13 2103190100021 Shivang Chauhan
14 2103190100022 Sohil Dilshad
15 2103190100023 Swati
16 2103190100024 Tushar
17 2203190109001 Amit Singh
18 2203190109002 Ayush Srivastav
19 2203190109003 Devendra Waliya
20 2203190109004 Nishij Yadav
21 2203190109005 Udit Kumar Varshney
22 2203190109006 Vicky Srivastav
23 2203190109007 Vishal Sahu
`35

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

4 Bachitar Singh 2103190100006 62

5 Brij Kishor 2103190100007 50

6 Love Gupta 2103190100008 53

7 Mohammad Rizwan 2103190100009 49

8 Nandini Saxena 2103190100011 84

9 Pankaj Verma 2103190100012 61

10 Prabhat Bhardwaj 2103190100013 51

11 Prashant Singh 2103190100015 62

12 Sadiq Ali Khan 2103190100020 28

13 Shivang Chauhan 2103190100021 68

14 Sohil Dilshad 2103190100022 8

15 Swati 2103190100023 51

16 Tushar 2103190100024 59

17 Amit Singh 2203190109001 0

18 Ayush Srivastav 2203190109002 74

19 Devendra Waliya 2203190109003 62

20 Nishij Yadav 2203190109004 0

21 Udit Kumar Varshney 2203190109005 0

22 Vicky Srivastav 2203190109006 13

23 Vishal Sahu 2203190109007 52


`38

SESSION: 2023-24

Class Test Papers


Semester: 5th

Rakshpal Bahadur College of Engineering and Technology Bareilly


B. Tech. Unit Test– 1 Examination, November 2023

Branch Name& Semester: CSE(5th )

Subject Name: Compiler design Total Marks:50

Subject Code: KCS - 502 Time:120Minutes

Section – A

1. Attempt all questions in brief. (5 × 1=5 Marks)

a) What do you mean by Syntax Directed Definition(SDD)?


b) Differentiate between compiler & assembler.
c) How YACC can be used to generate parser?
d) Differentiate between quadruples and triples.
e) Draw the syntax tree for the following statement:
cbcba-*+-*=

Section – B

2. Attempt any five of the following. (5 × 5=25 Marks)

a) Explain in detail the process of Compilation.


b) Draw syntax tree for the arithmetic expressions:
a*(b+c)-d/2.also write the given expression in postfix notation.
c) Define bootstrapping with the help of an example.
d) Construct the CLR parse table for the following grammar.
S→CC
C→Cc
C→d
e) What is intermediate code generation?
f) Give the algorithm for construction of LALR parsing table.
g) Remove left recursion from the grammar
`39
`40

E→E(T)/T
T→T(F)/F
F→id

Section – C

3.Attempt any one part of the following. (1 × 10=10 Marks)

a) Explain non-recursive descent (predictive) parsing . consider the following grammar


and construct the predictive parsing table
E→TE’
E’→+TE’/ε
T→FT’
T’→*FT’/ε
F→F*/a/b
b) generate 3- address code for the following code:

switch a+b

Case1: x=x+1

Case2: y=y+2

Case3: z=z+3

default : c=c-

4. Attempt any one part of the following. (1 × 10=10 Marks)

a) Illustrate the output of each phase of compilation of the


input “a=(b+c)*(b+c)*2”
b) For the grammar S→aAd/bBd/aBe
A→f
B→f

Construct LR(1) Parsing table . also draw the LALR table from the derived

LR(1) Parsing table.


`41
`42
`43
`44
`45
`46
`47
`48
`49
`50
`51
`52
`53
`54
`55
`56

SESSION: 2023-24

Class Test Papers


Semester: 5th

RakshpalBahadur CollegeofEngineering andTechnologyBareilly


B. Tech. Unit Test– 2 Examination, January 2024

Branch Name& Semester:CSE(5th )

SubjectName: Compiler design Total Marks:100

SubjectCode: KCS - 502 Time:150Minutes

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.

Q4. Attempt any one question. (1 × 10 = 10 Marks)


a) Define a DAG. Construct a DAG for the expression:
p+p*(q-r)+(q-r)*s
b) Check whether the given grammar is LR(0) or not:
S→PQy, P→Sy|x, Q→yS
Q5. Attempt any one question. (1 × 10 = 10 Marks)
`57

a) Write quadruple, triples and indirect triples for following expression


: a = b * – c + b * – c.
b) Generate three address code for the following
code: Switch p+q
`58

{
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

Class Test Attendance


Semester: 5th

UT – 1 PUT
S. No. Name Roll Number
Attendance Attendance

1 Aastha Chaurasiya 2103190100001 P P


2 Aman Gupta 2103190100002 P P
3 Aryan Saxena 2103190100005 P P
4 Bachitar Singh 2103190100006 P A
5 Brij Kishor 2103190100007 P P
6 Love Gupta 2103190100008 P P
7 Mohammad Rizwan 2103190100009 P A
8 Nandini Saxena 2103190100011 P P
9 Pankaj Verma 2103190100012 P P
10 Prabhat Bhardwaj 2103190100013 P P
11 Prashant Singh 2103190100015 P P
12 Sadiq Ali Khan 2103190100020 A A
13 Shivang Chauhan 2103190100021 A P
14 Sohil Dilshad 2103190100022 A A
15 Swati 2103190100023 A A
16 Tushar 2103190100024 P P
17 Amit Singh 2203190109001 A A
18 Ayush Srivastav 2203190109002 P P
19 Devendra Waliya 2203190109003 P A
20 Nishij Yadav 2203190109004 A A
21 Udit Kumar Varshney 2203190109005 A A
22 Vicky Srivastav 2203190109006 P A
23 Vishal Sahu 2203190109007 P A
`85

SESSION: 2023-24

Short Attendance List


Semester: 5th

Attendance
S. No. Name Roll Number
(%)

1 Brij Kishor 2103190100007 50


2 Love Gupta 2103190100008 53
3 Mohammad Rizwan 2103190100009 49
4 Prabhat Bhardwaj 2103190100013 51
5 Sadiq Ali Khan 2103190100020 28
6 Sohil Dilshad 2103190100022 08
7 Swati 2103190100023 51
8 Amit Singh 2203190109001 0
9 Nishij Yadav 2203190109004 0
10 Udit Kumar Varshney 2203190109005 0
11 Vicky Srivastav 2203190109006 13
12 Vishal Sahu 2203190109007 52
`86

SESSION: 2023-24

Class Test Marks


Semester: 5th

UT – 1
S. No. Name Roll Number PUT (100)
(50)

1 Aastha Chaurasiya 2103190100001 18 58


2 Aman Gupta 2103190100002 9 45
3 Aryan Saxena 2103190100005 18 30
4 Bachitar Singh 2103190100006 9 A
5 Brij Kishor 2103190100007 8 2
6 Love Gupta 2103190100008 18 50
7 Mohammad Rizwan 2103190100009 11 A
8 Nandini Saxena 2103190100011 41 82
9 Pankaj Verma 2103190100012 18 45
10 Prabhat Bhardwaj 2103190100013 32 70
11 Prashant Singh 2103190100015 34 77
12 Sadiq Ali Khan 2103190100020 A A
13 Shivang Chauhan 2103190100021 A 77
14 Sohil Dilshad 2103190100022 A A
15 Swati 2103190100023 A A
16 Tushar 2103190100024 20 49
17 Amit Singh 2203190109001 A A
18 Ayush Srivastav 2203190109002 31 60
19 Devendra Waliya 2203190109003 0 A
20 Nishij Yadav 2203190109004 A A
21 Udit Kumar Varshney 2203190109005 A A
22 Vicky Srivastav 2203190109006 3 A
23 Vishal Sahu 2203190109007 2 A
`87

SESSION: 2023-24

List of Weak Students Semester: 5th


(Action taken for Improvement)

UT – 1
S. No. Name Roll Number PUT (100)
(50)

1 Bachitar Singh 2103190100006 9 A


2 Brij Kishor 2103190100007 8 2
3 Mohammad Rizwan 2103190100009 11 A
4 Sadiq Ali Khan 2103190100020 A A
5 Sohil Dilshad 2103190100022 A A
6 Swati 2103190100023 A A
7 Amit Singh 2203190109001 A A
8 Devendra Waliya 2203190109003 0 A
9 Nishij Yadav 2203190109004 A A
10 Udit Kumar Varshney 2203190109005 A A
11 Vicky Srivastav 2203190109006 3 A
12 Vishal Sahu 2203190109007 2 A

Action Plan for weak Students

(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

List of Bright Students Semester: 5th


(Action taken for enhancing
performance)

UT – 1
S. No. Name Roll Number PUT (100)
(50)

1 Aastha Chaurasiya 2103190100001 18 58


2 Nandini Saxena 2103190100011 41 82
3 Prabhat Bhardwaj 2103190100013 32 70
4 Prashant Singh 2103190100015 34 77
5 Ayush Shrivastava 2203190109002 31 60

Action Plan for Bright Students

(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

PrintedPages:02 Sub Code: KCS-502

Paper Id: Roll No.


231842

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

1. Attempt all questions in brief. 2x10=20


(a) How will you group the phases of compiler?
(b) Mention the role of semantic analysis.
(c) What are the various parts in LEX program?
(d) Differentiate Parse tree and Syntax tree with an example.
(e) Give the properties of intermediate representation.
(f) Differentiate between LR and LL parsers.
(g) What is phrase level error recovery?
(h) Discuss the capabilities of CFG.
(i) Define loop jamming.
(j) What is induction variable?

SECTION-B

2. Attempt any three of the following: 10x3=30


(a) Write SDD top roduce three address code for Boolean expressions and
obtain the three-address code for the statement given below:
`90

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

3) Attempt any one part of the following: 10x1=10


(f) Construct the CLR parse table for the following Grammar:
ABB

BCb

Bd

(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.

5) Attempt any one part of the following: 10x1=10


a. What is an activation record? Draw diagram of general activation
record and explain the purpose of different fields of an activation
record.
b. How do we represent the scope information? Explain scope by
number and scope by location.

6) Attempt any one part of the following: 10x1=10


a. Define Symbol table? Explain about the data structures used for
symbol table.
b. Explain the following:
i. Copy Propagation
ii. Dead-Code Elimination
iii. Code Motion
iv. Reduction in Strength.

7) Attempt any one part of the following: 10x1=10


a. Explain in the DAG representation of the basic block with example.
b. Write quadruple, triples and indirect triples for following expression:
a=b*–c+b*–c.
`92
`93

Question Paper SESSION: 2023-24

Semester: 5th

PrintedPages:02 Sub Code: KCS-502

Paper Id: Roll No.


310677

B.TECH.
(SEM V) THEORY EXAMINATION 2023-24

COMPILER DESIGN
`94

89

You might also like