100% found this document useful (1 vote)
71 views

19ecs332: Compiler Design

This document describes a course on compiler design. The course aims to teach students about the various phases involved in designing a compiler through exploring basic techniques, algorithms, and data structures. It covers topics like lexical analysis, syntax analysis using both top-down and bottom-up parsing, syntax-directed translations to generate intermediate code, code optimizations, and code generation. The course objectives are to explore compiler construction principles and gain experience using automated tools to transform compiler phases. The course is divided into 5 units covering the above topics and a laboratory component involves implementing experiments related to compiler design phases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
71 views

19ecs332: Compiler Design

This document describes a course on compiler design. The course aims to teach students about the various phases involved in designing a compiler through exploring basic techniques, algorithms, and data structures. It covers topics like lexical analysis, syntax analysis using both top-down and bottom-up parsing, syntax-directed translations to generate intermediate code, code optimizations, and code generation. The course objectives are to explore compiler construction principles and gain experience using automated tools to transform compiler phases. The course is divided into 5 units covering the above topics and a laboratory component involves implementing experiments related to compiler design phases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

19ECS332: COMPILER DESIGN

L T P C
3 0 2 4

Compilers play a significant role in fulfilling user’s computing requirements, specified in terms of
programs in a high-level language, which translate into machine-understandable form. The process
involved in such a transformation of a program is quite complex. This course enables the students to
gain knowledge on various phases involved in designing a compiler. Automata Theory and Formal
Languages provides the basis for this course in which several automated tools help construct various
phases. Advanced computer architecture, memory management, and operating systems help the
compiler designer generate efficient code.

Course objectives:
 Explore the basic techniques that underlie the principles, algorithms and data structures
involved in the Compiler Construction.
 Gain experience in using automated tools that helps in transforming various phases of the
compiler.

UNIT I: Introduction & Lexical Analysis 8+4 T+P


Introduction: The Structure of Compiler, The Science of Building a Compiler in Bootstrapping and
Cross compiler.
Lexical Analysis: The role of the Lexical analyzer, Input Buffering, Specification of Tokens,
Recognition of Tokens, The Lexical Analyzer Generator (LEX/FLEX).

Learning Outcomes:
After completion of this unit, the student will be able to
 summarizing various phases involved in the design of compiler construction(L2)
 comparing methods involved in constructing the compiler(L2)
 highlighting how regular expressions help to design the Lexical Analysis phase(L1)
 exploring how LEX Tool simplifies the design of the Lexical Analysis phase(L2)

UNIT II: Syntax Analysis (Part-I) 8+6 L+P


Introduction, Context-Free Grammars, Top-Down parsing: Brute force Parsing, Recursive Descent
Parsing, Non-recursive Predictive Parsing, Error Recovery in Predictive Parsing, Bottom-Up parsing -
Shift Reduce Parsing, Operator-Precedence Parsing, Error Recovery in Operator Precedence Parsing.
Learning Outcomes:
After completion of this unit, the student will be able to
 design the possible ways of constructing Syntax Analysis Phase (L3)
 identifying the issues involved in creating an efficient Top-Down (LL) parser(L1)
 implementing both bottom-up and top-down parsers (L3)
 illustrating the deficiencies in the design of basic Bottom-Up parsers(L4)

UNIT III: Syntax Analysis (Part-II) 8+3 L+P


Introduction to LR Parsing: Simple LR Parser, More Powerful LR Parsers, Using Ambiguous
grammars, Error Recovery in LR Parsers, Parser Generator (YACC).

Learning Outcomes:
1
After completion of this unit, the student will be able to

2
 identifying the issues involved in designing efficient Bottom-Up (LR) Parses(L1)
 predicting the role of look-ahead in LR parsers(L2)
 illustrating the significance of using ambiguous grammars in LR Parses(L4)
 assessing how YACC Tool simplifies the design of Parser(L5)

UNIT IV: Syntax Directed Translation & Intermediate Code Generation 8+2 L+P
Syntax Directed Translation: Syntax Directed Definitions, Evaluation Orders for SDD’s,
Applications of Syntax-Directed Translation.
Intermediate Code Generation: Three Address codes, Types & Declarations, Translation of
Arithmetic Expressions, Back patching for Boolean Expressions, and Flow of Control.

Learning Outcomes:
After completion of this unit, the student will be able to
 summarizing the notational framework of Syntax Directed Definitions(L2)
 designing Syntax Directed Definitions to generate intermediate code(L3)
 illustrating various techniques to store three address statements(L3)
 designing Syntax Directed Definitions for Boolean expressions using back patching (L3)

UNIT V: Code Optimization & Code Generation 8 L


Code Optimization: The Principal Sources of Optimization, Basic blocks and Flow Graphs,
Optimization of Basic Blocks, Introduction to Data-Flow Analysis: Live Variable Analysis
Code Generation: Issues in designing a code Generator, The Target Language, A Simple Code
Generator, Peephole Optimization, Register allocation, and Assignment.

Learning Outcomes:
After completion of this unit, the student will be able to
 identifying issues involved in the machine-independent code optimization(L1)
 illustrating with a suitable example on local and loop optimization(L4)
 determining the issues involved in global optimization techniques(L3)
 estimating the processes involved in obtaining the final code, register allocation, and
assignment(L2)

Text Books(s)
1. Alfred.V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey. D. Ullman, Compilers Principles,
Techniques and Tools, 2/e, Pearson Education, 2008.

References
1. Alfred.V. Aho, J.D.Ullman, Principles of compiler design, Narosa Publications, 2002
2. John R. Levine, Tony Mason, Doug Brown, Lex &yacc, O’reilly ,2/e, 1992
3. Keith Cooper, Linda Torczon, Engineering a compiler, Morgan Kaufmann, 2/e, 2011.

Course Outcomes:
After completion of this course, the student will be able to
 define and analyse various phases involved in designing a compiler(L1)
 compare and contrast between bottom-up and top-down parsing techniques(L2)
 illustrate the usage of Syntax Directed Definition in generating intermediate code(L3)
 identify various machine independent optimization techniques(L4)
 explore techniques involved in obtaining the final code(L4)

3
COMPILER DESIGN LABORATORY
For Laboratory courses: List of Experiments:
1. Implement transition diagram for identifying an identifier and classify whether it is either
variable or array or function or structure.

2. Implement transition diagram for identifying constant and classify whether it is integer or
real.

3. Write a LEX specification which takes input from a file (a C’ program) and recognize valid
identifiers, keywords contained in the program and store them in a file.

4. Write a LEX specification for lexical analyzer of C’ language in which it recognizes all
possible tokens in a given program taken as a file and output all the tokens into another
file.

5. The production “A → α1 / α2 /α3 ...” of the CFG uses the following structure/class
representation.
struct/class production
{
char left, //Head of the production ie., left hand side
char right(10)(10), //body of prod ie., all alternatives are represent as array of
strings int noa, //noa means no of alternatives in the production
},

Similarly the Context Free Grammar can be represented as


struct / class CFG
{
production p(10), // all productions of the
grammar int nop, //nop means no of production.
char t(10), nt(10), s, // string of t’s , nt’s and start symbol (optional)
},
The following programs are to be implementing using the above representation.
a. Write a program which reads single productions of the form “ A → α1 , A →α2, A
→ α3 ... “ and make them into a single production “A → α1 / α2 /α3 ...” and display.
b. Write a program which reads single productions of the form “ A → α1 , B →α2, B
→ α3 ... “ and build CFG and display.
c. Write a program which reads a production and check for Left-Recursion (may contain
in more than one alternatives) and if found eliminate it and store in another
production and display the result.
d. Write a program which reads a grammar and check for Left-Recursion (may contain
in more than one productions) and if found eliminate it and store in another grammar
and display the result.
e. Write a program which reads a production, factor out the alternatives if required using
left factoring and store the result in to another production and display it.
f. Write a program which reads a grammar, factor out the alternatives of each
production if required using left factoring and store the result in to another grammar
and display it.
g. Write a program which reads a grammar and find First symbols of all non-terminals.
h. Write a program which reads a grammar and find Follow symbols of all non-
4
terminals.

6. Write a program to implement Recursive Descent Parser for any given grammar.

7. Write a program to implements Operator Precedence Parsing algorithm.

8. Consider the following Expression language that used to describe the Arithmetic expressions
in a Calculator The syntax of the language is defined by following grammar
<line> <exp>\n
<exp> <exp>+ <term>| <exp>-<term>|<term>
<term> <term>*<factor>|<term>/<factor>/<factor>
<factor> (<exp>)|<value>
<value> <letter>|<digit>
A sample arithmetic expression written in this language is(a+b)*c\n or 2 + 4 * 5 -6 /2\n
a. Design a LEX specification for the above language. (Ignore redundant spaces, tabs and
newlines). Although the syntax specification states that value can be arbitrarily long, you
may restrict the length to some reasonable value. (Implement the lexical analyser using
JLex, flex or lex or any other tools)
b. Write YACC Specification to validate any given arithmetic expression accepted by the
above grammar.
c. Write YACC specification to evaluate the given arithmetic expression accepted by the
above grammar.
d. Write YACC specification to generate three address code and quadruples for any given
expression.
e. Write YACC specification to convert an infix expression to a postfix expression.

9. Consider the following grammar which is used to describe the X language which might be
used in next generation programmable calculators. It supports integer, real and complex
numbers This language uses something called Hungarian notation the name of the variable
itself tells you about the type of the data it contains if the starting letter is 'i’ then integer , 'r'
then real , 'c' then complex number
<program> begin<stmts>end
<stmts> <statement>,<stmts>| <statement>,
<statement> <identifer>=<expr> | <conditional>
<expr> <expr> + <term> |<expr>-<term>|<term>
<term> <term>*<fact>|<fact>
<fact> <identifier><conditional>--->if <cexpr>thenbegin<stmts>end
<cexpr> <identifier>==<identifier> |<identifier>!=<identifier>
<identifier> i<letters>|r<letters>|c<letters>
<letters> <letter><letters>|<letter>
<letter> a|b|....|z|A|B|.....|Z

a. Design a LEX specification for the above language. (Ignore the redundant spaces, tabs and
newline Although the syntax specification states that value can be arbitrarily long, you may restrict
the leng to some reasonable value. (Use JLex, flex or lex or any other lexical analyser generating
tools).
b. Write YACC specification to generate three address code and quadruples for the given
arithmetic statement.

5
c. Write YACC specification to validate the statements of the above language.
d. Write program to generate 8086 assembly code from the abstract syntax tree or three address
code generated by the parser. The target assembly instructions can be simple move, add, sub,
and jump. Also simple addressing modes are used.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy