Compiler Design: Instructor: Mohammed O. Samara University
Compiler Design: Instructor: Mohammed O. Samara University
Compiler Design: Instructor: Mohammed O. Samara University
Instructor: Mohammed O.
Email: [email protected]
Samara University
Preliminaries Required
oBasic knowledge of programming languages.
oBasic knowledge of FSA and CFG.
Chapter One: Introduction
This Chapter Covers:
Phases of a Compiler
Compiler Construction Tool
Introduction
Programming languages are notations for describing
computations (study) to people and to machines.
It takes all the tokens one by one and uses Context Free
Grammar to construct the parse tree.
Parsing Techniques
Depending on how the parse tree is created, there are
different parsing techniques.
Top-Down Parsing:
Construction of the parse tree starts at the root, and
proceeds towards the leaves.
Efficient top-down parsers can be easily constructed by
hand.
Recursive Predictive Parsing, Non-Recursive Predictive
Parsing (LL Parsing).
Parsing Techniques (Cont.)
Bottom-Up Parsing:
Construction of the parse tree starts at the leaves, and
proceeds towards the root.
Normally efficient bottom-up parsers are created with
the help of some software tools.
Bottom-up parsing is also known as shift-reduce parsing.
LR Parsing – much general form of shift-reduce parsing,
LR, SLR, LALR.
Semantic Analyzer
A semantic analyzer checks the source program for
semantic errors and collects the type information for the
code generation.
Ex:
MULT id2,id3,temp1
ADD temp1,#1,id1
Code Generator
The main purpose of code generator is to write a code that the
machine can understand (Produces the target language).
Ex:
MOVE id2,R1 - Register is a temporary storage area built into
a CPU
MULTid3,R1
ADD #1,R1
MOVE R1,id1
Symbol Table
This portion of the compiler keeps track of the names used
by the programme and records essential information about
each, such as its type (integer, real, etc.).