0% found this document useful (0 votes)
2 views16 pages

Understanding Compiler Structure and Design

The document outlines a course on compilers, detailing the agenda, instructors, grading system, and reasons for studying compilers. It describes the steps involved in compiler construction, including lexical analysis, syntax analysis, semantic analysis, intermediate representation generation, optimization, and code generation. Additionally, it provides examples of input and output streams, parse trees, and optimization techniques.

Uploaded by

gamalmido455
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Understanding Compiler Structure and Design

The document outlines a course on compilers, detailing the agenda, instructors, grading system, and reasons for studying compilers. It describes the steps involved in compiler construction, including lexical analysis, syntax analysis, semantic analysis, intermediate representation generation, optimization, and code generation. Additionally, it provides examples of input and output streams, parse trees, and optimization techniques.

Uploaded by

gamalmido455
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Compilers

Introduction

1
2

Agenda
 Course Information
 Why Study Compilers?
 The Structure of a Compiler.
3

Instructors
 Lectures:
 Dr. Shimaa Ibrahim Hassan
 [Link]@[Link]
 shimaahassan4779@[Link]

 Sections:
 Eng: Mahmouud Mohadmed
4

Main Book
5

Grading system
 Finalexam ................................. 40
degrees
 Mid-term .................................. 30
degrees
 Section ....................................... 10
degrees
 Quizes ......................................... 5
degrees
 Project ........................................ 15
degrees
6

Why Study Compilers?


 Learn how programming languages work.
 Learn how to build programming
languages.
 Learn tradeoffs in language design.
 Build a large software system.
7

From Description to
Implementation
 Lexical analysis: Identify logical pieces of
description.
 Syntax analysis: Identify how those pieces relate to
each other.
 Semantic analysis: Identify the meaning of those
relations.
 IR Generation: Generate an intermediate code
(three address code).
 IR Optimization: Simplify the intermediate code.
 Code Generation: Generate the assembly code.
 Optimization: Improve the resulting assembly.
8

The Structure of a Modern


Compiler
9

Lexical Analysis

while (y < z) {
int x = a + b;
y += x; }
10

Lexemes vs Tokens
 Input Stream:
while (y < z) {
int x = a + b;
y += x; }

 Output Stream (Tokens):


T_While T_LeftParen T_Identifier y T_Less T_Identifier
z T_RightParen T_OpenBrace T_Int T_Identifier x
T_Assign T_Identifier a T_Plus T_Identifier b
T_Semicolon T_Identifier y T_PlusAssign T_Identifier
x T_Semicolon T_CloseBrace
11

Syntax Analysis

Parse Tree:
12

Semantic Analysis
13

IR Generation

while (y < z) {
int x = a + b;
y += x; }

Loop: x = a + b
y =x+y
_t1 = y < z
if _t1 goto Loop
14

IR Optimization
while (y < z) {
int x = a + b;
y += x; }

x =a+b
Loop: y = x + y
_t1 = y < z
if _t1 goto Loop
15

Code Generation

while (y < z) {
int x = a + b;
y += x; }

add $1, $2, $3


Loop: add $4, $1, $4
slt $6, $4, $5
bne $6, $zero, loop
16

Optimization

while (y < z) {
int x = a + b;
y += x; }

add $1, $2, $3


Loop: add $4, $1, $4
blt $4, $5, loop

You might also like