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
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6125)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8214)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2922)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2619)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2530)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)