SlideShare a Scribd company logo
1 of 8
Download to read offline
System Programming
Walchand Institute of Technology
Aim:
Design lexical analyzer for tokens: keywords, identifiers, numbers, and operators
Theory:
Figure 1 depicts the schematic
performs analysis of the source program and reflects its
representation. The second pass reads and analyses the IR, instead
program, to perform synthesis
processing of the source program.
Figure 1: Two pass schematic for la
The Front End
The front end performs
• Lexical analysis,
• Syntax analysis and
• Semantic analysis
Each kind of analysis involves the following functions:
1. Determine validity
analysis.
2. Determine the ‘content’
Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur
HANDOUT#09
Design lexical analyzer for tokens: keywords, identifiers, numbers, and operators
depicts the schematic of a two pass language processor.
the source program and reflects its results in the intermedi
representation. The second pass reads and analyses the IR, instead
program, to perform synthesis of the target program. This avoids repeated
the source program.
Figure 1: Two pass schematic for language processing
Lexical analysis,
Syntax analysis and
Semantic analysis of the source program.
analysis involves the following functions:
Determine validity of a source statement from the viewpoint
Determine the ‘content’ of a source statement.
Sunita M. Dol, CSE Dept
Page 1
Design lexical analyzer for tokens: keywords, identifiers, numbers, and operators.
language processor. The first pass
results in the intermediate
representation. The second pass reads and analyses the IR, instead of the source
the target program. This avoids repeated
nguage processing
a source statement from the viewpoint of the
System Programming
Walchand Institute of Technology
3. Construct a suitable representation
subsequent analysis functions, or
processor.
The word ‘content’ has different co
analysis.
• In lexical analysis, the content is the lexical class to which each lexical unit
belongs,
• In syntax analysis it is the syntactic structure
In semantic analysis the content is t
statement, it is the sef of
mensionality), while for an imperative statement, it is the sequence
implied by the statement.
Figure: Front en
Output of the front end
The IR produced by the front end consists
1. Tables of information
2. An intermediate code
Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur
Construct a suitable representation of the source statement for use
quent analysis functions, or by the synthesis phase
The word ‘content’ has different connotations in lexical, syntax and semantic
In lexical analysis, the content is the lexical class to which each lexical unit
In syntax analysis it is the syntactic structure of a source statement.
In semantic analysis the content is the meaning of a statement
of attributes of a declared variable (e.g. type, length and di
mensionality), while for an imperative statement, it is the sequence
Figure: Front end of the toy compiler
the front end consists of two components:
information
intermediate code (IC) which is a description of the source program.
Sunita M. Dol, CSE Dept
Page 2
the source statement for use by
the synthesis phase of the language
nnotations in lexical, syntax and semantic
In lexical analysis, the content is the lexical class to which each lexical unit
a source statement.
a statement—for a declaration
a declared variable (e.g. type, length and di-
mensionality), while for an imperative statement, it is the sequence of actions
the source program.
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 3
The Back End
The back end performs
• 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 dimensionality, and memory is allocated to it. The
address of the memory area is entered in the symbol table.
• Code generation: Code generation uses knowledge of the target architecture,
viz. knowledge of instructions and addressing modes in the target computer,
to select the appropriate instructions. The important issues in code
generation are:
o Determine the places where the intermediate results should
be kept, i.e. whether they should be kept in memory
locations or held in machine registers. This is a preparatory
step for code generation.
o Determine which instructions should be used for type
conversion operations.
o Determine which addressing modes should be used for
accessing variables.
System Programming
Walchand Institute of Technology
Figure : Back end of the toy compiler
Lexical analysis (Scanning)
Lexical analysis identifies the lexical units in a source statement. It then
the units into different lexical classes, e.g. id's, constants, reserved id’s, etc, and
enters them into different tables. Lexical analysis builds a descriptor, called a
token, for each lexical unit. A token contains two fields
in class, class code identifies the class to which a lexical unit belongs;
class is the entry number
Example: The statement a
Input:
TRIAL.CPP
Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur
Figure : Back end of the toy compiler
Lexical analysis (Scanning)
Lexical analysis identifies the lexical units in a source statement. It then
the units into different lexical classes, e.g. id's, constants, reserved id’s, etc, and
enters them into different tables. Lexical analysis builds a descriptor, called a
, for each lexical unit. A token contains two fields—class code
identifies the class to which a lexical unit belongs;
is the entry number of the lexical unit in the relevant table.
statement a := b+i; is represented as the string of
Sunita M. Dol, CSE Dept
Page 4
Figure : Back end of the toy compiler
Lexical analysis identifies the lexical units in a source statement. It then classifies
the units into different lexical classes, e.g. id's, constants, reserved id’s, etc, and
enters them into different tables. Lexical analysis builds a descriptor, called a
class code, and number
identifies the class to which a lexical unit belongs; number in
the lexical unit in the relevant table.
of tokens
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 5
# include< stdio.h>
# include< conio.h>
void main()
{
int num1= 5 , count= 1 , ab= 10 ;
char ch;
printf ( "This is a trial program" ) ;
while ( count ! = num1 )
{
ab = ab* count/ 2 ;
if ( count== 3 )
count= count+ 1 ;
printf ( "AB %d" , ab);
}
}
Output:
Token ID=0 # Special Character
Token ID=1 include Keyword type
Token ID=2 < Special Character
Token ID=3 stdio Keyword type
Token ID=4 . Special Character
Token ID=5 h Identifier type
Token ID=6 > Special Character
Token ID=7 # Special Character
Token ID=8 include Keyword type
Token ID=9 < Special Character
Token ID=10 conio Keyword type
Token ID=11 . Special Character
Token ID=12 h Identifier type
Token ID=13 > Special Character
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 6
Token ID=14 void Keyword type
Token ID=15 main Keyword type
Token ID=16 ( Special Character
Token ID=17 ) Special Character
Token ID=18 { Special Character
Token ID=19 int Keyword type
Token ID=20 num1 Identifier type
Token ID=21 = Operator type
Token ID=22 5 Numeric type
Token ID=23 , Special Character
Token ID=24 count Identifier type
Token ID=25 = Operator type
Token ID=26 1 Numeric type
Token ID=27 , Special Character
Token ID=28 ab Identifier type
Token ID=29 = Operator type
Token ID=30 10 Numeric type
Token ID=31 ; Special Character
Token ID=32 char Keyword type
Token ID=33 ch Identifier type
Token ID=34 ; Special Character
Token ID=35 printf Keyword type
Token ID=36 ( Special Character
Token ID=37 This is a trial program Literal type
Token ID=38 ) Special Character
Token ID=39 ; Special Character
Token ID=40 while Keyword type
Token ID=41 ( Special Character
Token ID=42 count Identifier type
Token ID=43 ! Special Character
Token ID=44 = Operator type
Token ID=45 num1 Identifier type
Token ID=46 ) Special Character
Token ID=47 { Special Character
Token ID=48 ab Identifier type
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 7
Token ID=49 = Operator type
Token ID=50 ab Identifier type
Token ID=51 * Operator type
Token ID=52 count Identifier type
Token ID=53 / Operator type
Token ID=54 2 Numeric type
Token ID=55 ; Special Character
Token ID=56 if Keyword type
Token ID=57 ( Special Character
Token ID=58 count Identifier type
Token ID=59 = Operator type
Token ID=60 = Operator type
Token ID=61 3 Numeric type
Token ID=62 ) Special Character
Token ID=63 count Identifier type
Token ID=64 = Operator type
Token ID=65 count Identifier type
Token ID=66 + Operator type
Token ID=67 1 Numeric type
Token ID=68 ; Special Character
Token ID=69 printf Keyword type
Token ID=70 ( Special Character
Token ID=71 AB %d Literal type
Token ID=72 , Special Character
Token ID=73 ab Identifier type
Token ID=74 ) Special Character
Token ID=75 ; Special Character
Token ID=76 } Special Character
Token ID=77 } Special Character
Conclusion:
In lexical analysis, the content is the lexical class to which each lexical unit
belongs
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 8
Lexical analysis identifies the lexical units in a source statement. It then
classifies the units into different lexical classes, e.g. id's, constants, reserved
id’s, etc, and enters them into different tables.
Lexical analysis builds a descriptor, called a token, for each lexical unit.
Thus the lexical analyser is implemented in the C-language.

More Related Content

What's hot (20)

Handout#05
Handout#05Handout#05
Handout#05
 
Assignment2
Assignment2Assignment2
Assignment2
 
Handout#06
Handout#06Handout#06
Handout#06
 
Handout#04
Handout#04Handout#04
Handout#04
 
Handout#07
Handout#07Handout#07
Handout#07
 
Handout#11
Handout#11Handout#11
Handout#11
 
Lexical analysis-using-lex
Lexical analysis-using-lexLexical analysis-using-lex
Lexical analysis-using-lex
 
Handout#01
Handout#01Handout#01
Handout#01
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
 
Handout#12
Handout#12Handout#12
Handout#12
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Oops
OopsOops
Oops
 
Compiler design and lexical analyser
Compiler design and lexical analyserCompiler design and lexical analyser
Compiler design and lexical analyser
 
C++
C++C++
C++
 
Structure of the compiler
Structure of the compilerStructure of the compiler
Structure of the compiler
 
Cnotes
CnotesCnotes
Cnotes
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
role of lexical anaysis
role of lexical anaysisrole of lexical anaysis
role of lexical anaysis
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 

Similar to Handout#09

what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compileradilmehmood93
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORPSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORijistjournal
 
phases of compiler-analysis phase
phases of compiler-analysis phasephases of compiler-analysis phase
phases of compiler-analysis phaseSuyash Srivastava
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]Abhishek Sinha
 
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
 
Compiler Design lab manual for Computer Engineering .pdf
Compiler Design lab manual for Computer Engineering .pdfCompiler Design lab manual for Computer Engineering .pdf
Compiler Design lab manual for Computer Engineering .pdfkalpana Manudhane
 
3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdfTANZINTANZINA
 
COMPILER DESIGN.pdf
COMPILER DESIGN.pdfCOMPILER DESIGN.pdf
COMPILER DESIGN.pdfManishBej3
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageRakesh Roshan
 

Similar to Handout#09 (20)

Ss ui lecture 2
Ss ui lecture 2Ss ui lecture 2
Ss ui lecture 2
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORPSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
 
Language processors
Language processorsLanguage processors
Language processors
 
SS & CD Module 3
SS & CD Module 3 SS & CD Module 3
SS & CD Module 3
 
Module 2
Module 2 Module 2
Module 2
 
Plc part 2
Plc  part 2Plc  part 2
Plc part 2
 
phases of compiler-analysis phase
phases of compiler-analysis phasephases of compiler-analysis phase
phases of compiler-analysis phase
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
 
phase of compiler
phase of compilerphase of compiler
phase of compiler
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
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
 
Compiler Design lab manual for Computer Engineering .pdf
Compiler Design lab manual for Computer Engineering .pdfCompiler Design lab manual for Computer Engineering .pdf
Compiler Design lab manual for Computer Engineering .pdf
 
3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
COMPILER DESIGN.pdf
COMPILER DESIGN.pdfCOMPILER DESIGN.pdf
COMPILER DESIGN.pdf
 
Introduction to Compilers | Phases & Structure
Introduction to Compilers | Phases & StructureIntroduction to Compilers | Phases & Structure
Introduction to Compilers | Phases & Structure
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 

More from Sunita Milind Dol (16)

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
 

Recently uploaded

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 

Recently uploaded (20)

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 

Handout#09

  • 1. System Programming Walchand Institute of Technology Aim: Design lexical analyzer for tokens: keywords, identifiers, numbers, and operators Theory: Figure 1 depicts the schematic performs analysis of the source program and reflects its representation. The second pass reads and analyses the IR, instead program, to perform synthesis processing of the source program. Figure 1: Two pass schematic for la The Front End The front end performs • Lexical analysis, • Syntax analysis and • Semantic analysis Each kind of analysis involves the following functions: 1. Determine validity analysis. 2. Determine the ‘content’ Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur HANDOUT#09 Design lexical analyzer for tokens: keywords, identifiers, numbers, and operators depicts the schematic of a two pass language processor. the source program and reflects its results in the intermedi representation. The second pass reads and analyses the IR, instead program, to perform synthesis of the target program. This avoids repeated the source program. Figure 1: Two pass schematic for language processing Lexical analysis, Syntax analysis and Semantic analysis of the source program. analysis involves the following functions: Determine validity of a source statement from the viewpoint Determine the ‘content’ of a source statement. Sunita M. Dol, CSE Dept Page 1 Design lexical analyzer for tokens: keywords, identifiers, numbers, and operators. language processor. The first pass results in the intermediate representation. The second pass reads and analyses the IR, instead of the source the target program. This avoids repeated nguage processing a source statement from the viewpoint of the
  • 2. System Programming Walchand Institute of Technology 3. Construct a suitable representation subsequent analysis functions, or processor. The word ‘content’ has different co analysis. • In lexical analysis, the content is the lexical class to which each lexical unit belongs, • In syntax analysis it is the syntactic structure In semantic analysis the content is t statement, it is the sef of mensionality), while for an imperative statement, it is the sequence implied by the statement. Figure: Front en Output of the front end The IR produced by the front end consists 1. Tables of information 2. An intermediate code Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Construct a suitable representation of the source statement for use quent analysis functions, or by the synthesis phase The word ‘content’ has different connotations in lexical, syntax and semantic In lexical analysis, the content is the lexical class to which each lexical unit In syntax analysis it is the syntactic structure of a source statement. In semantic analysis the content is the meaning of a statement of attributes of a declared variable (e.g. type, length and di mensionality), while for an imperative statement, it is the sequence Figure: Front end of the toy compiler the front end consists of two components: information intermediate code (IC) which is a description of the source program. Sunita M. Dol, CSE Dept Page 2 the source statement for use by the synthesis phase of the language nnotations in lexical, syntax and semantic In lexical analysis, the content is the lexical class to which each lexical unit a source statement. a statement—for a declaration a declared variable (e.g. type, length and di- mensionality), while for an imperative statement, it is the sequence of actions the source program.
  • 3. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 3 The Back End The back end performs • 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 dimensionality, and memory is allocated to it. The address of the memory area is entered in the symbol table. • Code generation: Code generation uses knowledge of the target architecture, viz. knowledge of instructions and addressing modes in the target computer, to select the appropriate instructions. The important issues in code generation are: o Determine the places where the intermediate results should be kept, i.e. whether they should be kept in memory locations or held in machine registers. This is a preparatory step for code generation. o Determine which instructions should be used for type conversion operations. o Determine which addressing modes should be used for accessing variables.
  • 4. System Programming Walchand Institute of Technology Figure : Back end of the toy compiler Lexical analysis (Scanning) Lexical analysis identifies the lexical units in a source statement. It then the units into different lexical classes, e.g. id's, constants, reserved id’s, etc, and enters them into different tables. Lexical analysis builds a descriptor, called a token, for each lexical unit. A token contains two fields in class, class code identifies the class to which a lexical unit belongs; class is the entry number Example: The statement a Input: TRIAL.CPP Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Figure : Back end of the toy compiler Lexical analysis (Scanning) Lexical analysis identifies the lexical units in a source statement. It then the units into different lexical classes, e.g. id's, constants, reserved id’s, etc, and enters them into different tables. Lexical analysis builds a descriptor, called a , for each lexical unit. A token contains two fields—class code identifies the class to which a lexical unit belongs; is the entry number of the lexical unit in the relevant table. statement a := b+i; is represented as the string of Sunita M. Dol, CSE Dept Page 4 Figure : Back end of the toy compiler Lexical analysis identifies the lexical units in a source statement. It then classifies the units into different lexical classes, e.g. id's, constants, reserved id’s, etc, and enters them into different tables. Lexical analysis builds a descriptor, called a class code, and number identifies the class to which a lexical unit belongs; number in the lexical unit in the relevant table. of tokens
  • 5. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 5 # include< stdio.h> # include< conio.h> void main() { int num1= 5 , count= 1 , ab= 10 ; char ch; printf ( "This is a trial program" ) ; while ( count ! = num1 ) { ab = ab* count/ 2 ; if ( count== 3 ) count= count+ 1 ; printf ( "AB %d" , ab); } } Output: Token ID=0 # Special Character Token ID=1 include Keyword type Token ID=2 < Special Character Token ID=3 stdio Keyword type Token ID=4 . Special Character Token ID=5 h Identifier type Token ID=6 > Special Character Token ID=7 # Special Character Token ID=8 include Keyword type Token ID=9 < Special Character Token ID=10 conio Keyword type Token ID=11 . Special Character Token ID=12 h Identifier type Token ID=13 > Special Character
  • 6. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 6 Token ID=14 void Keyword type Token ID=15 main Keyword type Token ID=16 ( Special Character Token ID=17 ) Special Character Token ID=18 { Special Character Token ID=19 int Keyword type Token ID=20 num1 Identifier type Token ID=21 = Operator type Token ID=22 5 Numeric type Token ID=23 , Special Character Token ID=24 count Identifier type Token ID=25 = Operator type Token ID=26 1 Numeric type Token ID=27 , Special Character Token ID=28 ab Identifier type Token ID=29 = Operator type Token ID=30 10 Numeric type Token ID=31 ; Special Character Token ID=32 char Keyword type Token ID=33 ch Identifier type Token ID=34 ; Special Character Token ID=35 printf Keyword type Token ID=36 ( Special Character Token ID=37 This is a trial program Literal type Token ID=38 ) Special Character Token ID=39 ; Special Character Token ID=40 while Keyword type Token ID=41 ( Special Character Token ID=42 count Identifier type Token ID=43 ! Special Character Token ID=44 = Operator type Token ID=45 num1 Identifier type Token ID=46 ) Special Character Token ID=47 { Special Character Token ID=48 ab Identifier type
  • 7. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 7 Token ID=49 = Operator type Token ID=50 ab Identifier type Token ID=51 * Operator type Token ID=52 count Identifier type Token ID=53 / Operator type Token ID=54 2 Numeric type Token ID=55 ; Special Character Token ID=56 if Keyword type Token ID=57 ( Special Character Token ID=58 count Identifier type Token ID=59 = Operator type Token ID=60 = Operator type Token ID=61 3 Numeric type Token ID=62 ) Special Character Token ID=63 count Identifier type Token ID=64 = Operator type Token ID=65 count Identifier type Token ID=66 + Operator type Token ID=67 1 Numeric type Token ID=68 ; Special Character Token ID=69 printf Keyword type Token ID=70 ( Special Character Token ID=71 AB %d Literal type Token ID=72 , Special Character Token ID=73 ab Identifier type Token ID=74 ) Special Character Token ID=75 ; Special Character Token ID=76 } Special Character Token ID=77 } Special Character Conclusion: In lexical analysis, the content is the lexical class to which each lexical unit belongs
  • 8. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 8 Lexical analysis identifies the lexical units in a source statement. It then classifies the units into different lexical classes, e.g. id's, constants, reserved id’s, etc, and enters them into different tables. Lexical analysis builds a descriptor, called a token, for each lexical unit. Thus the lexical analyser is implemented in the C-language.