SlideShare a Scribd company logo
1 of 17
Assignment Statements
Bp150526
Divya.D
M.Sc.Computer Science
Sacred Heart College
Topics
• Names in the symbol table
• Reusing temporary names
• Addressing array elements
• The translation scheme for addressing array
elements.
• Accessing fields in records
Names in the Symbol table
• Emit (instruction): emit a three address statement to the
output
• newtemp: return a new temporary
• lookup(identifier): check if the identifier is in the
symbol table.
• Grammar:
S->id:=E
E->E1+E2
E->E1*E2
E->-E
E->(E1)
E->id
Translation scheme to produce three address
code for assignment statement
S->id:=E {p:=lookup(id.name);
if (p!=nil) then
emit(p ‘:=‘ E.place); else error}
E->E1+E2 {E.place = newtemp;
emit(E.place ‘:=‘ E1.place ‘+’ E2.place);}
E->E1*E2 {E.place = newtemp;
emit(E.place ‘:=‘ E1.place ‘*’ E2.place);}
E->-E1 {E.place = newtemp;
emit(E.place ‘:=‘ ‘-’ E1.place);}
E->(E1) {E.place = E1.place;}
E->id {p = lookup(id.name);
if (p!= nil) then E.place := p; else error;}
Reusing temporary names
– The code generated by E->E1+E2 has the general form:
Evaluate E1 into t1
Evaluate E2 into t2
t3 := t1 + t2
» All temporaries used in E1 are dead after t1 is evaluated
» All temporaries used in E2 are dead after t2 is evaluated
» T1 and t2 are dead after t3 is assigned
– Temporaries can be managed as a stack:
» Keep a counter c, newtemp increases c, when a
temporary is used, decreases c.
» See the previous example.
Addressing array elements
– Arrays are typically stored in block of consecutive locations.
– One-dimensional arrays
• A: array[low..high] of …
• the ith elements is at:
base + (i-low)*width  i*width + (base – low*width)
– Multi-dimensional arrays:
• Row major or column major forms
– Row major: a[1,1], a[1,2], a[1,3], a[2,1], a[2,2], a[2,3]
– Column major: a[1,1], a[2,1], a[1, 2], a[2, 2],a[1, 3],a[2,3]
• In raw major form, the address of a[i1, i2] is
Base+((i1-low1)*(high2-low2+1)+i2-low2)*width
Addressing array elements
• In raw major form, the address of a[i1, i2] is
Base+((i1-low1)*(high2-low2+1)+i2-low2)*width
– In general, for any dimensional array, the address of
a[i1, i2, i3, …, ik] can be computed as follows:
• Let highj and lowj be for bounds for ij
• Let nj = highj – lowj + 1
• The address is
• ((…(i1*n2+i2)*n3+…)nk+ik)*width + base –
((…low1*n2+low2)*n3+…)nk+lowk) * width
– When generating code for array references, we need to
explicitly compute the address.
Translation scheme for array elements
• Limit(array, j) returns nj=highj-lowj+1
• .place: the temporarys or variables
• .offset: offset from the base, null if not an array reference
• Grammar:
S->L := E
E->E+E
E->(E)
E->L
L->Elist ]
L->id
Elist->Elist, E
Elist->id[E
S->L := E { if L.offset = null then emit(L.place ‘:=‘ E.place)
else emit(L.place’[‘L.offset ‘]’ ‘:=‘ E.place);}
E->E1+E2 {E.place := newtemp;
emit(E.place ‘:=‘ E1.place ‘+’ E2.place);}
E->(E1) {E.place := E1.place;}
E->L {if L.offset = null then E.place = L.place
else {E.place = newtemp;
emit(E.place ‘:=‘ L.place ‘[‘ L.offset ‘]’);
}
}
L->Elist ] {L.place = newtemp; L.offset = newtemp;
emit(L.place ‘:=‘ c(Elist.array));
emit(L.offset ‘:=‘ Elist.place ‘*’ width(Elist.array);
}
L->id {L.place = lookup(id.name);
L.offset = null;
}
Elist->Elist1, E {
t := newtemp;
m := Elist1.ndim + 1;
emit(t ‘:=‘ Elist1.place ‘*’limit(Elist1.array, m));
emit(t, ‘:=‘ t ‘+’ E.place);
Elist.array = Elist1.array;
Elist.place := t;
Elist.ndim := m;
}
Elist->id[E {Elist.array := lookup(id.name);
Elist.place := E.place
Elist.ndim := 1;
}
E.place := newtemp;
if E1.type = integer and E2.type = integer then begin
emit(E.place’:=’E1.place ’int+’E2.place);
E.type: = integer end else if E1.type = real and E2.type = real then begin
emit (E.place ’:=’E1.place ‟real +‟ E2.place);
E.type := real end else if E1.type = integer and E2.type = real then begin
u := newtemp;
emit(u ’:=’‟inttoreal‟ E1.place);
emit(E.place ’:=’u ‟real+‟ E2.place);
E.type:= real end else if E1.type = real and E2.type = integer then begin
u := newtemp;
emit(u ’:=’‟inttoreal‟ E2.place);
emit(E.place ’:=’E1.place ‟real+‟ u);
E.type: = real end else
E.type:= type error;
Fig. 8.19. Semantic action for E E1 + E2.
Type conversions with Assignments
Cont…
• The semantic action of Fig. 8. l9 uses two
attributes E.place and E.type for the non-terminal
E.
• As the number of types subject to conversion
increases.
• The number of cases that arise increases
quadratically (or worse, if there are operators with
more than two arguments).
• Therefore with large numbers of types, careful
organization of the semantic actions becomes
more important.
Accessing Fields in Records
• The compiler must keep track of both the types and relative
addresses of the fields of a record.
• An advantage of keeping this information in symbol-table
entries for the field names is that the routine for looking up
names in the symbol table can also be used for field names.
T  record L D end {T.type := record(top(tblptr));
T.width := top(offset);
Pop(tblptr); pop(offset) }
L ε { t:= mktable(nil);
Push(t, tblptr); push (0, offset) }
Cont…
• lf r is a pointer to the symbol table for a record type, then the
type record(t) formed by applying the constructor record to the
pointer was returned as T.type
We use the expression ,
p↑.info + 1
• From the operations in this expression it follows that p must be
a pointer to a record with a field name info whose type is
arithmetic.
Cont….
pointer (record(t))
• The type of pt is then record(t), from which t can be extracted.
The field name info is looked up in the symbol table pointed to
by t.
?

More Related Content

What's hot

Ambiguous & Unambiguous Grammar
Ambiguous & Unambiguous GrammarAmbiguous & Unambiguous Grammar
Ambiguous & Unambiguous GrammarMdImamHasan1
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocksJothi Lakshmi
 
Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)Siddhesh Pange
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In Generalmartha leon
 
Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12Rabia Khalid
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Csc1100 lecture12 ch08_pt2
Csc1100 lecture12 ch08_pt2Csc1100 lecture12 ch08_pt2
Csc1100 lecture12 ch08_pt2IIUM
 
Arrays and Pointers
Arrays and PointersArrays and Pointers
Arrays and PointersSimoniShah6
 
Introduction_modern_fortran_short
Introduction_modern_fortran_shortIntroduction_modern_fortran_short
Introduction_modern_fortran_shortNils van Velzen
 
Generating code from dags
Generating code from dagsGenerating code from dags
Generating code from dagsindhu mathi
 
9 the basic language of functions
9 the basic language of functions 9 the basic language of functions
9 the basic language of functions math260
 
GSP 215 Entire Course NEW
GSP 215 Entire Course NEWGSP 215 Entire Course NEW
GSP 215 Entire Course NEWshyamuopten
 
2.1 the basic language of functions x
2.1 the basic language of functions x2.1 the basic language of functions x
2.1 the basic language of functions xmath260
 
C Pointers
C PointersC Pointers
C Pointersomukhtar
 

What's hot (20)

Ambiguous & Unambiguous Grammar
Ambiguous & Unambiguous GrammarAmbiguous & Unambiguous Grammar
Ambiguous & Unambiguous Grammar
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
 
Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
 
Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Csc1100 lecture12 ch08_pt2
Csc1100 lecture12 ch08_pt2Csc1100 lecture12 ch08_pt2
Csc1100 lecture12 ch08_pt2
 
Ch03
Ch03Ch03
Ch03
 
Arrays and Pointers
Arrays and PointersArrays and Pointers
Arrays and Pointers
 
Ch04
Ch04Ch04
Ch04
 
Ch06
Ch06Ch06
Ch06
 
Introduction_modern_fortran_short
Introduction_modern_fortran_shortIntroduction_modern_fortran_short
Introduction_modern_fortran_short
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
 
Generating code from dags
Generating code from dagsGenerating code from dags
Generating code from dags
 
9 the basic language of functions
9 the basic language of functions 9 the basic language of functions
9 the basic language of functions
 
GSP 215 Entire Course NEW
GSP 215 Entire Course NEWGSP 215 Entire Course NEW
GSP 215 Entire Course NEW
 
2.1 the basic language of functions x
2.1 the basic language of functions x2.1 the basic language of functions x
2.1 the basic language of functions x
 
C Pointers
C PointersC Pointers
C Pointers
 
Linked list
Linked listLinked list
Linked list
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 

Viewers also liked

Viewers also liked (13)

Case statements
Case statementsCase statements
Case statements
 
Declarations
DeclarationsDeclarations
Declarations
 
Code optimization
Code optimization Code optimization
Code optimization
 
ASSIGNMENT STATEMENTS AND
ASSIGNMENT STATEMENTS ANDASSIGNMENT STATEMENTS AND
ASSIGNMENT STATEMENTS AND
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
code optimization
code optimization code optimization
code optimization
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2
 
The dag representation of basic blocks
The dag representation of basic blocksThe dag representation of basic blocks
The dag representation of basic blocks
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Code generation
Code generationCode generation
Code generation
 
Procedure calls(compilar)
Procedure  calls(compilar)Procedure  calls(compilar)
Procedure calls(compilar)
 

Similar to Assignment statements

Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1Shashwat Shriparv
 
12IRGeneration.pdf
12IRGeneration.pdf12IRGeneration.pdf
12IRGeneration.pdfSHUJEHASSAN
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Codesanchi29
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...venkatapranaykumarGa
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationRamchandraRegmi
 
R_CheatSheet.pdf
R_CheatSheet.pdfR_CheatSheet.pdf
R_CheatSheet.pdfMariappanR3
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory MappingQundeel
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generationVipul Naik
 
CS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design TechniquesCS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design Techniquesd72994185
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++NUST Stuff
 
Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)Sourov Kumar Ron
 
Review session2
Review session2Review session2
Review session2NEEDY12345
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionarySoba Arjun
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignKuppusamy P
 

Similar to Assignment statements (20)

Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
12IRGeneration.pdf
12IRGeneration.pdf12IRGeneration.pdf
12IRGeneration.pdf
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
R_CheatSheet.pdf
R_CheatSheet.pdfR_CheatSheet.pdf
R_CheatSheet.pdf
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
scripting in Python
scripting in Pythonscripting in Python
scripting in Python
 
CS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design TechniquesCS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design Techniques
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
 
Array
ArrayArray
Array
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
 
Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
Left factor put
Left factor putLeft factor put
Left factor put
 
1.2 matlab numerical data
1.2  matlab numerical data1.2  matlab numerical data
1.2 matlab numerical data
 
Review session2
Review session2Review session2
Review session2
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 

Recently uploaded

Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Assignment statements

  • 2. Topics • Names in the symbol table • Reusing temporary names • Addressing array elements • The translation scheme for addressing array elements. • Accessing fields in records
  • 3. Names in the Symbol table • Emit (instruction): emit a three address statement to the output • newtemp: return a new temporary • lookup(identifier): check if the identifier is in the symbol table. • Grammar: S->id:=E E->E1+E2 E->E1*E2 E->-E E->(E1) E->id
  • 4. Translation scheme to produce three address code for assignment statement S->id:=E {p:=lookup(id.name); if (p!=nil) then emit(p ‘:=‘ E.place); else error} E->E1+E2 {E.place = newtemp; emit(E.place ‘:=‘ E1.place ‘+’ E2.place);} E->E1*E2 {E.place = newtemp; emit(E.place ‘:=‘ E1.place ‘*’ E2.place);} E->-E1 {E.place = newtemp; emit(E.place ‘:=‘ ‘-’ E1.place);} E->(E1) {E.place = E1.place;} E->id {p = lookup(id.name); if (p!= nil) then E.place := p; else error;}
  • 5. Reusing temporary names – The code generated by E->E1+E2 has the general form: Evaluate E1 into t1 Evaluate E2 into t2 t3 := t1 + t2 » All temporaries used in E1 are dead after t1 is evaluated » All temporaries used in E2 are dead after t2 is evaluated » T1 and t2 are dead after t3 is assigned – Temporaries can be managed as a stack: » Keep a counter c, newtemp increases c, when a temporary is used, decreases c. » See the previous example.
  • 6. Addressing array elements – Arrays are typically stored in block of consecutive locations. – One-dimensional arrays • A: array[low..high] of … • the ith elements is at: base + (i-low)*width  i*width + (base – low*width) – Multi-dimensional arrays: • Row major or column major forms – Row major: a[1,1], a[1,2], a[1,3], a[2,1], a[2,2], a[2,3] – Column major: a[1,1], a[2,1], a[1, 2], a[2, 2],a[1, 3],a[2,3] • In raw major form, the address of a[i1, i2] is Base+((i1-low1)*(high2-low2+1)+i2-low2)*width
  • 7. Addressing array elements • In raw major form, the address of a[i1, i2] is Base+((i1-low1)*(high2-low2+1)+i2-low2)*width
  • 8. – In general, for any dimensional array, the address of a[i1, i2, i3, …, ik] can be computed as follows: • Let highj and lowj be for bounds for ij • Let nj = highj – lowj + 1 • The address is • ((…(i1*n2+i2)*n3+…)nk+ik)*width + base – ((…low1*n2+low2)*n3+…)nk+lowk) * width – When generating code for array references, we need to explicitly compute the address.
  • 9. Translation scheme for array elements • Limit(array, j) returns nj=highj-lowj+1 • .place: the temporarys or variables • .offset: offset from the base, null if not an array reference • Grammar: S->L := E E->E+E E->(E) E->L L->Elist ] L->id Elist->Elist, E Elist->id[E
  • 10. S->L := E { if L.offset = null then emit(L.place ‘:=‘ E.place) else emit(L.place’[‘L.offset ‘]’ ‘:=‘ E.place);} E->E1+E2 {E.place := newtemp; emit(E.place ‘:=‘ E1.place ‘+’ E2.place);} E->(E1) {E.place := E1.place;} E->L {if L.offset = null then E.place = L.place else {E.place = newtemp; emit(E.place ‘:=‘ L.place ‘[‘ L.offset ‘]’); } } L->Elist ] {L.place = newtemp; L.offset = newtemp; emit(L.place ‘:=‘ c(Elist.array)); emit(L.offset ‘:=‘ Elist.place ‘*’ width(Elist.array); }
  • 11. L->id {L.place = lookup(id.name); L.offset = null; } Elist->Elist1, E { t := newtemp; m := Elist1.ndim + 1; emit(t ‘:=‘ Elist1.place ‘*’limit(Elist1.array, m)); emit(t, ‘:=‘ t ‘+’ E.place); Elist.array = Elist1.array; Elist.place := t; Elist.ndim := m; } Elist->id[E {Elist.array := lookup(id.name); Elist.place := E.place Elist.ndim := 1; }
  • 12. E.place := newtemp; if E1.type = integer and E2.type = integer then begin emit(E.place’:=’E1.place ’int+’E2.place); E.type: = integer end else if E1.type = real and E2.type = real then begin emit (E.place ’:=’E1.place ‟real +‟ E2.place); E.type := real end else if E1.type = integer and E2.type = real then begin u := newtemp; emit(u ’:=’‟inttoreal‟ E1.place); emit(E.place ’:=’u ‟real+‟ E2.place); E.type:= real end else if E1.type = real and E2.type = integer then begin u := newtemp; emit(u ’:=’‟inttoreal‟ E2.place); emit(E.place ’:=’E1.place ‟real+‟ u); E.type: = real end else E.type:= type error; Fig. 8.19. Semantic action for E E1 + E2. Type conversions with Assignments
  • 13. Cont… • The semantic action of Fig. 8. l9 uses two attributes E.place and E.type for the non-terminal E. • As the number of types subject to conversion increases. • The number of cases that arise increases quadratically (or worse, if there are operators with more than two arguments). • Therefore with large numbers of types, careful organization of the semantic actions becomes more important.
  • 14. Accessing Fields in Records • The compiler must keep track of both the types and relative addresses of the fields of a record. • An advantage of keeping this information in symbol-table entries for the field names is that the routine for looking up names in the symbol table can also be used for field names. T  record L D end {T.type := record(top(tblptr)); T.width := top(offset); Pop(tblptr); pop(offset) } L ε { t:= mktable(nil); Push(t, tblptr); push (0, offset) }
  • 15. Cont… • lf r is a pointer to the symbol table for a record type, then the type record(t) formed by applying the constructor record to the pointer was returned as T.type We use the expression , p↑.info + 1 • From the operations in this expression it follows that p must be a pointer to a record with a field name info whose type is arithmetic.
  • 16. Cont…. pointer (record(t)) • The type of pt is then record(t), from which t can be extracted. The field name info is looked up in the symbol table pointed to by t.
  • 17. ?