SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
Compiler Construction
AIM:
Generate the symbol table for language.
THEORY:
Figure 1 depicts the schematic
performs analysis of the source program and reflects its results in the intermedi
representation (IR). The second pass reads and analyses the IR
synthesis of the target program. This avoids repeated processing
program.
The first pass is concerned exclusively with source
called the front end of the langu
program synthesis for a specific target
the language processor.
Figure 1: Two pass schematic for language processing
The Front End
The front end performs
 Lexical analysis,
 Syntax analysis and
 Semantic analysis of
Sunita M. Dol, CSE Dept
Assignment No.11
Generate the symbol table for language.
Figure 1 depicts the schematic of a two pass language processor.
the source program and reflects its results in the intermedi
The second pass reads and analyses the IR
the target program. This avoids repeated processing
The first pass is concerned exclusively with source language issues. Hence it is
language processor. The second pass is concerned with
program synthesis for a specific target language. Hence it is called the
Figure 1: Two pass schematic for language processing
Syntax analysis and
of the source program.
Sunita M. Dol, CSE Dept
Page 1
language processor. The first pass
the source program and reflects its results in the intermediate
The second pass reads and analyses the IR to perform
the target program. This avoids repeated processing of the source
issues. Hence it is
The second pass is concerned with
Hence it is called the back end of
Figure 1: Two pass schematic for language processing
Compiler Construction Sunita M. Dol, CSE Dept
Page 2
Each kind of analysis involves the following functions:
1. Determine validity of a source statement from the viewpoint of the
analysis.
2. Determine the ‘content’ of a source statement.
3. Construct a suitable representation of the source statement for use by
subsequent analysis functions, or by the synthesis phase of the language
processor.
The word ‘content’ has different connotations in lexical, syntax and semantic
analysis.
 In lexical analysis, the content is the lexical class to which each lexical unit
belongs,
 In syntax analysis it is the syntactic structure of a source statement.
 In semantic analysis the content is the meaning of a statement—for a
declaration statement, it is the sef of attributes of a declared variable (e.g.
type, length and dimensionality), while for an imperative statement, it is the
sequence of actions implied by the statement.
Each analysis represents the ‘content’ of a source statement in the form of
(1) tables of information, and (2) description of the source statement. Subsequent
analysis uses this information for its own purposes and either adds information to
these tables and descriptions, or constructs its own tables and descriptions.
Output of the front end
The IR produced by the front end consists of two components:
1. Tables of information
2. An intermediate code (IC) which is a description of the source program.
Tables
Tables contain the information obtained during different analyses of SP. The
most important table is the symbol table which contains information concerning all
identifiers used in the SP. The symbol table is built during lexical analysis.
Semantic analysis adds information concerning symbol attributes while processing
declaration statements. It may also add new names designating temporary results.
Compiler Construction Sunita M. Dol, CSE Dept
Page 3
Intermediate code ( I C )
The IC is a sequence of IC units; each IC unit representing the meaning of one
action in SP. IC units may contain references to the information in various tables.
Example
Figure 2 shows the IR produced by the analysis phase for the program
i: integer;
a,b: real;
a := b+i;
Symbol Table:
Intermediate code
1. Convert (id, #1) to real, giving (id, #4)
2. Add (id, #4) to (id, #3) giving (id, #5)
3. Store (id, #5) in (Id, #2)
Figure 2: Intermediate Representation
The symbol table contains information concerning the identifiers and their types.
This information is determined during lexical and semantic analysis, respectively.
In IC, the specification (Id, #1) refers to the id occupying the first entry in the
table. i* and temp are temporary names added during semantic analysis of the
assignment statement.
The Back End
Compiler Construction Sunita M. Dol, CSE Dept
Page 4
The back end performs memory allocation and code generation.
Memory allocation
Memory allocation is a simple task given the presence of the symbol table. The
memory requirement of an identifier is computed from its type, length and dimen-
sionality, and memory is allocated to it. The address of the memory area is entered
in the symbol table.
Example
After memory allocation, the symbol table looks as shown in Figure 3. The entries
for i* and temp are not shown because memory allocation is not needed for these
id’s.
Figure 3: Symbol table after memory allocation
Certain decisions have to precede memory allocation, for example, whether i* and
temp should be allocated memory. These decisions are taken in the preparatory
steps of code generation.
Code generation
Code generation uses knowledge of the target architecture, viz. knowledge of in-
structions and addressing modes in the target computer, to select the appropriate
instructions.
Example
For the sequence of actions for the assignment statement a :* b+i;
(i) Convert i to real, giving i*.
(ii) Add i* to b, giving temp,
(iii) Store temp in a.
the synthesis phase may decide to hold the values of i* and temp in machine
registers and may generate the assembly code
CONV_R AREG, I
Compiler Construction Sunita M. Dol, CSE Dept
Page 5
ADD_R AREG, B
MOVEM AREG, A
where CONV_R converts the value of I into the real representation and leaves the
result in AREG. ADD_R performs the addition in real mode and MOVEM puts the
result into the memory area allocated to A.
PROGRAM:
INPUT:
#include<stdio.h>
void main()
{
double a=10;
int b=5;
float c=2.3f;
char d='A';
}
OUTPUT:
Generating the symbol table
ID Datatype Variable Value
1 double a 10
2 int b 5
3 float c 2.3f
4 char d ‘A’
CONCLUSION:
 The symbol table contains information concerning the identifiers and their
types. This information is determined during lexical and semantic analysis.
 The symbol table is built during lexical analysis.
Compiler Construction Sunita M. Dol, CSE Dept
Page 6
 Semantic analysis adds information concerning symbol attributes while
processing declaration statements
 The symbol table is implemented in C-Language.
REFERENCES:
 Compilers - Principles, Techniques and Tools - A.V. Aho, R. Shethi and J. D.
Ullman (Pearson Education)
 System Programming and operating systems – 2nd Edition D.M. Dhamdhere
(TMGH)

Contenu connexe

Tendances (20)

Handout#09
Handout#09Handout#09
Handout#09
 
Handout#11
Handout#11Handout#11
Handout#11
 
Handout#06
Handout#06Handout#06
Handout#06
 
Assignment4
Assignment4Assignment4
Assignment4
 
Handout#12
Handout#12Handout#12
Handout#12
 
Handout#01
Handout#01Handout#01
Handout#01
 
Assignment5
Assignment5Assignment5
Assignment5
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#Literals,variables,datatype in C#
Literals,variables,datatype in C#
 
Oops
OopsOops
Oops
 
Cnotes
CnotesCnotes
Cnotes
 
Uniti classnotes
Uniti classnotesUniti classnotes
Uniti classnotes
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
The smartpath information systems c pro
The smartpath information systems c proThe smartpath information systems c pro
The smartpath information systems c pro
 
C language
C languageC language
C language
 
Operators and Expressions in C#
Operators and Expressions in C#Operators and Expressions in C#
Operators and Expressions in C#
 
Lecture 21 22
Lecture 21 22Lecture 21 22
Lecture 21 22
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 
C tutorial
C tutorialC tutorial
C tutorial
 
C notes
C notesC notes
C notes
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 

Similaire à Assignment11

Toy compiler
Toy compilerToy compiler
Toy compilerhome
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORPSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORijistjournal
 
Compiler gate question key
Compiler gate question keyCompiler gate question key
Compiler gate question keyArthyR3
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGEIJCI JOURNAL
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGEIJCI JOURNAL
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Tirumala Rao
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingMukesh Tekwani
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in detailskazi_aihtesham
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Rohit Singh
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docxvenkatapranaykumarGa
 
System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical fileAnkit Dixit
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxSanketShah544615
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language ProcessingHemant Sharma
 

Similaire à Assignment11 (20)

Toy compiler
Toy compilerToy compiler
Toy compiler
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORPSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
 
Compiler gate question key
Compiler gate question keyCompiler gate question key
Compiler gate question key
 
Language processors
Language processorsLanguage processors
Language processors
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
 
UNIT 1 NOTES.docx
UNIT 1 NOTES.docxUNIT 1 NOTES.docx
UNIT 1 NOTES.docx
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Intro
IntroIntro
Intro
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Unit1 cd
Unit1 cdUnit1 cd
Unit1 cd
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
 
System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical file
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptx
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
 

Plus de Sunita Milind Dol (17)

9.Joins.pdf
9.Joins.pdf9.Joins.pdf
9.Joins.pdf
 
8.Views.pdf
8.Views.pdf8.Views.pdf
8.Views.pdf
 
7. Nested Subqueries.pdf
7. Nested Subqueries.pdf7. Nested Subqueries.pdf
7. Nested Subqueries.pdf
 
6. Aggregate Functions.pdf
6. Aggregate Functions.pdf6. Aggregate Functions.pdf
6. Aggregate Functions.pdf
 
5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf
 
4. DML.pdf
4. DML.pdf4. DML.pdf
4. DML.pdf
 
3. DDL.pdf
3. DDL.pdf3. DDL.pdf
3. DDL.pdf
 
2. SQL Introduction.pdf
2. SQL Introduction.pdf2. SQL Introduction.pdf
2. SQL Introduction.pdf
 
1. University Example.pdf
1. University Example.pdf1. University Example.pdf
1. University Example.pdf
 
Assignment12
Assignment12Assignment12
Assignment12
 
Assignment10
Assignment10Assignment10
Assignment10
 
Assignment9
Assignment9Assignment9
Assignment9
 
Assignment8
Assignment8Assignment8
Assignment8
 
Assignment7
Assignment7Assignment7
Assignment7
 
Assignment6
Assignment6Assignment6
Assignment6
 
Assignment3
Assignment3Assignment3
Assignment3
 
Assignment2
Assignment2Assignment2
Assignment2
 

Dernier

Multicomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdfMulticomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdfGiovanaGhasary1
 
me3493 manufacturing technology unit 1 Part A
me3493 manufacturing technology unit 1 Part Ame3493 manufacturing technology unit 1 Part A
me3493 manufacturing technology unit 1 Part Akarthi keyan
 
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....santhyamuthu1
 
Landsman converter for power factor improvement
Landsman converter for power factor improvementLandsman converter for power factor improvement
Landsman converter for power factor improvementVijayMuni2
 
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxUNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxrealme6igamerr
 
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxVertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxLMW Machine Tool Division
 
Lecture 1: Basics of trigonometry (surveying)
Lecture 1: Basics of trigonometry (surveying)Lecture 1: Basics of trigonometry (surveying)
Lecture 1: Basics of trigonometry (surveying)Bahzad5
 
solar wireless electric vechicle charging system
solar wireless electric vechicle charging systemsolar wireless electric vechicle charging system
solar wireless electric vechicle charging systemgokuldongala
 
ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderjuancarlos286641
 
Nodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxNodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxwendy cai
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabusViolet Violet
 
Modelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsModelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsYusuf Yıldız
 
Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical SensorTanvir Moin
 
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratoryدليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide LaboratoryBahzad5
 
Design of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptxDesign of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptxYogeshKumarKJMIT
 

Dernier (20)

Litature Review: Research Paper work for Engineering
Litature Review: Research Paper work for EngineeringLitature Review: Research Paper work for Engineering
Litature Review: Research Paper work for Engineering
 
Lecture 2 .pptx
Lecture 2                            .pptxLecture 2                            .pptx
Lecture 2 .pptx
 
Multicomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdfMulticomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdf
 
me3493 manufacturing technology unit 1 Part A
me3493 manufacturing technology unit 1 Part Ame3493 manufacturing technology unit 1 Part A
me3493 manufacturing technology unit 1 Part A
 
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
 
Landsman converter for power factor improvement
Landsman converter for power factor improvementLandsman converter for power factor improvement
Landsman converter for power factor improvement
 
Lecture 2 .pdf
Lecture 2                           .pdfLecture 2                           .pdf
Lecture 2 .pdf
 
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxUNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
 
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxVertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
 
計劃趕得上變化
計劃趕得上變化計劃趕得上變化
計劃趕得上變化
 
Présentation IIRB 2024 Chloe Dufrane.pdf
Présentation IIRB 2024 Chloe Dufrane.pdfPrésentation IIRB 2024 Chloe Dufrane.pdf
Présentation IIRB 2024 Chloe Dufrane.pdf
 
Lecture 1: Basics of trigonometry (surveying)
Lecture 1: Basics of trigonometry (surveying)Lecture 1: Basics of trigonometry (surveying)
Lecture 1: Basics of trigonometry (surveying)
 
solar wireless electric vechicle charging system
solar wireless electric vechicle charging systemsolar wireless electric vechicle charging system
solar wireless electric vechicle charging system
 
ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entender
 
Nodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxNodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptx
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabus
 
Modelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsModelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovations
 
Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical Sensor
 
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratoryدليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
 
Design of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptxDesign of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptx
 

Assignment11

  • 1. Compiler Construction AIM: Generate the symbol table for language. THEORY: Figure 1 depicts the schematic performs analysis of the source program and reflects its results in the intermedi representation (IR). The second pass reads and analyses the IR synthesis of the target program. This avoids repeated processing program. The first pass is concerned exclusively with source called the front end of the langu program synthesis for a specific target the language processor. Figure 1: Two pass schematic for language processing The Front End The front end performs  Lexical analysis,  Syntax analysis and  Semantic analysis of Sunita M. Dol, CSE Dept Assignment No.11 Generate the symbol table for language. Figure 1 depicts the schematic of a two pass language processor. the source program and reflects its results in the intermedi The second pass reads and analyses the IR the target program. This avoids repeated processing The first pass is concerned exclusively with source language issues. Hence it is language processor. The second pass is concerned with program synthesis for a specific target language. Hence it is called the Figure 1: Two pass schematic for language processing Syntax analysis and of the source program. Sunita M. Dol, CSE Dept Page 1 language processor. The first pass the source program and reflects its results in the intermediate The second pass reads and analyses the IR to perform the target program. This avoids repeated processing of the source issues. Hence it is The second pass is concerned with Hence it is called the back end of Figure 1: Two pass schematic for language processing
  • 2. Compiler Construction Sunita M. Dol, CSE Dept Page 2 Each kind of analysis involves the following functions: 1. Determine validity of a source statement from the viewpoint of the analysis. 2. Determine the ‘content’ of a source statement. 3. Construct a suitable representation of the source statement for use by subsequent analysis functions, or by the synthesis phase of the language processor. The word ‘content’ has different connotations in lexical, syntax and semantic analysis.  In lexical analysis, the content is the lexical class to which each lexical unit belongs,  In syntax analysis it is the syntactic structure of a source statement.  In semantic analysis the content is the meaning of a statement—for a declaration statement, it is the sef of attributes of a declared variable (e.g. type, length and dimensionality), while for an imperative statement, it is the sequence of actions implied by the statement. Each analysis represents the ‘content’ of a source statement in the form of (1) tables of information, and (2) description of the source statement. Subsequent analysis uses this information for its own purposes and either adds information to these tables and descriptions, or constructs its own tables and descriptions. Output of the front end The IR produced by the front end consists of two components: 1. Tables of information 2. An intermediate code (IC) which is a description of the source program. Tables Tables contain the information obtained during different analyses of SP. The most important table is the symbol table which contains information concerning all identifiers used in the SP. The symbol table is built during lexical analysis. Semantic analysis adds information concerning symbol attributes while processing declaration statements. It may also add new names designating temporary results.
  • 3. Compiler Construction Sunita M. Dol, CSE Dept Page 3 Intermediate code ( I C ) The IC is a sequence of IC units; each IC unit representing the meaning of one action in SP. IC units may contain references to the information in various tables. Example Figure 2 shows the IR produced by the analysis phase for the program i: integer; a,b: real; a := b+i; Symbol Table: Intermediate code 1. Convert (id, #1) to real, giving (id, #4) 2. Add (id, #4) to (id, #3) giving (id, #5) 3. Store (id, #5) in (Id, #2) Figure 2: Intermediate Representation The symbol table contains information concerning the identifiers and their types. This information is determined during lexical and semantic analysis, respectively. In IC, the specification (Id, #1) refers to the id occupying the first entry in the table. i* and temp are temporary names added during semantic analysis of the assignment statement. The Back End
  • 4. Compiler Construction Sunita M. Dol, CSE Dept Page 4 The back end performs memory allocation and code generation. Memory allocation Memory allocation is a simple task given the presence of the symbol table. The memory requirement of an identifier is computed from its type, length and dimen- sionality, and memory is allocated to it. The address of the memory area is entered in the symbol table. Example After memory allocation, the symbol table looks as shown in Figure 3. The entries for i* and temp are not shown because memory allocation is not needed for these id’s. Figure 3: Symbol table after memory allocation Certain decisions have to precede memory allocation, for example, whether i* and temp should be allocated memory. These decisions are taken in the preparatory steps of code generation. Code generation Code generation uses knowledge of the target architecture, viz. knowledge of in- structions and addressing modes in the target computer, to select the appropriate instructions. Example For the sequence of actions for the assignment statement a :* b+i; (i) Convert i to real, giving i*. (ii) Add i* to b, giving temp, (iii) Store temp in a. the synthesis phase may decide to hold the values of i* and temp in machine registers and may generate the assembly code CONV_R AREG, I
  • 5. Compiler Construction Sunita M. Dol, CSE Dept Page 5 ADD_R AREG, B MOVEM AREG, A where CONV_R converts the value of I into the real representation and leaves the result in AREG. ADD_R performs the addition in real mode and MOVEM puts the result into the memory area allocated to A. PROGRAM: INPUT: #include<stdio.h> void main() { double a=10; int b=5; float c=2.3f; char d='A'; } OUTPUT: Generating the symbol table ID Datatype Variable Value 1 double a 10 2 int b 5 3 float c 2.3f 4 char d ‘A’ CONCLUSION:  The symbol table contains information concerning the identifiers and their types. This information is determined during lexical and semantic analysis.  The symbol table is built during lexical analysis.
  • 6. Compiler Construction Sunita M. Dol, CSE Dept Page 6  Semantic analysis adds information concerning symbol attributes while processing declaration statements  The symbol table is implemented in C-Language. REFERENCES:  Compilers - Principles, Techniques and Tools - A.V. Aho, R. Shethi and J. D. Ullman (Pearson Education)  System Programming and operating systems – 2nd Edition D.M. Dhamdhere (TMGH)