Docsity

Two-Pass Compiler: Understanding the Front-End and Back-End, Assignments of Compiler Construction

Partial preview of the text

Download Two-Pass Compiler: Understanding the Front-End and Back-End and more Assignments Compiler Construction in PDF only on Docsity!

CSC373-Compiler Construction Week-3 Lecture- Semester-#5 Fall 2019 Prepared by: Eisha Tir Razia Lahore Garrison University

Overview of previous lecture

 (^) Symbol Table  (^) How to construct Symbol Table? Lahore Garrison University

Lecture Outcomes

 (^) Understanding related to  (^) Two-Pass Compiler Lahore Garrison University

The Grouping of Phases into Passes

 (^) The discussion of phases deals with the logical organization of a compiler. In an implementation, activities from several phases may be grouped together into a pass that reads an input file and writes an output file.  (^) For example, the front-end phases of lexical analysis, syntax analysis, semantic analysis, and intermediate code generation might be grouped together into one pass. Code optimization might be an optional pass. Then there could be a back-end pass consisting of code generation for a particular target machine. Lahore Garrison University

Two-pass Compiler 7

Front

End

Back

End

source

code

IR machine

code

errors

Two-pass Compiler

 (^) Use an intermediate representation (IR)  (^) Front end maps legal source code into IR

Two-pass Compiler

 (^) Front end is O(n) or O(n log n)  (^) Back end is NP-Complete (NPC)

Front End

 (^) Recognizes legal (& illegal) programs  (^) Report errors in a useful way  (^) Produce IR & preliminary storage map

Scanner

scanner parser

source

code

tokens IR

errors

Scanner 14

 (^) Maps character stream into words – basic unit of syntax  (^) Produces pairs –  (^) a word and  (^) its part of speech

Scanner 16

 (^) we call the pair “<token type, word>” a “token”  (^) typical tokens: number , identifier , +, -, new , while , if

Parser

 (^) Recognizes context-free syntax and reports errors  (^) Guides context-sensitive (“semantic”) analysis  (^) Builds IR for source program

References

 (^) These lecture notes were taken from following source:  (^) Compilers: Principles, Techniques, and Tools By Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman, Contributor Jeffrey D. Ullman, Addison- Wesley Pub. Co., 2nd edition, 2006 Lahore Garrison University