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
 
Module 2
Module 2 Module 2
Module 2
 
SS & CD Module 3
SS & CD Module 3 SS & CD Module 3
SS & CD Module 3
 
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

UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 

Recently uploaded (20)

Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 

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.