SlideShare a Scribd company logo
1 of 15
Mr.Keshav Tambre
Information Technology Department
International Institute of Information Technology, I²IT
www.isquareit.edu.in
Regular Expressions To Finite Automata
 Lexical analyzer recognizes tokens present in the source
program
 Compiler defines tokens using RE
 These indicate what characters may go into a lexeme
belonging to a particular token and how they go together
 Lexical analyzer is implemented as FSM
2
Regular Expressions
 Design of lexical analyzer involves:-
 Represent tokens by RE
 Synthesis of finite state machines that recognize desired
strings generated by RE
 Simulating the behavior of FSM which generates the lexical
analyzer
3
Regular Expressions
 RE are notations for specifying patterns
 Alphabet/Character class
 Denotes a finite set of symbols
 String
 Strings are defined over some alphabets, is a finite sequence
of symbols drawn from the alphabet
 Empty string denoted by €
 Language
 Set of strings over some alphabet
4
Specification of Tokens
 ∑={a,b}
 a|b denotes the set {a,b}
 RE (a|b) (a|b) denotes the set {aa,ab,ba,bb}
 (a|b)*
 a|a*b
 Identifiers in C
 letter|(letter | digit)*
5
Regular Expression
 Names given to RE
 If ∑ is an alphabet of basic symbols then RE is a sequence
of definitions of the form:
d1 → r1……….. dn → rn
where di is the distinct name and ri is the RE
 Short hand notations:
 *
 +
 ?
6
Regular Definitions
 Intermediate steps in the construction of the analyzer
 Depicts the action of the lexical analyzer when called
upon by the parser to get the next token
 Positions are represented as circles called as states
 States connected by arrows called edges
 Edges have labels indicating the input characters that
can appear next after the transition diagram has
reached states
 Assumption –TD are deterministic in nature
7
Transition diagrams
 When RE is compiled as a recognizer for a language by
constructing a generalized transition diagram called finite
automata
 Deterministic and Non deterministic
 NFA
 Mathematical model that consists of
 Set of states , s
 Set of input symbol ∑
 Transition function move that maps state symbol pairs to set of states
 A start state
 A final state
8
Finite automata
 Diagrammatically represented as a labeled directed graph
called transition graph
 Implementation-State Transition Table
 DFA
 Special case of NFA in which
 No state has € transition
 For each state s and input symbol a is at most one edge labeled a
leaving s
9
Finite automata
 RE are notations for specifying patterns
 Alphabet/Character class
 Denotes a finite set of symbols
 String
 Strings are defined over some alphabets, is a finite sequence
of symbols drawn from the alphabet
 Empty string denoted by €
 Language
 Set of strings over some alphabet
10
Specification of Tokens
 RE to DFA
 We augment the grammar the RE with #
 Construct nullable,firstpos ,lastpos and followpos which is done by
making traversal over the tree
 Construct DFA from followpos
 Firstpos: at what positions the string can start
 Lastpos:at what positions the string can end
 Follopos:what positions can follow position I in the syntax tree
 Nullable:whether an empty string can be generated at the node (sub
expression)
11
RE to DFA
Node n Nullable(n) Firstpos(n) Lastpos(n)
N is a leaf labeled έ true ø ø
if N is | node with left child
c1 and right child c2
Nullable(c1) or
Nullable (c2)
Firstpos (C1) U Firstpos(C2) Lastpos (C1) U Lasttpos(C2)
N is a leaf labeled with
position i
false { i } { i }
if N is . Node node with left
child c1 and right child c2
Nullable(c1) and
Nullable (c2)
If nullable (C1) then
Firstpos (C1) U Firstpos(C2)
else Firstpos(C1)
If nullable (C2) then
Lastpos (C1) U Lastpos(C2)
else Lastpos(C2)
if N is the node with only c1 as
child
true Firstpos (C1) Lastpos (C2)
12
RE to DFA
 Computation of Followpos : Followpos(i) tells us what
positions can follow position i in the syntax tree. This can be
computed as follows.
 if n is a ‘.’ Node, with a left child C1 and right child C2 and i
is a position in the Lastpos(C1), then all positions in
Firstpos(C2) are in Followpos(i)
 if n is a * Nodeand i is a position in the Lastpos(n), then all
positions in Firstpos(n) are Followpos(i)
13
RE to DFA
Algorithm for construction of DFA transition table
Initially , the only unmarked state in Dstates is firstpos(root), where root is the root of a
syntax tree.
While there is an unmarked state T in Dstates do
Begin
Mark T
For each input symbol a do
Begin
Let U be the set of positions that are in Followpos(P) for some P in T,
such that the symbol at position P is a.
If U is not empty and is not in Dstates then add U as an unmarked
state to Dstates
Dtran [T,a] = U
End
End
14
RE to DFA
Thank You
www.isquareit.edu.in
P-14, Rajiv Gandhi Infotech Park, MIDC Phase – 1,
Hinjawadi, Pune – 411057, India

More Related Content

What's hot (20)

COMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed TranslationCOMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed Translation
 
Analysis of the source program
Analysis of the source programAnalysis of the source program
Analysis of the source program
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Semantics analysis
Semantics analysisSemantics analysis
Semantics analysis
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithm
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Semantic analysis
Semantic analysisSemantic analysis
Semantic analysis
 
Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & Pattern
 
State Diagrams
State DiagramsState Diagrams
State Diagrams
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Parsing
ParsingParsing
Parsing
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Activity diagram
Activity diagramActivity diagram
Activity diagram
 

Similar to Regular Expressions To Finite Automata

Similar to Regular Expressions To Finite Automata (20)

02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.ppt
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
 
Ch3
Ch3Ch3
Ch3
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
Re1 (3)
Re1 (3)Re1 (3)
Re1 (3)
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
Ch 2.pptx
Ch 2.pptxCh 2.pptx
Ch 2.pptx
 
QB104541.pdf
QB104541.pdfQB104541.pdf
QB104541.pdf
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 
Chapter Three(2)
Chapter Three(2)Chapter Three(2)
Chapter Three(2)
 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
 
The Theory of Finite Automata.pptx
The Theory of Finite Automata.pptxThe Theory of Finite Automata.pptx
The Theory of Finite Automata.pptx
 
A simple approach of lexical analyzers
A simple approach of lexical analyzersA simple approach of lexical analyzers
A simple approach of lexical analyzers
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Automata
AutomataAutomata
Automata
 
Automata
AutomataAutomata
Automata
 

More from International Institute of Information Technology (I²IT)

More from International Institute of Information Technology (I²IT) (20)

Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
Understanding Natural Language Processing
Understanding Natural Language ProcessingUnderstanding Natural Language Processing
Understanding Natural Language Processing
 
What Is Smart Computing?
What Is Smart Computing?What Is Smart Computing?
What Is Smart Computing?
 
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
 
Writing Skills: Importance of Writing Skills
Writing Skills: Importance of Writing SkillsWriting Skills: Importance of Writing Skills
Writing Skills: Importance of Writing Skills
 
Professional Communication | Introducing Oneself
Professional Communication | Introducing Oneself Professional Communication | Introducing Oneself
Professional Communication | Introducing Oneself
 
Servlet: A Server-side Technology
Servlet: A Server-side TechnologyServlet: A Server-side Technology
Servlet: A Server-side Technology
 
What Is Jenkins? Features and How It Works
What Is Jenkins? Features and How It WorksWhat Is Jenkins? Features and How It Works
What Is Jenkins? Features and How It Works
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
Hypothesis-Testing
Hypothesis-TestingHypothesis-Testing
Hypothesis-Testing
 
Data Science, Big Data, Data Analytics
Data Science, Big Data, Data AnalyticsData Science, Big Data, Data Analytics
Data Science, Big Data, Data Analytics
 
Types of Artificial Intelligence
Types of Artificial Intelligence Types of Artificial Intelligence
Types of Artificial Intelligence
 
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
 
Sentiment Analysis in Machine Learning
Sentiment Analysis in  Machine LearningSentiment Analysis in  Machine Learning
Sentiment Analysis in Machine Learning
 
What Is Cloud Computing?
What Is Cloud Computing?What Is Cloud Computing?
What Is Cloud Computing?
 
Introduction To Design Pattern
Introduction To Design PatternIntroduction To Design Pattern
Introduction To Design Pattern
 
Importance of Theory of Computations
Importance of Theory of ComputationsImportance of Theory of Computations
Importance of Theory of Computations
 
Java as Object Oriented Programming Language
Java as Object Oriented Programming LanguageJava as Object Oriented Programming Language
Java as Object Oriented Programming Language
 
What Is High Performance-Computing?
What Is High Performance-Computing?What Is High Performance-Computing?
What Is High Performance-Computing?
 
Data Visualization - How to connect Microsoft Forms to Power BI
Data Visualization - How to connect Microsoft Forms to Power BIData Visualization - How to connect Microsoft Forms to Power BI
Data Visualization - How to connect Microsoft Forms to Power BI
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 

Regular Expressions To Finite Automata

  • 1. Mr.Keshav Tambre Information Technology Department International Institute of Information Technology, I²IT www.isquareit.edu.in Regular Expressions To Finite Automata
  • 2.  Lexical analyzer recognizes tokens present in the source program  Compiler defines tokens using RE  These indicate what characters may go into a lexeme belonging to a particular token and how they go together  Lexical analyzer is implemented as FSM 2 Regular Expressions
  • 3.  Design of lexical analyzer involves:-  Represent tokens by RE  Synthesis of finite state machines that recognize desired strings generated by RE  Simulating the behavior of FSM which generates the lexical analyzer 3 Regular Expressions
  • 4.  RE are notations for specifying patterns  Alphabet/Character class  Denotes a finite set of symbols  String  Strings are defined over some alphabets, is a finite sequence of symbols drawn from the alphabet  Empty string denoted by €  Language  Set of strings over some alphabet 4 Specification of Tokens
  • 5.  ∑={a,b}  a|b denotes the set {a,b}  RE (a|b) (a|b) denotes the set {aa,ab,ba,bb}  (a|b)*  a|a*b  Identifiers in C  letter|(letter | digit)* 5 Regular Expression
  • 6.  Names given to RE  If ∑ is an alphabet of basic symbols then RE is a sequence of definitions of the form: d1 → r1……….. dn → rn where di is the distinct name and ri is the RE  Short hand notations:  *  +  ? 6 Regular Definitions
  • 7.  Intermediate steps in the construction of the analyzer  Depicts the action of the lexical analyzer when called upon by the parser to get the next token  Positions are represented as circles called as states  States connected by arrows called edges  Edges have labels indicating the input characters that can appear next after the transition diagram has reached states  Assumption –TD are deterministic in nature 7 Transition diagrams
  • 8.  When RE is compiled as a recognizer for a language by constructing a generalized transition diagram called finite automata  Deterministic and Non deterministic  NFA  Mathematical model that consists of  Set of states , s  Set of input symbol ∑  Transition function move that maps state symbol pairs to set of states  A start state  A final state 8 Finite automata
  • 9.  Diagrammatically represented as a labeled directed graph called transition graph  Implementation-State Transition Table  DFA  Special case of NFA in which  No state has € transition  For each state s and input symbol a is at most one edge labeled a leaving s 9 Finite automata
  • 10.  RE are notations for specifying patterns  Alphabet/Character class  Denotes a finite set of symbols  String  Strings are defined over some alphabets, is a finite sequence of symbols drawn from the alphabet  Empty string denoted by €  Language  Set of strings over some alphabet 10 Specification of Tokens
  • 11.  RE to DFA  We augment the grammar the RE with #  Construct nullable,firstpos ,lastpos and followpos which is done by making traversal over the tree  Construct DFA from followpos  Firstpos: at what positions the string can start  Lastpos:at what positions the string can end  Follopos:what positions can follow position I in the syntax tree  Nullable:whether an empty string can be generated at the node (sub expression) 11 RE to DFA
  • 12. Node n Nullable(n) Firstpos(n) Lastpos(n) N is a leaf labeled έ true ø ø if N is | node with left child c1 and right child c2 Nullable(c1) or Nullable (c2) Firstpos (C1) U Firstpos(C2) Lastpos (C1) U Lasttpos(C2) N is a leaf labeled with position i false { i } { i } if N is . Node node with left child c1 and right child c2 Nullable(c1) and Nullable (c2) If nullable (C1) then Firstpos (C1) U Firstpos(C2) else Firstpos(C1) If nullable (C2) then Lastpos (C1) U Lastpos(C2) else Lastpos(C2) if N is the node with only c1 as child true Firstpos (C1) Lastpos (C2) 12 RE to DFA
  • 13.  Computation of Followpos : Followpos(i) tells us what positions can follow position i in the syntax tree. This can be computed as follows.  if n is a ‘.’ Node, with a left child C1 and right child C2 and i is a position in the Lastpos(C1), then all positions in Firstpos(C2) are in Followpos(i)  if n is a * Nodeand i is a position in the Lastpos(n), then all positions in Firstpos(n) are Followpos(i) 13 RE to DFA
  • 14. Algorithm for construction of DFA transition table Initially , the only unmarked state in Dstates is firstpos(root), where root is the root of a syntax tree. While there is an unmarked state T in Dstates do Begin Mark T For each input symbol a do Begin Let U be the set of positions that are in Followpos(P) for some P in T, such that the symbol at position P is a. If U is not empty and is not in Dstates then add U as an unmarked state to Dstates Dtran [T,a] = U End End 14 RE to DFA
  • 15. Thank You www.isquareit.edu.in P-14, Rajiv Gandhi Infotech Park, MIDC Phase – 1, Hinjawadi, Pune – 411057, India