Compiler Designs and Constructions - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Compiler Designs and Constructions

Description:

Demonstration of a simple Compiler. One Pass Compiler. Dr. ... Ass 50 = ass_op. num 15 2 num. plus 51 add_op. id 10 Total id. minus 51 - add_op. num 15 17 num ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 13
Provided by: rawaj
Category:

less

Transcript and Presenter's Notes

Title: Compiler Designs and Constructions


1
Compiler Designs and Constructions
  • Chapter 2 A Simple Compiler
  • Objectives
  • Demonstration of a simple Compiler
  • One Pass Compiler
  • Dr. Mohsen Chitsaz

2
Simple Compiler
  • Example of a Simple Compiler
  • Language
  • A2
  • BA
  • CAB-2
  • Method of representation
  • Bachus-Naur-Form (BNF)
  • Syntax Diagram
  • SALARY 2TOTAL 17

3
Simple Compiler
  • Grammar
  • ltstatementgt ----gt ID ltexpressiongt
  • ltexpressiongt ----gt ltprimarygt
  • ltexpressiongt ----gtltprimarygt ltadd_opgt
    ltexpressiongt
  • ltprimarygt ----gt ID
  • ltprimarygt ----gt NUM
  • ltadd_opgt ----gt
  • ltadd_opgt ----gt -

4
Simple Compiler
  • Scanner (Lexical Analyzer)(Tokenizer)
  • Salary 2 Total 17
  • Token Token Token
  • Representation Lexeme Type (Attribute)
  • id 10 Salary id
  • Ass 50 ass_op
  • num 15 2 num
  • plus 51 add_op
  • id 10 Total id
  • minus 51 - add_op
  • num 15 17 num
  • semicolon 53 semicolon

5
Simple Compiler
  • Symbol Table, Literal Table
  • Salary 2 Total 17
  • Identifier Type Value
  • Salary int
  • Total int 150

6
Simple Compiler
  • Parser (Syntax Analyzer)
  • Parse Tree
  • Salary 2 Total 17

7
Simple Compiler
  • Syntax Tree
  • Salary 2 Total 17

8
Simple Compiler
  • 5. Semantic Analyzer
  • Salary 2 Total 17

9
Simple Compiler
  • Intermediate Code Generation
  • Salary2 total 17

10
Simple Compiler
  • Why intermediate code and not assembly code

Pascal
C
Python
Intermediate Code
Final Object Code
11
Simple Compiler
  • Code Optimization
  • a. Salary 2 Total 17
  • b. Salary Total 15

12
Simple Compiler
  • Final Code Generation
  • a. ADDL3 Total , 2, R5
  • SUBL3 R5, 17, Salary
  • b. SUBL3 Total, 15, Salary
Write a Comment
User Comments (0)
About PowerShow.com