SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
Lexical Analysis
Lecture 3
Lexical Analysis
Introduction
• For an English sentence:
– Read the sentence string
– Recognize its parts of speech – noun, verb, adjective,
etc…
– Match these parts of speech against a grammar
• For computer languages:
– Extract the words (lexemes) of the input string
– Classify them according to their roles (parts of speech)
• This is tokenization – finding token classes
– Lexical analyzer recognizes the string by matching
these tokens against a grammar
8-Jan-15 2CS 346 Lecture 3
• Lexical Structure of a programming language
consists of a set of token classes
– Operators, whitespaces, keywords, identifiers,
numbers, (, ), ;, = etc…
• Lexical Analysis
Introduction
• Lexical Analysis
– Classify the program substrings into various token
classes and communicate them to the parser.
• Goal – Given the specification for token classes
of a language, automatically construct a lexical
analyzer
8-Jan-15 3CS 346 Lecture 3
Regular Expressions
• Each token class consists of a set of strings.
• A distinct set of strings constitute a language over an alphabet .
– Alphabet: A finite set of symbols by which the strings of the language
may be formed
• They are regular languages (recognized by FA)
• Regular languages – defined by regular expressions (RE)
• RE’s denote the set of strings recognized by a language by defining
their pattern
• Automation steps:
– RE NFA DFA Table-Driven Implementation
8-Jan-15 4CS 346 Lecture 3
• Two basic RE’s
– Single character RE – eg: ‘B’: A language containing
one string which is the single character ‘B’
– Epsilon RE – ɛ : A language which contains one
string, the empty string.
Regular Expressions
• Three compound RE’s
– Union – eg.: A + B or A | B (either A or B)
– Concatenation – eg.: AB {ab | a Є AΛ b Є B}
– Iteration – eg.: A* – 0 or more occurrences of A
• A0 = ɛ
• (A) has the same meaning as A
Regular Language (Set)
• The regular expression over alphabet Σ are the
smallest set of expressions including
R = ɛ
| ‘c’ for c Є Σ (alphabet)| ‘c’ for c Є Σ (alphabet)
| R + R (union)
| RR (concatenation)
| R* (iteration)
• Operator precedence: (A), A*, AB, A|B
– So ab*c|d is parsed as ((a(b*))c)|d
• Describe the languages denoted by the following
REs when alphabet (Σ) = {0,1}
– 1*; (1+0)1; 0*+1*; 01(01)*, (0+1)*, 11(0+1)*
Regular Expressions
– 1*; (1+0)1; 0*+1*; 01(01)*, (0+1)*, 11(0+1)*
• Short-hands:
– Character range: [a-d] for a | b | c | d;
– Atleast one: r+ for rr*;
– Option: r? for r | e
– Excluded range: [^a-z] = Complement of [a-z]
• Write RE’s for:
– Strings of 0’s and 1’s containing 00 as a substring
Regular Expressions
• Write RE’s that:
– Recognizes our email addresses at IITG
– Recognizes a number consisting of: One or more
digits, followed by an optional fractional part,
followed by an optional exponent.
Lexical Specification of a Language
1. Write REs for the lexemes of each token class:
Number = digit+
Keyword = ‘if’ + ‘else’ + …
Identifier = letter (letter + digit)*Identifier = letter (letter + digit)*
…
2. Construct R, matching all lexemes for all tokens:
R = Keyword + Identifier + Number + …
= R1 + R2 + …
1. Let input be x1…xn
For 1 <= i <= n check
x1…xi Є L(R)
Lexical Specification of a Language
2. If success, then we know that:
x1…xi Є L(Rj) for some j
3. Remove x1…xi from input and go to (3)
• How much of the input to use?
– x1 …xi Є L(R)
– x1…xj Є L(R), i ≠ j
Solution: “Maximal Munch”
• What if more than one token matches?
Lexical Specification of a Language
• What if more than one token matches?
– x1 …xi Є L(Rx)
– x1…xi Є L(Ry)
– Solution: Priority ordering – Choose the one listed first
• What to do when no rule matches?
– Solution: Make special token class / classes for all error
strings. Put it last in the priority list.
Lecture3 lexical analysis

Contenu connexe

Tendances (20)

Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
 
Lexical
LexicalLexical
Lexical
 
Compiler lec 8
Compiler lec 8Compiler lec 8
Compiler lec 8
 
Compiler design and lexical analyser
Compiler design and lexical analyserCompiler design and lexical analyser
Compiler design and lexical analyser
 
Lexical analysis
Lexical analysisLexical analysis
Lexical analysis
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysis
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
Lecture4 lexical analysis2
Lecture4 lexical analysis2Lecture4 lexical analysis2
Lecture4 lexical analysis2
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Lexical Analyzers and Parsers
Lexical Analyzers and ParsersLexical Analyzers and Parsers
Lexical Analyzers and Parsers
 
Lex
LexLex
Lex
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 

En vedette

13. Constantin Orasan (UoW) Natural Language Processing for Translation
13. Constantin Orasan (UoW) Natural Language Processing for Translation13. Constantin Orasan (UoW) Natural Language Processing for Translation
13. Constantin Orasan (UoW) Natural Language Processing for TranslationRIILP
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionSarmad Ali
 
Lecture2 general structure of a compiler
Lecture2 general structure of a compilerLecture2 general structure of a compiler
Lecture2 general structure of a compilerMahesh Kumar Chelimilla
 
Symbolic Automata = Automata + SMT solvers at ExCape14
Symbolic Automata = Automata + SMT solvers at ExCape14Symbolic Automata = Automata + SMT solvers at ExCape14
Symbolic Automata = Automata + SMT solvers at ExCape14Loris D'Antoni
 
DFA minimization algorithms in map reduce
DFA minimization algorithms in map reduceDFA minimization algorithms in map reduce
DFA minimization algorithms in map reduceIraj Hedayati
 
Nltk:a tool for_nlp - py_con-dhaka-2014
Nltk:a tool for_nlp - py_con-dhaka-2014Nltk:a tool for_nlp - py_con-dhaka-2014
Nltk:a tool for_nlp - py_con-dhaka-2014Fasihul Kabir
 
نموذج مسار هندسة الأفكار
نموذج مسار هندسة الأفكارنموذج مسار هندسة الأفكار
نموذج مسار هندسة الأفكارHani Al-Menaii
 
هندسة الأفكار
هندسة الأفكارهندسة الأفكار
هندسة الأفكارHani Al-Menaii
 

En vedette (17)

Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
13. Constantin Orasan (UoW) Natural Language Processing for Translation
13. Constantin Orasan (UoW) Natural Language Processing for Translation13. Constantin Orasan (UoW) Natural Language Processing for Translation
13. Constantin Orasan (UoW) Natural Language Processing for Translation
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Lecture6 syntax analysis_2
Lecture6 syntax analysis_2Lecture6 syntax analysis_2
Lecture6 syntax analysis_2
 
Lecture5 syntax analysis_1
Lecture5 syntax analysis_1Lecture5 syntax analysis_1
Lecture5 syntax analysis_1
 
Lecture2 general structure of a compiler
Lecture2 general structure of a compilerLecture2 general structure of a compiler
Lecture2 general structure of a compiler
 
تعرف إلى-الهندسة المعلوماتية
تعرف إلى-الهندسة المعلوماتيةتعرف إلى-الهندسة المعلوماتية
تعرف إلى-الهندسة المعلوماتية
 
Symbolic Automata = Automata + SMT solvers at ExCape14
Symbolic Automata = Automata + SMT solvers at ExCape14Symbolic Automata = Automata + SMT solvers at ExCape14
Symbolic Automata = Automata + SMT solvers at ExCape14
 
ف 2 الدرس الأول والثانى والثالث
ف 2 الدرس الأول والثانى والثالثف 2 الدرس الأول والثانى والثالث
ف 2 الدرس الأول والثانى والثالث
 
Forouzan atm
Forouzan atmForouzan atm
Forouzan atm
 
Lecture1 introduction compilers
Lecture1 introduction compilersLecture1 introduction compilers
Lecture1 introduction compilers
 
DFA minimization algorithms in map reduce
DFA minimization algorithms in map reduceDFA minimization algorithms in map reduce
DFA minimization algorithms in map reduce
 
DFA Minimization
DFA MinimizationDFA Minimization
DFA Minimization
 
optimization of DFA
optimization of DFAoptimization of DFA
optimization of DFA
 
Nltk:a tool for_nlp - py_con-dhaka-2014
Nltk:a tool for_nlp - py_con-dhaka-2014Nltk:a tool for_nlp - py_con-dhaka-2014
Nltk:a tool for_nlp - py_con-dhaka-2014
 
نموذج مسار هندسة الأفكار
نموذج مسار هندسة الأفكارنموذج مسار هندسة الأفكار
نموذج مسار هندسة الأفكار
 
هندسة الأفكار
هندسة الأفكارهندسة الأفكار
هندسة الأفكار
 

Similaire à Lecture3 lexical analysis

Regular expressions h1
Regular expressions h1Regular expressions h1
Regular expressions h1Rajendran
 
Syntax Analyzer.pdf
Syntax Analyzer.pdfSyntax Analyzer.pdf
Syntax Analyzer.pdfkenilpatel65
 
Chapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfChapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfDrIsikoIsaac
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler DesignKuppusamy P
 
Theory of computing
Theory of computingTheory of computing
Theory of computingRanjan Kumar
 
01-Introduction&Languages.pdf
01-Introduction&Languages.pdf01-Introduction&Languages.pdf
01-Introduction&Languages.pdfTariqSaeed80
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
Compiler Design ug semLexical Analysis.ppt
Compiler Design ug semLexical Analysis.pptCompiler Design ug semLexical Analysis.ppt
Compiler Design ug semLexical Analysis.pptssuser6ba09a
 
Compiler Designs
Compiler DesignsCompiler Designs
Compiler Designswasim liam
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2gadisaAdamu
 

Similaire à Lecture3 lexical analysis (20)

Syntax
SyntaxSyntax
Syntax
 
Regular expressions h1
Regular expressions h1Regular expressions h1
Regular expressions h1
 
Syntax Analyzer.pdf
Syntax Analyzer.pdfSyntax Analyzer.pdf
Syntax Analyzer.pdf
 
7645347.ppt
7645347.ppt7645347.ppt
7645347.ppt
 
Control structure
Control structureControl structure
Control structure
 
Chapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfChapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdf
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
SS UI Lecture 4
SS UI Lecture 4SS UI Lecture 4
SS UI Lecture 4
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
01-Introduction&Languages.pdf
01-Introduction&Languages.pdf01-Introduction&Languages.pdf
01-Introduction&Languages.pdf
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Compiler Design ug semLexical Analysis.ppt
Compiler Design ug semLexical Analysis.pptCompiler Design ug semLexical Analysis.ppt
Compiler Design ug semLexical Analysis.ppt
 
Compiler Designs
Compiler DesignsCompiler Designs
Compiler Designs
 
L_2_apl.pptx
L_2_apl.pptxL_2_apl.pptx
L_2_apl.pptx
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
 

Plus de Mahesh Kumar Chelimilla (14)

Lecture11 syntax analysis_7
Lecture11 syntax analysis_7Lecture11 syntax analysis_7
Lecture11 syntax analysis_7
 
Lecture10 syntax analysis_6
Lecture10 syntax analysis_6Lecture10 syntax analysis_6
Lecture10 syntax analysis_6
 
Lecture9 syntax analysis_5
Lecture9 syntax analysis_5Lecture9 syntax analysis_5
Lecture9 syntax analysis_5
 
Lecture8 syntax analysis_4
Lecture8 syntax analysis_4Lecture8 syntax analysis_4
Lecture8 syntax analysis_4
 
Lecture7 syntax analysis_3
Lecture7 syntax analysis_3Lecture7 syntax analysis_3
Lecture7 syntax analysis_3
 
Transportlayer tanenbaum
Transportlayer tanenbaumTransportlayer tanenbaum
Transportlayer tanenbaum
 
Network layer tanenbaum
Network layer tanenbaumNetwork layer tanenbaum
Network layer tanenbaum
 
Forouzan x25
Forouzan x25Forouzan x25
Forouzan x25
 
Forouzan ppp
Forouzan pppForouzan ppp
Forouzan ppp
 
Forouzan isdn
Forouzan isdnForouzan isdn
Forouzan isdn
 
Forouzan frame relay
Forouzan frame relayForouzan frame relay
Forouzan frame relay
 
Forouzan data link_2
Forouzan data link_2Forouzan data link_2
Forouzan data link_2
 
Forouzan data link_1
Forouzan data link_1Forouzan data link_1
Forouzan data link_1
 
Datalinklayer tanenbaum
Datalinklayer tanenbaumDatalinklayer tanenbaum
Datalinklayer tanenbaum
 

Dernier

VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
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
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 

Dernier (20)

VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
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
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
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
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 

Lecture3 lexical analysis

  • 2. Introduction • For an English sentence: – Read the sentence string – Recognize its parts of speech – noun, verb, adjective, etc… – Match these parts of speech against a grammar • For computer languages: – Extract the words (lexemes) of the input string – Classify them according to their roles (parts of speech) • This is tokenization – finding token classes – Lexical analyzer recognizes the string by matching these tokens against a grammar 8-Jan-15 2CS 346 Lecture 3
  • 3. • Lexical Structure of a programming language consists of a set of token classes – Operators, whitespaces, keywords, identifiers, numbers, (, ), ;, = etc… • Lexical Analysis Introduction • Lexical Analysis – Classify the program substrings into various token classes and communicate them to the parser. • Goal – Given the specification for token classes of a language, automatically construct a lexical analyzer 8-Jan-15 3CS 346 Lecture 3
  • 4. Regular Expressions • Each token class consists of a set of strings. • A distinct set of strings constitute a language over an alphabet . – Alphabet: A finite set of symbols by which the strings of the language may be formed • They are regular languages (recognized by FA) • Regular languages – defined by regular expressions (RE) • RE’s denote the set of strings recognized by a language by defining their pattern • Automation steps: – RE NFA DFA Table-Driven Implementation 8-Jan-15 4CS 346 Lecture 3
  • 5. • Two basic RE’s – Single character RE – eg: ‘B’: A language containing one string which is the single character ‘B’ – Epsilon RE – ɛ : A language which contains one string, the empty string. Regular Expressions • Three compound RE’s – Union – eg.: A + B or A | B (either A or B) – Concatenation – eg.: AB {ab | a Є AΛ b Є B} – Iteration – eg.: A* – 0 or more occurrences of A • A0 = ɛ • (A) has the same meaning as A
  • 6. Regular Language (Set) • The regular expression over alphabet Σ are the smallest set of expressions including R = ɛ | ‘c’ for c Є Σ (alphabet)| ‘c’ for c Є Σ (alphabet) | R + R (union) | RR (concatenation) | R* (iteration)
  • 7. • Operator precedence: (A), A*, AB, A|B – So ab*c|d is parsed as ((a(b*))c)|d • Describe the languages denoted by the following REs when alphabet (Σ) = {0,1} – 1*; (1+0)1; 0*+1*; 01(01)*, (0+1)*, 11(0+1)* Regular Expressions – 1*; (1+0)1; 0*+1*; 01(01)*, (0+1)*, 11(0+1)* • Short-hands: – Character range: [a-d] for a | b | c | d; – Atleast one: r+ for rr*; – Option: r? for r | e – Excluded range: [^a-z] = Complement of [a-z]
  • 8. • Write RE’s for: – Strings of 0’s and 1’s containing 00 as a substring Regular Expressions • Write RE’s that: – Recognizes our email addresses at IITG – Recognizes a number consisting of: One or more digits, followed by an optional fractional part, followed by an optional exponent.
  • 9. Lexical Specification of a Language 1. Write REs for the lexemes of each token class: Number = digit+ Keyword = ‘if’ + ‘else’ + … Identifier = letter (letter + digit)*Identifier = letter (letter + digit)* … 2. Construct R, matching all lexemes for all tokens: R = Keyword + Identifier + Number + … = R1 + R2 + …
  • 10. 1. Let input be x1…xn For 1 <= i <= n check x1…xi Є L(R) Lexical Specification of a Language 2. If success, then we know that: x1…xi Є L(Rj) for some j 3. Remove x1…xi from input and go to (3)
  • 11. • How much of the input to use? – x1 …xi Є L(R) – x1…xj Є L(R), i ≠ j Solution: “Maximal Munch” • What if more than one token matches? Lexical Specification of a Language • What if more than one token matches? – x1 …xi Є L(Rx) – x1…xi Є L(Ry) – Solution: Priority ordering – Choose the one listed first • What to do when no rule matches? – Solution: Make special token class / classes for all error strings. Put it last in the priority list.