SlideShare a Scribd company logo
1 of 13
Compiler Phases:
Source program
Lexical analyzer
Syntax analyzer
Semantic analyzer
Machine-independent code improvement
Target code generation
Machine-specific code improvement
Front End
Backend
Lexical Analysis
• Lexical analyzer: reads input characters and produces a
sequence of tokens as output (nexttoken()).
– Trying to understand each element in a program.
– Token: a group of characters having a collective meaning.
const pi = 3.14159;
Token 1: (const, -)
Token 2: (identifier, ‘pi’)
Token 3: (=, -)
Token 4: (realnumber, 3.14159)
Token 5: (;, -)
Interaction of Lexical analyzer
with parser
Lexical
analyzer
symbol
table
parser
Source
program
token
Nexttoken()
• Some terminology:
– Token: a group of characters having a collective
meaning. A lexeme is a particular instant of a token.
• E.g. token: identifier, lexeme: pi, etc.
– pattern: the rule describing how a token can be formed.
• E.g: identifier: ([a-z]|[A-Z]) ([a-z]|[A-Z]|[0-9])*
• Lexical analyzer does not have to be an individual
phase. But having a separate phase simplifies the
design and improves the efficiency and
portability.
• Two issues in lexical analysis.
– How to specify tokens (patterns)?
– How to recognize the tokens given a token specification (how to
implement the nexttoken() routine)?
• How to specify tokens:
– all the basic elements in a language must be
tokens so that they can be recognized.
• There are not many types of tokens in a typical programming
language: constant, identifier, reserved word, operator and
misc. symbol.
main() {
int i, j;
for (i=0; i<50; i++) {
printf(“i = %d”, i);
}
}
• Type of tokens in C++:
– Constants:
• char constants: ‘a’
• string constants: “I=%d”
• int constants: 50
• float point constants
– Identifiers: i, j, counter, ……
– Reserved words: main, int, for, …
– Operators: +, =, ++, /, …
– Misc. symbols: (, ), {, }, …
• Tokens are specified by regular
expressions.
main() {
int i, j;
for (I=0; I<50; I++) {
printf(“I = %d”, I);
}
}
• Definitions
– alphabet : a finite set of symbols. E.g. {a, b, c}
– A string over an alphabet is a finite sequence of symbols drawn
from that alphabet (sometimes a string is also called a sentence or a
word).
– A language is a set of strings over an alphabet.
– Operation on languages (a set):
• union of L and M, L U M = {s|s is in L or s is in M}
• concatenation of L and M
LM = {st | s is in L and t is in M}
• Kleene closure of L,
• Positive closure of L,
– Example:
• L={aa, bb, cc}, M = {abc}
i
i
L
L



0
*

i
i
L
L




1

• Formal definition of Regular expression
• Given an alphabet ,
• (1) is a regular expression that denote { }, the
set that contains the empty string.
• (2) For each , a is a regular expression
denote {a}, the set containing the string a.
• (3) r and s are regular expressions denoting the
language (set) L(r ) and L(s ). Then
– ( r ) | ( s ) is a regular expression denoting L( r ) U L( s )
– ( r ) ( s ) is a regular expression denoting L( r ) L ( s )
– ( r )* is a regular expression denoting (L ( r )) *
• Regular expression is defined together with the
language it denotes.

 


a
• Examples:
– let
a | b
(a | b) (a | b)
a *
(a | b)*
a | a*b
– We assume that ‘*’ has the highest precedence and is
left associative. Concatenation has second highest
precedence and is left associative and ‘|’ has the lowest
precedence and is left associative
• (a) | ((b)*(c ) ) = a | b*c
 }
,
{ b
a
• Regular definition.
– gives names to regular expressions to construct more complicate
regular expressions.
d1 -> r1
d2 ->r2
…
dn ->rn
– example:
letter -> A | B | C | … | Z | a | b | …. | z
digit -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
identifier -> letter (letter | digit) *
– Cannot use recursive definitions
• digits -> digit digits | digit
Regular expression for tokens in
C++
– Constants:
• char constants: ‘’’ any_char ‘’’
• string constants: “I=%d”
– ‘”’ [^”]* ‘”’ – not quite right.
• int constants: 50 -- digit (digit)*
• float point constants 50.0 – digit (digit)* ‘.’ digit (digit) *
– Identifiers: letter (letter | digit | ‘_’) *
– Reserved words: ‘m’’a’’i’’n’ for main
– Operators: ‘+’ for +, and ‘+’ ‘+’ for ++
– Misc symbols: ‘(‘ for (
Regular expression for tokens in
C++
• A signed number in C++:
3.1416 +2006 1e-010 -3.14159
2006.00000 0.00000 3.14159e+000
2.00600e+003 -1.00000E-010
Regular expression for tokens in
C++
• A signed number in C++:
3.1416 +2006 1e-010 -3.14159
2006.00000 0.00000 3.14159e+000
2.00600e+003 -1.00000E-010
Num -> digit (digit)*
NUMBER->(+|-| ) (Num | Num . Num) ( |
(e|E)(+|-| )Num )
 


More Related Content

Similar to 7645347.ppt

0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdfssusere19c741
 
3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdfTANZINTANZINA
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2gadisaAdamu
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfpaijitk
 
Syntax Analyzer.pdf
Syntax Analyzer.pdfSyntax Analyzer.pdf
Syntax Analyzer.pdfkenilpatel65
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler DesignKuppusamy P
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptNderituGichuki1
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITASIT
 
Compiler Designs
Compiler DesignsCompiler Designs
Compiler Designswasim liam
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Aman Sharma
 

Similar to 7645347.ppt (20)

SS UI Lecture 4
SS UI Lecture 4SS UI Lecture 4
SS UI Lecture 4
 
Lexical
LexicalLexical
Lexical
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Lecture3 lexical analysis
Lecture3 lexical analysisLecture3 lexical analysis
Lecture3 lexical analysis
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
Ch04
Ch04Ch04
Ch04
 
Unit-1-part-1.pptx
Unit-1-part-1.pptxUnit-1-part-1.pptx
Unit-1-part-1.pptx
 
3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 
Ch3
Ch3Ch3
Ch3
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdf
 
Syntax Analyzer.pdf
Syntax Analyzer.pdfSyntax Analyzer.pdf
Syntax Analyzer.pdf
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.ppt
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 
Compiler Designs
Compiler DesignsCompiler Designs
Compiler Designs
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
 

More from jeronimored

Computer Networks 7.Physical LayerComputer Networks 7.Physical Layer
Computer Networks 7.Physical LayerComputer Networks 7.Physical LayerComputer Networks 7.Physical LayerComputer Networks 7.Physical Layer
Computer Networks 7.Physical LayerComputer Networks 7.Physical Layerjeronimored
 
Android – Open source mobile OS developed ny the Open Handset Alliance led by...
Android – Open source mobile OS developed ny the Open Handset Alliance led by...Android – Open source mobile OS developed ny the Open Handset Alliance led by...
Android – Open source mobile OS developed ny the Open Handset Alliance led by...jeronimored
 
Intel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.pptIntel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.pptjeronimored
 
Intro Ch 01BA business alliance consisting of 47 companies to develop open st...
Intro Ch 01BA business alliance consisting of 47 companies to develop open st...Intro Ch 01BA business alliance consisting of 47 companies to develop open st...
Intro Ch 01BA business alliance consisting of 47 companies to develop open st...jeronimored
 
preKnowledge-InternetNetworking Android's mobile operating system is based on...
preKnowledge-InternetNetworking Android's mobile operating system is based on...preKnowledge-InternetNetworking Android's mobile operating system is based on...
preKnowledge-InternetNetworking Android's mobile operating system is based on...jeronimored
 
TelecommunicationsThe Internet Basic Telecom Model
TelecommunicationsThe Internet Basic Telecom ModelTelecommunicationsThe Internet Basic Telecom Model
TelecommunicationsThe Internet Basic Telecom Modeljeronimored
 
Functional Areas of Network Management Configuration Management
Functional Areas of Network Management Configuration ManagementFunctional Areas of Network Management Configuration Management
Functional Areas of Network Management Configuration Managementjeronimored
 
Coding, Information Theory (and Advanced Modulation
Coding, Information Theory (and Advanced ModulationCoding, Information Theory (and Advanced Modulation
Coding, Information Theory (and Advanced Modulationjeronimored
 
8085microprocessorarchitectureppt-121013115356-phpapp02_2.ppt
8085microprocessorarchitectureppt-121013115356-phpapp02_2.ppt8085microprocessorarchitectureppt-121013115356-phpapp02_2.ppt
8085microprocessorarchitectureppt-121013115356-phpapp02_2.pptjeronimored
 
A microprocessor is the main component of a microcomputer system and is also ...
A microprocessor is the main component of a microcomputer system and is also ...A microprocessor is the main component of a microcomputer system and is also ...
A microprocessor is the main component of a microcomputer system and is also ...jeronimored
 
Erroneous co-routines can block system Formal interfaces slow down system
Erroneous co-routines can block system Formal  interfaces slow down systemErroneous co-routines can block system Formal  interfaces slow down system
Erroneous co-routines can block system Formal interfaces slow down systemjeronimored
 
Welcome to Introduction to Algorithms, Spring 2004
Welcome to Introduction to Algorithms, Spring 2004Welcome to Introduction to Algorithms, Spring 2004
Welcome to Introduction to Algorithms, Spring 2004jeronimored
 
Resource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time SystemsResource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time Systemsjeronimored
 
Management Tools Desirable features Management Architectures Simple Network ...
Management Tools  Desirable features Management Architectures Simple Network ...Management Tools  Desirable features Management Architectures Simple Network ...
Management Tools Desirable features Management Architectures Simple Network ...jeronimored
 
MICMicrowave Tubes – klystron, reflex klystron, magnetron and TWT.
MICMicrowave Tubes – klystron, reflex klystron, magnetron and TWT.MICMicrowave Tubes – klystron, reflex klystron, magnetron and TWT.
MICMicrowave Tubes – klystron, reflex klystron, magnetron and TWT.jeronimored
 
Network Management Network Management Model
Network Management Network Management ModelNetwork Management Network Management Model
Network Management Network Management Modeljeronimored
 
Saumya Debray The University of Arizona Tucson
Saumya Debray The University of Arizona TucsonSaumya Debray The University of Arizona Tucson
Saumya Debray The University of Arizona Tucsonjeronimored
 
An operating system (OS) provides a virtual execution environment on top of h...
An operating system (OS) provides a virtual execution environment on top of h...An operating system (OS) provides a virtual execution environment on top of h...
An operating system (OS) provides a virtual execution environment on top of h...jeronimored
 
application Fundamentals Android Introduction
application Fundamentals  Android Introductionapplication Fundamentals  Android Introduction
application Fundamentals Android Introductionjeronimored
 
linux-lecture1.ppt
linux-lecture1.pptlinux-lecture1.ppt
linux-lecture1.pptjeronimored
 

More from jeronimored (20)

Computer Networks 7.Physical LayerComputer Networks 7.Physical Layer
Computer Networks 7.Physical LayerComputer Networks 7.Physical LayerComputer Networks 7.Physical LayerComputer Networks 7.Physical Layer
Computer Networks 7.Physical LayerComputer Networks 7.Physical Layer
 
Android – Open source mobile OS developed ny the Open Handset Alliance led by...
Android – Open source mobile OS developed ny the Open Handset Alliance led by...Android – Open source mobile OS developed ny the Open Handset Alliance led by...
Android – Open source mobile OS developed ny the Open Handset Alliance led by...
 
Intel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.pptIntel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.ppt
 
Intro Ch 01BA business alliance consisting of 47 companies to develop open st...
Intro Ch 01BA business alliance consisting of 47 companies to develop open st...Intro Ch 01BA business alliance consisting of 47 companies to develop open st...
Intro Ch 01BA business alliance consisting of 47 companies to develop open st...
 
preKnowledge-InternetNetworking Android's mobile operating system is based on...
preKnowledge-InternetNetworking Android's mobile operating system is based on...preKnowledge-InternetNetworking Android's mobile operating system is based on...
preKnowledge-InternetNetworking Android's mobile operating system is based on...
 
TelecommunicationsThe Internet Basic Telecom Model
TelecommunicationsThe Internet Basic Telecom ModelTelecommunicationsThe Internet Basic Telecom Model
TelecommunicationsThe Internet Basic Telecom Model
 
Functional Areas of Network Management Configuration Management
Functional Areas of Network Management Configuration ManagementFunctional Areas of Network Management Configuration Management
Functional Areas of Network Management Configuration Management
 
Coding, Information Theory (and Advanced Modulation
Coding, Information Theory (and Advanced ModulationCoding, Information Theory (and Advanced Modulation
Coding, Information Theory (and Advanced Modulation
 
8085microprocessorarchitectureppt-121013115356-phpapp02_2.ppt
8085microprocessorarchitectureppt-121013115356-phpapp02_2.ppt8085microprocessorarchitectureppt-121013115356-phpapp02_2.ppt
8085microprocessorarchitectureppt-121013115356-phpapp02_2.ppt
 
A microprocessor is the main component of a microcomputer system and is also ...
A microprocessor is the main component of a microcomputer system and is also ...A microprocessor is the main component of a microcomputer system and is also ...
A microprocessor is the main component of a microcomputer system and is also ...
 
Erroneous co-routines can block system Formal interfaces slow down system
Erroneous co-routines can block system Formal  interfaces slow down systemErroneous co-routines can block system Formal  interfaces slow down system
Erroneous co-routines can block system Formal interfaces slow down system
 
Welcome to Introduction to Algorithms, Spring 2004
Welcome to Introduction to Algorithms, Spring 2004Welcome to Introduction to Algorithms, Spring 2004
Welcome to Introduction to Algorithms, Spring 2004
 
Resource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time SystemsResource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time Systems
 
Management Tools Desirable features Management Architectures Simple Network ...
Management Tools  Desirable features Management Architectures Simple Network ...Management Tools  Desirable features Management Architectures Simple Network ...
Management Tools Desirable features Management Architectures Simple Network ...
 
MICMicrowave Tubes – klystron, reflex klystron, magnetron and TWT.
MICMicrowave Tubes – klystron, reflex klystron, magnetron and TWT.MICMicrowave Tubes – klystron, reflex klystron, magnetron and TWT.
MICMicrowave Tubes – klystron, reflex klystron, magnetron and TWT.
 
Network Management Network Management Model
Network Management Network Management ModelNetwork Management Network Management Model
Network Management Network Management Model
 
Saumya Debray The University of Arizona Tucson
Saumya Debray The University of Arizona TucsonSaumya Debray The University of Arizona Tucson
Saumya Debray The University of Arizona Tucson
 
An operating system (OS) provides a virtual execution environment on top of h...
An operating system (OS) provides a virtual execution environment on top of h...An operating system (OS) provides a virtual execution environment on top of h...
An operating system (OS) provides a virtual execution environment on top of h...
 
application Fundamentals Android Introduction
application Fundamentals  Android Introductionapplication Fundamentals  Android Introduction
application Fundamentals Android Introduction
 
linux-lecture1.ppt
linux-lecture1.pptlinux-lecture1.ppt
linux-lecture1.ppt
 

Recently uploaded

Beautiful Sapna Call Girls CP 9711199012 ☎ Call /Whatsapps
Beautiful Sapna Call Girls CP 9711199012 ☎ Call /WhatsappsBeautiful Sapna Call Girls CP 9711199012 ☎ Call /Whatsapps
Beautiful Sapna Call Girls CP 9711199012 ☎ Call /Whatsappssapnasaifi408
 
如何办理(UCLA毕业证书)加州大学洛杉矶分校毕业证成绩单留信学历认证原版一比一
如何办理(UCLA毕业证书)加州大学洛杉矶分校毕业证成绩单留信学历认证原版一比一如何办理(UCLA毕业证书)加州大学洛杉矶分校毕业证成绩单留信学历认证原版一比一
如何办理(UCLA毕业证书)加州大学洛杉矶分校毕业证成绩单留信学历认证原版一比一ga6c6bdl
 
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一zul5vf0pq
 
VIP Call Girls Kavuri Hills ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With ...
VIP Call Girls Kavuri Hills ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With ...VIP Call Girls Kavuri Hills ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With ...
VIP Call Girls Kavuri Hills ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With ...Suhani Kapoor
 
(办理学位证)多伦多大学毕业证成绩单原版一比一
(办理学位证)多伦多大学毕业证成绩单原版一比一(办理学位证)多伦多大学毕业证成绩单原版一比一
(办理学位证)多伦多大学毕业证成绩单原版一比一C SSS
 
萨斯喀彻温大学毕业证学位证成绩单-购买流程
萨斯喀彻温大学毕业证学位证成绩单-购买流程萨斯喀彻温大学毕业证学位证成绩单-购买流程
萨斯喀彻温大学毕业证学位证成绩单-购买流程1k98h0e1
 
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...Authentic No 1 Amil Baba In Pakistan
 
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一定制(UI学位证)爱达荷大学毕业证成绩单原版一比一
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一ss ss
 
Call Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile serviceCall Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile servicerehmti665
 
Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service GayaGaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service Gayasrsj9000
 
如何办理(NUS毕业证书)新加坡国立大学毕业证成绩单留信学历认证原版一比一
如何办理(NUS毕业证书)新加坡国立大学毕业证成绩单留信学历认证原版一比一如何办理(NUS毕业证书)新加坡国立大学毕业证成绩单留信学历认证原版一比一
如何办理(NUS毕业证书)新加坡国立大学毕业证成绩单留信学历认证原版一比一ga6c6bdl
 
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up Number
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up NumberCall Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up Number
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up NumberMs Riya
 
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service - Bandra F...
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service -  Bandra F...WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service -  Bandra F...
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service - Bandra F...Pooja Nehwal
 
如何办理(Adelaide毕业证)阿德莱德大学毕业证成绩单Adelaide学历认证真实可查
如何办理(Adelaide毕业证)阿德莱德大学毕业证成绩单Adelaide学历认证真实可查如何办理(Adelaide毕业证)阿德莱德大学毕业证成绩单Adelaide学历认证真实可查
如何办理(Adelaide毕业证)阿德莱德大学毕业证成绩单Adelaide学历认证真实可查awo24iot
 
定制(Salford学位证)索尔福德大学毕业证成绩单原版一比一
定制(Salford学位证)索尔福德大学毕业证成绩单原版一比一定制(Salford学位证)索尔福德大学毕业证成绩单原版一比一
定制(Salford学位证)索尔福德大学毕业证成绩单原版一比一ss ss
 
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...Amil baba
 
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
VIP Call Girl Saharanpur Aashi 8250192130 Independent Escort Service Saharanpur
VIP Call Girl Saharanpur Aashi 8250192130 Independent Escort Service SaharanpurVIP Call Girl Saharanpur Aashi 8250192130 Independent Escort Service Saharanpur
VIP Call Girl Saharanpur Aashi 8250192130 Independent Escort Service SaharanpurSuhani Kapoor
 

Recently uploaded (20)

Beautiful Sapna Call Girls CP 9711199012 ☎ Call /Whatsapps
Beautiful Sapna Call Girls CP 9711199012 ☎ Call /WhatsappsBeautiful Sapna Call Girls CP 9711199012 ☎ Call /Whatsapps
Beautiful Sapna Call Girls CP 9711199012 ☎ Call /Whatsapps
 
如何办理(UCLA毕业证书)加州大学洛杉矶分校毕业证成绩单留信学历认证原版一比一
如何办理(UCLA毕业证书)加州大学洛杉矶分校毕业证成绩单留信学历认证原版一比一如何办理(UCLA毕业证书)加州大学洛杉矶分校毕业证成绩单留信学历认证原版一比一
如何办理(UCLA毕业证书)加州大学洛杉矶分校毕业证成绩单留信学历认证原版一比一
 
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一
定制加拿大滑铁卢大学毕业证(Waterloo毕业证书)成绩单(文凭)原版一比一
 
VIP Call Girls Kavuri Hills ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With ...
VIP Call Girls Kavuri Hills ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With ...VIP Call Girls Kavuri Hills ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With ...
VIP Call Girls Kavuri Hills ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With ...
 
(办理学位证)多伦多大学毕业证成绩单原版一比一
(办理学位证)多伦多大学毕业证成绩单原版一比一(办理学位证)多伦多大学毕业证成绩单原版一比一
(办理学位证)多伦多大学毕业证成绩单原版一比一
 
萨斯喀彻温大学毕业证学位证成绩单-购买流程
萨斯喀彻温大学毕业证学位证成绩单-购买流程萨斯喀彻温大学毕业证学位证成绩单-购买流程
萨斯喀彻温大学毕业证学位证成绩单-购买流程
 
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...
 
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一定制(UI学位证)爱达荷大学毕业证成绩单原版一比一
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一
 
Call Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile serviceCall Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile service
 
Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service GayaGaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
 
如何办理(NUS毕业证书)新加坡国立大学毕业证成绩单留信学历认证原版一比一
如何办理(NUS毕业证书)新加坡国立大学毕业证成绩单留信学历认证原版一比一如何办理(NUS毕业证书)新加坡国立大学毕业证成绩单留信学历认证原版一比一
如何办理(NUS毕业证书)新加坡国立大学毕业证成绩单留信学历认证原版一比一
 
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up Number
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up NumberCall Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up Number
Call Girls Delhi {Rs-10000 Laxmi Nagar] 9711199012 Whats Up Number
 
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Jejuri ( 7001035870 ) HI-Fi Pune Escorts Service
 
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service - Bandra F...
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service -  Bandra F...WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service -  Bandra F...
WhatsApp 9892124323 ✓Call Girls In Khar ( Mumbai ) secure service - Bandra F...
 
如何办理(Adelaide毕业证)阿德莱德大学毕业证成绩单Adelaide学历认证真实可查
如何办理(Adelaide毕业证)阿德莱德大学毕业证成绩单Adelaide学历认证真实可查如何办理(Adelaide毕业证)阿德莱德大学毕业证成绩单Adelaide学历认证真实可查
如何办理(Adelaide毕业证)阿德莱德大学毕业证成绩单Adelaide学历认证真实可查
 
定制(Salford学位证)索尔福德大学毕业证成绩单原版一比一
定制(Salford学位证)索尔福德大学毕业证成绩单原版一比一定制(Salford学位证)索尔福德大学毕业证成绩单原版一比一
定制(Salford学位证)索尔福德大学毕业证成绩单原版一比一
 
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...
 
9953330565 Low Rate Call Girls In Jahangirpuri Delhi NCR
9953330565 Low Rate Call Girls In Jahangirpuri  Delhi NCR9953330565 Low Rate Call Girls In Jahangirpuri  Delhi NCR
9953330565 Low Rate Call Girls In Jahangirpuri Delhi NCR
 
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(ANIKA) Wanwadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
VIP Call Girl Saharanpur Aashi 8250192130 Independent Escort Service Saharanpur
VIP Call Girl Saharanpur Aashi 8250192130 Independent Escort Service SaharanpurVIP Call Girl Saharanpur Aashi 8250192130 Independent Escort Service Saharanpur
VIP Call Girl Saharanpur Aashi 8250192130 Independent Escort Service Saharanpur
 

7645347.ppt

  • 1. Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Machine-independent code improvement Target code generation Machine-specific code improvement Front End Backend
  • 2. Lexical Analysis • Lexical analyzer: reads input characters and produces a sequence of tokens as output (nexttoken()). – Trying to understand each element in a program. – Token: a group of characters having a collective meaning. const pi = 3.14159; Token 1: (const, -) Token 2: (identifier, ‘pi’) Token 3: (=, -) Token 4: (realnumber, 3.14159) Token 5: (;, -)
  • 3. Interaction of Lexical analyzer with parser Lexical analyzer symbol table parser Source program token Nexttoken()
  • 4. • Some terminology: – Token: a group of characters having a collective meaning. A lexeme is a particular instant of a token. • E.g. token: identifier, lexeme: pi, etc. – pattern: the rule describing how a token can be formed. • E.g: identifier: ([a-z]|[A-Z]) ([a-z]|[A-Z]|[0-9])* • Lexical analyzer does not have to be an individual phase. But having a separate phase simplifies the design and improves the efficiency and portability.
  • 5. • Two issues in lexical analysis. – How to specify tokens (patterns)? – How to recognize the tokens given a token specification (how to implement the nexttoken() routine)? • How to specify tokens: – all the basic elements in a language must be tokens so that they can be recognized. • There are not many types of tokens in a typical programming language: constant, identifier, reserved word, operator and misc. symbol. main() { int i, j; for (i=0; i<50; i++) { printf(“i = %d”, i); } }
  • 6. • Type of tokens in C++: – Constants: • char constants: ‘a’ • string constants: “I=%d” • int constants: 50 • float point constants – Identifiers: i, j, counter, …… – Reserved words: main, int, for, … – Operators: +, =, ++, /, … – Misc. symbols: (, ), {, }, … • Tokens are specified by regular expressions. main() { int i, j; for (I=0; I<50; I++) { printf(“I = %d”, I); } }
  • 7. • Definitions – alphabet : a finite set of symbols. E.g. {a, b, c} – A string over an alphabet is a finite sequence of symbols drawn from that alphabet (sometimes a string is also called a sentence or a word). – A language is a set of strings over an alphabet. – Operation on languages (a set): • union of L and M, L U M = {s|s is in L or s is in M} • concatenation of L and M LM = {st | s is in L and t is in M} • Kleene closure of L, • Positive closure of L, – Example: • L={aa, bb, cc}, M = {abc} i i L L    0 *  i i L L     1 
  • 8. • Formal definition of Regular expression • Given an alphabet , • (1) is a regular expression that denote { }, the set that contains the empty string. • (2) For each , a is a regular expression denote {a}, the set containing the string a. • (3) r and s are regular expressions denoting the language (set) L(r ) and L(s ). Then – ( r ) | ( s ) is a regular expression denoting L( r ) U L( s ) – ( r ) ( s ) is a regular expression denoting L( r ) L ( s ) – ( r )* is a regular expression denoting (L ( r )) * • Regular expression is defined together with the language it denotes.      a
  • 9. • Examples: – let a | b (a | b) (a | b) a * (a | b)* a | a*b – We assume that ‘*’ has the highest precedence and is left associative. Concatenation has second highest precedence and is left associative and ‘|’ has the lowest precedence and is left associative • (a) | ((b)*(c ) ) = a | b*c  } , { b a
  • 10. • Regular definition. – gives names to regular expressions to construct more complicate regular expressions. d1 -> r1 d2 ->r2 … dn ->rn – example: letter -> A | B | C | … | Z | a | b | …. | z digit -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 identifier -> letter (letter | digit) * – Cannot use recursive definitions • digits -> digit digits | digit
  • 11. Regular expression for tokens in C++ – Constants: • char constants: ‘’’ any_char ‘’’ • string constants: “I=%d” – ‘”’ [^”]* ‘”’ – not quite right. • int constants: 50 -- digit (digit)* • float point constants 50.0 – digit (digit)* ‘.’ digit (digit) * – Identifiers: letter (letter | digit | ‘_’) * – Reserved words: ‘m’’a’’i’’n’ for main – Operators: ‘+’ for +, and ‘+’ ‘+’ for ++ – Misc symbols: ‘(‘ for (
  • 12. Regular expression for tokens in C++ • A signed number in C++: 3.1416 +2006 1e-010 -3.14159 2006.00000 0.00000 3.14159e+000 2.00600e+003 -1.00000E-010
  • 13. Regular expression for tokens in C++ • A signed number in C++: 3.1416 +2006 1e-010 -3.14159 2006.00000 0.00000 3.14159e+000 2.00600e+003 -1.00000E-010 Num -> digit (digit)* NUMBER->(+|-| ) (Num | Num . Num) ( | (e|E)(+|-| )Num )   