Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
18 views
Structure of Compiler
Uploaded by
Innovative Industry
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Structure of compiler For Later
Download
Save
Save Structure of compiler For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
18 views
Structure of Compiler
Uploaded by
Innovative Industry
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Structure of compiler For Later
Carousel Previous
Carousel Next
Save
Save Structure of compiler For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 3
Search
Fullscreen
(RUCTURE OF A COMP! ‘The compilation process is a sequence of various phases. Each phase takes input from its previous, stage, has its own representation of the source program, and feeds its output to the next phase of the compiler. Let us understand the phases of a compiler. ‘aon Ate yn Aneto Semantic Anaiyeer ‘Cosa open Lexical Analysis: '¢ lexical analysis or scanning forms the first phase of a compiler. ‘* The lexical analyzer reads the stream of characters which makes the source program and groups them into meaningful sequences called lexemes, For each lexeme, the lexical analyzer produces tokens as output. ‘A token format is shown below. ‘token-name, attribute-value> ‘* These tokens pass on to the subsequent phase known as syntax analysis, ‘¢ The token elements are listed below ‘Token-name: This is an abstract symbol used during syntax analysis Attribute-value: This points to an entry in the symbol table for the corresponding token, ‘¢ Information from the symbol-table entry ‘is needed for semantic analysis and code ger For example, let us try to analyze a simple arithmetic expression evaluation in Lexical context Assignment Symbol I y‘The expression is seen by Lexical analyzer as
<=>
<+>
<*> <60> Syntax Analysis ‘© Syntax analysis forms the second phase of the compiler. ‘© The list of tokens produced by the lexical analysis phase forms the input and arranges them in the form of tree structure (called the syntax tree). This reflects the structure of the program. This phase is also called parsing. ‘* The syntax tree consists of interior node representing an operation and the child of the node representing arguments. A syntax tree for the token statement is as shown in the above example, © Operators are considered as root nodes of this syntax tree. In the above case = has left and a right node. The left node consists of
and the right node is again parsed and the immediate operator is taken as right node (id,1y~ + aay a (id, 3) 60 Semantic analysis ‘© Semantic analysis forms the third phase of the compiler. This phase uses the syntax tree and the formation in the symbol table to check the source program for consistency with the language definition, ‘* This phase also collects type information and saves it in either the syntax tree or the symbol table, for subsequent use during intermediate-code generation, ‘© Type checking forms an important part of semantic analysis. Here the compiler checks whether each operator has matching operands ‘* Coercions (some type of conversions) may be permitted by the language specifications. If the operator is applied to a floating-point number and an integer, the compiler may convert or coerce the integer into a floating-point number, Coercion exists in the example quoted position = initial + rate * 60 ‘© Suppose position, initial and rate variables are declared as float. Since the
is a floating point, then 60 is also converted to a floating-point. ‘© The syntax tree is modified to include the conversion/semantic aspects. In the example quoted 60 is converted to float as inttofloat, (id, 1) gp (id,27~ (id,3)~ — inttofloat 1 ’ 60Intermediate Code Generation ‘Intermediate code generation forms the fourth phase of the compiler. After syntax and semantic analysis of the source program, many compilers generate a low level or machine-like intermediate representation, which can be thought as a program for an abstract machine, ‘+ This intermediate representation must have two important properties (a) It should be easy to produce (b) It should be easy to translate into the target machine t1 = inttofloat (60) Code Optimization ‘© Code Optimization forms the fifth phase in the compiler design ‘+ This is a machine-independent phase that attempts to improve the intermediate code for generating better (Faster) target code, t1= id3 * 60.0 id1 = id2 +t1 Code Generator © Code Generator forms the sixth phase in the compiler design, This takes the intermediate representation of the source program as input and maps it to the target language. ‘© The intermediate instructions are translated into sequences of machine instructions that perform the same task. A critical aspect of code generation is the assignment of registers to hold variables. Using R1 & R2 the intermediate code will get converted into machine code. LDF R2, id3 MULF R2, R2, #60.0 ADDF R1, R1, R2 STF id1,R1 Symbol-Table Management ‘© Anessential function of a compiler isto record the variable names used in the source program and collect {information about various attributes of each name. ‘+ These attributes may provide information about the storage allocated for a name, its type, its scope (wherein the program its value may be used), and in the case of procedure names, such things as the number and types of its arguments, the method of passing each argument (for example, by value or by reference), and the type returned. © The symbol table is a data structu attributes of the name. Error Handling ‘© One of the most important functions of a compiler is the detection and reporting of errors in the source program. The error message should allow the programmer to determine exactly where the err occurred. Errors may occur in all or the phases of a compiler. containing a record for each variable name, with fields for the ‘© Whenever a phase of the compiler discovers an error, it must report the error to the error handler, which. issues an appropriate diagnostic msg. Both of the table-management and error-Handling routines interact swith all phases of the compiler.
You might also like
Chapter One-Introduction
PDF
No ratings yet
Chapter One-Introduction
6 pages
Phases of A Compiler
PDF
No ratings yet
Phases of A Compiler
17 pages
Lec 2
PDF
No ratings yet
Lec 2
21 pages
Compiler Construction Design Phases
PDF
No ratings yet
Compiler Construction Design Phases
7 pages
CD Full Material
PDF
No ratings yet
CD Full Material
74 pages
UNIT-I Compiler Design - SCS1303: School of Computing Department of Computer Science and Engineering
PDF
No ratings yet
UNIT-I Compiler Design - SCS1303: School of Computing Department of Computer Science and Engineering
27 pages
SCS13033
PDF
No ratings yet
SCS13033
121 pages
Com Phases
PDF
No ratings yet
Com Phases
10 pages
SSCDNotes PDF
PDF
100% (1)
SSCDNotes PDF
53 pages
phases of compiler
PDF
No ratings yet
phases of compiler
12 pages
COMPILER DESIGN UNIT 1
PDF
No ratings yet
COMPILER DESIGN UNIT 1
30 pages
Compilation Phases
PDF
No ratings yet
Compilation Phases
20 pages
CD UNIT 1 Chapter 1
PDF
No ratings yet
CD UNIT 1 Chapter 1
9 pages
Unit 1 CD
PDF
No ratings yet
Unit 1 CD
26 pages
CD 1
PDF
No ratings yet
CD 1
23 pages
Compiler Design Mod 1
PDF
No ratings yet
Compiler Design Mod 1
75 pages
SCSA1604
PDF
No ratings yet
SCSA1604
133 pages
Unit 1
PDF
No ratings yet
Unit 1
37 pages
phases of compiler
PDF
No ratings yet
phases of compiler
36 pages
SPCCPDF
PDF
No ratings yet
SPCCPDF
83 pages
CC Assignment
PDF
No ratings yet
CC Assignment
6 pages
Phase 1: Lexical Analysis: Example
PDF
No ratings yet
Phase 1: Lexical Analysis: Example
6 pages
Compiler Design - YesDee(1)
PDF
No ratings yet
Compiler Design - YesDee(1)
427 pages
Unit-1 PCD
PDF
No ratings yet
Unit-1 PCD
28 pages
CST302_FullNotes
PDF
No ratings yet
CST302_FullNotes
134 pages
Compiler Notes
PDF
No ratings yet
Compiler Notes
66 pages
CompilerLab1 1637
PDF
No ratings yet
CompilerLab1 1637
5 pages
CD Unit I
PDF
No ratings yet
CD Unit I
27 pages
1.Q and A Compiler Design
PDF
No ratings yet
1.Q and A Compiler Design
20 pages
Lecture 1,2 Introduction
PDF
No ratings yet
Lecture 1,2 Introduction
40 pages
rkCD-Chapter 1 - INTRO TO COMPILERS
PDF
No ratings yet
rkCD-Chapter 1 - INTRO TO COMPILERS
11 pages
Language Processing System:-: Compiler
PDF
No ratings yet
Language Processing System:-: Compiler
6 pages
Compiler Construction Week 2
PDF
No ratings yet
Compiler Construction Week 2
29 pages
Introduction To Compilers - Analysis of The Source Program - Phases of A Compiler Phases of Compiler
PDF
No ratings yet
Introduction To Compilers - Analysis of The Source Program - Phases of A Compiler Phases of Compiler
25 pages
What Is Translators
PDF
No ratings yet
What Is Translators
95 pages
What Are The Phases of Compiler Design
PDF
No ratings yet
What Are The Phases of Compiler Design
6 pages
THE PHASES OF COMPILER
PDF
No ratings yet
THE PHASES OF COMPILER
3 pages
Lecture 01
PDF
No ratings yet
Lecture 01
47 pages
Compiler 1
PDF
No ratings yet
Compiler 1
28 pages
Lec#1
PDF
No ratings yet
Lec#1
36 pages
Modern Compilers
PDF
No ratings yet
Modern Compilers
35 pages
CD_ UNIT-1
PDF
No ratings yet
CD_ UNIT-1
10 pages
PCD Notes - Unit - 1
PDF
No ratings yet
PCD Notes - Unit - 1
15 pages
Module 1
PDF
No ratings yet
Module 1
133 pages
Compiler Notes 1
PDF
No ratings yet
Compiler Notes 1
20 pages
Compiler Design Slide Chapter 1-6
PDF
No ratings yet
Compiler Design Slide Chapter 1-6
250 pages
Introduction To Compiler Lexical Analysis Notes
PDF
No ratings yet
Introduction To Compiler Lexical Analysis Notes
21 pages
Unit I SRM
PDF
100% (1)
Unit I SRM
36 pages
Cdmodule 1
PDF
No ratings yet
Cdmodule 1
25 pages
Compiler Design
PDF
No ratings yet
Compiler Design
47 pages
Compiler
PDF
No ratings yet
Compiler
6 pages
Introduction To Compilers Complier: Ompiler Source Program Target Program Error Message
PDF
No ratings yet
Introduction To Compilers Complier: Ompiler Source Program Target Program Error Message
23 pages
AT_Module6_Compiler and its phases_PS
PDF
No ratings yet
AT_Module6_Compiler and its phases_PS
32 pages
cse-module-8
PDF
No ratings yet
cse-module-8
32 pages
Ch1 Introduction
PDF
No ratings yet
Ch1 Introduction
12 pages
PCD Lab Manual
PDF
No ratings yet
PCD Lab Manual
60 pages
DFJDFJ
PDF
No ratings yet
DFJDFJ
12 pages
Cousins of Compiler
PDF
100% (1)
Cousins of Compiler
25 pages
CD - 1
PDF
No ratings yet
CD - 1
22 pages