SlideShare una empresa de Scribd logo
1 de 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 )
 


Más contenido relacionado

Similar a 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 a 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
 

Más de 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
 

Más de 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
 

Último

NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...Amil baba
 
Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Pooja Nehwal
 
Develop Keyboard Skill.pptx er power point
Develop Keyboard Skill.pptx er power pointDevelop Keyboard Skill.pptx er power point
Develop Keyboard Skill.pptx er power pointGetawu
 
Russian Call Girls Kolkata Chhaya 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls Kolkata Chhaya 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls Kolkata Chhaya 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls Kolkata Chhaya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Russian Call Girls In South Delhi Delhi 9711199012 💋✔💕😘 Independent Escorts D...
Russian Call Girls In South Delhi Delhi 9711199012 💋✔💕😘 Independent Escorts D...Russian Call Girls In South Delhi Delhi 9711199012 💋✔💕😘 Independent Escorts D...
Russian Call Girls In South Delhi Delhi 9711199012 💋✔💕😘 Independent Escorts D...nagunakhan
 
presentation about microsoft power point
presentation about microsoft power pointpresentation about microsoft power point
presentation about microsoft power pointchhavia330
 
VVIP Pune Call Girls Kalyani Nagar (7001035870) Pune Escorts Nearby with Comp...
VVIP Pune Call Girls Kalyani Nagar (7001035870) Pune Escorts Nearby with Comp...VVIP Pune Call Girls Kalyani Nagar (7001035870) Pune Escorts Nearby with Comp...
VVIP Pune Call Girls Kalyani Nagar (7001035870) Pune Escorts Nearby with Comp...Call Girls in Nagpur High Profile
 
High Profile Call Girls In Andheri 7738631006 Call girls in mumbai Mumbai ...
High Profile Call Girls In Andheri 7738631006 Call girls in mumbai  Mumbai ...High Profile Call Girls In Andheri 7738631006 Call girls in mumbai  Mumbai ...
High Profile Call Girls In Andheri 7738631006 Call girls in mumbai Mumbai ...Pooja Nehwal
 
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...ranjana rawat
 
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Naicy mandal
 
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...Call Girls in Nagpur High Profile
 
(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
 
FULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhi
FULL ENJOY - 8264348440 Call Girls in Hauz Khas | DelhiFULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhi
FULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhisoniya singh
 
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...ranjana 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
 
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样qaffana
 
Lucknow 💋 Call Girls Adil Nagar | ₹,9500 Pay Cash 8923113531 Free Home Delive...
Lucknow 💋 Call Girls Adil Nagar | ₹,9500 Pay Cash 8923113531 Free Home Delive...Lucknow 💋 Call Girls Adil Nagar | ₹,9500 Pay Cash 8923113531 Free Home Delive...
Lucknow 💋 Call Girls Adil Nagar | ₹,9500 Pay Cash 8923113531 Free Home Delive...anilsa9823
 
Dubai Call Girls O528786472 Call Girls In Dubai Wisteria
Dubai Call Girls O528786472 Call Girls In Dubai WisteriaDubai Call Girls O528786472 Call Girls In Dubai Wisteria
Dubai Call Girls O528786472 Call Girls In Dubai WisteriaUnited Arab Emirates
 

Último (20)

NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
 
Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006
 
Develop Keyboard Skill.pptx er power point
Develop Keyboard Skill.pptx er power pointDevelop Keyboard Skill.pptx er power point
Develop Keyboard Skill.pptx er power point
 
Russian Call Girls Kolkata Chhaya 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls Kolkata Chhaya 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls Kolkata Chhaya 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls Kolkata Chhaya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Russian Call Girls In South Delhi Delhi 9711199012 💋✔💕😘 Independent Escorts D...
Russian Call Girls In South Delhi Delhi 9711199012 💋✔💕😘 Independent Escorts D...Russian Call Girls In South Delhi Delhi 9711199012 💋✔💕😘 Independent Escorts D...
Russian Call Girls In South Delhi Delhi 9711199012 💋✔💕😘 Independent Escorts D...
 
presentation about microsoft power point
presentation about microsoft power pointpresentation about microsoft power point
presentation about microsoft power point
 
VVIP Pune Call Girls Kalyani Nagar (7001035870) Pune Escorts Nearby with Comp...
VVIP Pune Call Girls Kalyani Nagar (7001035870) Pune Escorts Nearby with Comp...VVIP Pune Call Girls Kalyani Nagar (7001035870) Pune Escorts Nearby with Comp...
VVIP Pune Call Girls Kalyani Nagar (7001035870) Pune Escorts Nearby with Comp...
 
High Profile Call Girls In Andheri 7738631006 Call girls in mumbai Mumbai ...
High Profile Call Girls In Andheri 7738631006 Call girls in mumbai  Mumbai ...High Profile Call Girls In Andheri 7738631006 Call girls in mumbai  Mumbai ...
High Profile Call Girls In Andheri 7738631006 Call girls in mumbai Mumbai ...
 
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(MEGHA) Hinjewadi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
 
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
 
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...
 
(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...
 
FULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhi
FULL ENJOY - 8264348440 Call Girls in Hauz Khas | DelhiFULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhi
FULL ENJOY - 8264348440 Call Girls in Hauz Khas | Delhi
 
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
 
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...
 
🔝 9953056974🔝 Delhi Call Girls in Ajmeri Gate
🔝 9953056974🔝 Delhi Call Girls in Ajmeri Gate🔝 9953056974🔝 Delhi Call Girls in Ajmeri Gate
🔝 9953056974🔝 Delhi Call Girls in Ajmeri Gate
 
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
 
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
 
Lucknow 💋 Call Girls Adil Nagar | ₹,9500 Pay Cash 8923113531 Free Home Delive...
Lucknow 💋 Call Girls Adil Nagar | ₹,9500 Pay Cash 8923113531 Free Home Delive...Lucknow 💋 Call Girls Adil Nagar | ₹,9500 Pay Cash 8923113531 Free Home Delive...
Lucknow 💋 Call Girls Adil Nagar | ₹,9500 Pay Cash 8923113531 Free Home Delive...
 
Dubai Call Girls O528786472 Call Girls In Dubai Wisteria
Dubai Call Girls O528786472 Call Girls In Dubai WisteriaDubai Call Girls O528786472 Call Girls In Dubai Wisteria
Dubai Call Girls O528786472 Call Girls In Dubai Wisteria
 

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 )   