1. 5/11/2021 Saeed Parsa 1
Compiler Design
Course Introduction
Saeed Parsa
Room 332,
School of Computer Engineering,
Iran University of Science & Technology
parsa@iust.ac.ir
Winter 2021
2. Who, when/where, and what?
• Who are we?
• Lecturer
• Saeed Parsa
• Associate Professor in IUST
• Research Area: Software Engineering, Software Testing,
Software Debugging, Reverse Engineering, etc.
• Email: parsa@iust.ac.ir
• More Information:
• http://parsa.iust.ac.ir/
• Slide Share
• https://www.slideshare.net/SaeedParsa
5/11/2021 Saeed Parsa 2
3. Who, when/where, and what?
• When/where will attend the class?
• Time: 09:00-10:30 on Saturday & Monday
• Class: Virtual (Hope to have physical class soon!)
• What will we read (textbook)?
• No textbook is required for the class.
• You may use the slides prepared for the course.
• However, you may find a textbook useful as a reference or to learn
more details of some of the ideas discussed in the course.
5/11/2021 Saeed Parsa 3
4. Who, when/where, and what?
• Suggested References:
• Language Implementation Patterns, by Terence Parr
• Compilers Principles, Techniques & tools, by Alfred V. Aho
5/11/2021 Saeed Parsa 4
5. 2020 ACM A.M. Turing Award Laureates
• ACM Turing Award Honors Innovators Who Shaped the Foundations
of Programming Language Compilers and Algorithms
12 April 2021 Advanced compiler - Morteza Zakeri, Ph.D. Student 5
Alfred Vaino Aho Jeffrey David Ullman Dragon book
7. Class policies
• Exams to be done on the date given
• We have a quiz/midterm after each chapter
• There will be at least several homeworks & quizzes before the
last possible drop date.
• Class participation & attendance
• Attendance in the main class is required.
• The students whose number of absences are more than 6 session, have to
drop the course!
• Participation & being active in class will be encouraged.
5/11/2021 Saeed Parsa 7
8. Class policies
• The due dates are to be taken seriously and you should not expect them to be
extended.
• Homework to be graded should be turned on the specified due date.
• NO late programs or homework will be accepted FOR FULL CREDIT
without discussion with me prior to the due date.
• Allowing no late assignments would not give you much incentive to
continue to work on the assignment, which is a major source of learning in
this course.
5/11/2021 Saeed Parsa 8
9. Class policies
• Thus, I believe late assignments are better than no assignment.
• Late assignments will be penalized:
• 5% off the total possible points if turned in within the first 24-hour
period after the specified due date and time, and
• 5% per 24-hour period (or fraction of a day) (including weekends) after
that time, up to a week after the due date.
5/11/2021 Saeed Parsa 9
10. Class policies
• Any question
• You can communicate with me in Skype.
• Just search live:saeedparsa
5/11/2021 Saeed Parsa 10
11. Course Learning Objectives
1. Describe the various phases of a compiler
2. Use regular expressions & context free languages to define a language syntax.
3. Create a grammar for a simple context free language
4. Implement a lexical analyzer to recognize tokens defined by regular expressions
5. Implement a parser, using either top down (recursive descent) or bottom up (LR)
techniques
6. Generate working target language for simple programming constructs.
5/11/2021 Saeed Parsa 11
12. Course Learning Objectives
• This course examines the fundamental theory and practice of implementing
today's programming languages.
• The compiler course is an important component in the undergraduate
Computer Science curriculum.
5/11/2021 Saeed Parsa 12
13. Prerequisites
Automata Theory provides the base of the course on which several automated
tools can be designed to be used at various phases of a compiler.
Advances in computer architecture,
Machine code and assemblers,
Memory management and operating systems provide the compiler designer
large number of options to try out for efficient code generation.
Data structures.
5/11/2021 Saeed Parsa 13
14. Why Study Compilers?
• Compilers provide a bridge between applications and architectures.
• Compilers encapsulate techniques for reasoning about programs and their behavior.
• First major computer application.
• An opportunity to explore compiler techniques in both breadth and depth
Parallelization? Functional? Optimizations with more details.
• Compiler optimizations rely on both program analysis and transformation.
5/11/2021 Saeed Parsa 14
15. Why Study Compilers?
• Program analysis and transformation are useful in many related areas:
• Software engineering:
program understanding / reverse engineering / debugging / Testing
Run - time support and improvement
• Open problems Engineering effort:
limits and issues Motivate research topics “Advanced Compiler
Techniques”.
5/11/2021 Saeed Parsa 15
16. Grading policy
• Five Programming Assignments
(8% × 5 = 40%): (tentatively) out on weeks 1, 3, 5, 9, 12
• Three Midterms and Final exam
(5% + 5% + 5% + 15% = 30%): around weeks 3, 8, 11 and 17
• One non-programming Assignment
(5%)
• Final Project
(20%) -- In groups of three
• Class Participation
(5%) -- Both in-class & on canvas; helping your peers will be rewarded.
5/11/2021 Saeed Parsa 16
17. Course Layout
Being primarily targeted to a one-semester course for the undergraduate
students, the course will cover the following topics:
Week 1 Introduction
- Compilation steps
- How to install ANTLR
- Assignment 1: Install and use ANTLR.
5/11/2021 Saeed Parsa 17
18. Course Layout
Week 2 Lexical Analysis
- Input, output and body of the lexical analyzer.
- Regular expressions
- Assignment 2: Report on how to use REGX class.
Week 3 - Use ANTLR to develop a lexical analyzer.
- Assignment 3: Use ANTLR to develop a lexical analyzer.
- Solving examples.
- Assignment 1 deadline.
Week 4 - Solving examples.
- Midterm exam-1.
- Assignment 2 deadline.
5/11/2021 Saeed Parsa 18
19. Course Layout (Continued)
Week 5 Languages and Grammars
- Grammars and parse tress.
- Ambiguous grammars.
Week 6 - First and follow sets
- Use ANTLR to build parse trees.
- Use ANTLR to build parse tree for C# programs.
Week 7 Top-down parsers
- LL(1) parsers.
- LL(1) parsing tables.
5/11/2021 Saeed Parsa 19
20. Course Layout (Continued)
Week 8 Recursive Descent parsers
- How to develop recursive descent parsers.
- Using ANTLR to develop a recursive descent parser.
- Assignment 4: Use ANTLR to develop a recursive descent parser
- Assignment 3 deadline.
Week 9 Bottom-up parsers
- Bottom up parsing
- LR(1) Grammars
5/11/2021 Saeed Parsa 20
23. Why am I teaching this course?
• “If you don’t understand compilers, you can still write programs – you
can even be a competent programmer – but you can’t be a master.”
– Hal Abelson,
MIT
• “If you don’t know how compilers work, then you don’t know how
computers work. If you’re not 100% sure whether you know how
compilers work, then you don’t know how they work.”
– Steve Yegge
5/11/2021 Saeed Parsa 23
24. Why am I teaching this course?
• Development of tools for
- Reverse engineering
- Software testing
- Software quality assessment
- Source code analysis
Is based on compiler techniques.
5/11/2021 Saeed Parsa 24
25. How to increase your learning?
• Participate actively in class.
• This course is not meant to be a passive learning course, as it has
been shown that the best learning occurs when the learner is an
active participant, not a passive listener. Besides, classes are much
more enjoyable when the audience actively participates!
• Read the textbook.
• At least read the chapter as each new topic is covered in class.
Besides, you should not expect to gain all understanding of the
concepts from passively listening in the class periods alone.
5/11/2021 Saeed Parsa 25
26. How to increase your learning?
• Take an active role in your group projects.
• Ask your group members to explain concepts you do not clearly
understand, and share ideas among the group members. Meet
regularly with your group.
• Form an informal study group outside of class.
• Compare your notes from class, work together on group projects,
and discuss concepts you find unclear.
• Seek help if you start to feel lost, ASAP.
• Ask questions via chat room.
5/11/2021 Saeed Parsa 26
27. Prelude
Q: Who wrote the first compiler, when, and for what language?
A: Admiral Grace Murray Hopper in 1952
Q: What language did it compile?
A: A-0 (similar to 3-address code) for the UNIVAC I at Eckert-Mauchly Computer
Corporation
Q: What other interesting things did Admiral Hopper accomplish?
A: Helped develop COBOL for the UNIVAC
A: In 1969, awarded the first ever Computer Science “Man-of-
the-Year” Award from the Data Processing Management Association.
A: Rear Admiral in the Navy (highest rank for a woman)
A: In 1986, at 80, oldest active duty officer in the US.
A: In 1991, the National Medal of Technology (first woman to win)
Quote: “It's easier to ask forgiveness than it is to get permission.”
5/11/2021 Saeed Parsa 27
28. Phases of a Compiler
1. Lexical Analysis:
Converts a sequence of characters into words, or tokens
2. Syntax Analysis:
Converts a sequence of tokens into a parse tree
3. Semantic Analysis:
Manipulates parse tree to verify symbol and type information
4. Intermediate Code Generation:
Converts parse tree into a sequence of intermediate code instructions
5. Optimization:
Manipulates intermediate code to produce a more efficient program
6. Final Code Generation:
Translates intermediate code into final (machine/assembly) code
5/11/2021 Saeed Parsa 28
29. The place of IUST in the world
5/11/2021 Saeed Parsa 29
https://www.researchgate.net/publication/328099969_Software_Fault_Localisation_A_Systematic_Mapping_Study