cs466(prasad)l14equiv1 equivalence of regular language representations
TRANSCRIPT
cs466(Prasad) L14Equiv 1
Equivalence of Regular Language Representations
cs466(Prasad) L14Equiv 2
Regular Languages: Grand UnificationGrand Unification
)(
)()(
DFAsL
NFAsLsNFAL
)()(
)()(
RELFAL
RELFAL
(Parallel Simulation) (Rabin and Scott’s work)
(Collapsing graphs; Structural Induction)(S. Kleene’s work)
)()( RGLFAL (Construction)(Solving linear equations))()( RELRGL
cs466(Prasad) L14Equiv 3
Role of various representations for Regular Languages
• Closure under complemention. (DFAs)• Closure under union, concatenation, and Kleene
star. (NFA-s, Regular expression.)• Consequence:
Closure under intersection by De Morgan’s Laws.
• Relationship to context-free languages. (Regular Grammars.)
• Ease of specification. (Regular expression.)
• Building tokenizers/lexical analyzers. (DFAs)
cs466(Prasad) L14Equiv 4
Application to Scanner (Lexer, Tokenizer)
• High-level view
Regularexpressions
NFA
DFA
LexicalSpecification
Table-driven Implementation of a minimal DFA
cs466(Prasad) L14Equiv 5
M(a)
Construction of Finite Automata from Regular Expressions
)()( FALREL
Show that there are FA for basis elements and there exist constructions on FA for capturing union, concatenation, and Kleene star operations.
Basis Case
cs466(Prasad) L14Equiv 6
Constructions on NFA-s
M(R1)
M(R1)
M(R2)
MM(R1 U R2)
MM(R1 R2)
MM(R*)
M(R2)
M(R)
cs466(Prasad) L14Equiv 7
Construction of Regular Expression from Finite Automaton
• Expression Graph is a labeled directed graph in which the arcs are labeled by regular expressions. An expression graph, like a state diagram, contains a distinguished start node and a set of accepting nodes.
cs466(Prasad) L14Equiv 8
Examples
ab
L(M) = (ab)*
cs466(Prasad) L14Equiv 9
Examples
ba
L(M) = (b+ a)* (a u b) (ba)*
b+ a
a u b
cs466(Prasad) L14Equiv 10
Examples
bb
L(M) = (b a)* b*( bb u (a+(ba)*b*) )*
ba
b*
a+
cs466(Prasad) L14Equiv 11
Main Idea
• To associate an RE with an FA, – reduce an arbitrary expression graph to one
containing at most two nodes, – by repeatedly removing nodes from the graph
and relabeling the arcs to preserve the language.
• Without loss of generality, we can assume one accepting state (because of the presence of the union operation).
cs466(Prasad) L14Equiv 12
Example
qj qk
qj
qi
qk
Wj,i
Wj,i Wi,k
Wi,k
cs466(Prasad) L14Equiv 13
qj qk
qj
qi
qk
Wj,i
Wj,i (Wi,i)* Wi,k
Wi,k
Wi,i
cs466(Prasad) L14Equiv 14
Final Graph : Alternative 1
u
L(M) = (u)*
cs466(Prasad) L14Equiv 15
Final Graph : Alternative 2
w
L(M) = (u)* v( w u (x (u)* v) )*
u
v
x
cs466(Prasad) L14Equiv 16
Detailed Example
b
a ba
ab
bq0 q1
q2 q3
cs466(Prasad) L14Equiv 17
Delete node q1
b
a ba
ab
bq0 q1
q2 q3
bbab
cs466(Prasad) L14Equiv 18
Delete node q2
b
aa
b u bb
q0
q2 q3
ab
ab*ab
cs466(Prasad) L14Equiv 19
Finally
ab u bb
q0
q3
ab*ab
(ab*ab)*a ((bubb) (ab*ab)*a)*
cs466(Prasad) L14Equiv 20
• For precise details, see Algorithm 6.2.2 on Page 194 in Sudkamp’s Languages and Machines, 3rd Edition.
cs466(Prasad) L14Equiv 21
From Regular Expression to NFA to DFA to Regular Grammars
Via Examples
cs466(Prasad) L14Equiv 22
Exercise
• Construct a DFA for a+b+
q0b
q1 q2a
a b
cs466(Prasad) L14Equiv 23
Equivalent DFA
{q0} {q1,q2}
{q0,q1}
{}
a
a
a
a,b
b
b
b
cs466(Prasad) L14Equiv 24
Two Equivalent (Right-linear) Regular Grammars
<q0> -> a <q0> | a <q1>
<q1> -> b <q1> | b <q2>
<q2> -> λ
<{q0}> -> a <{q0,q1}> <{q0,q1}> ->
a <{q0,q1}> | b <{q1,q2}>
<{q1,q2}> -> λ | b <{q1,q2}>
• All productions involving <{}> can be deleted, as <{}> does not derive any terminal strings.
cs466(Prasad) L14Equiv 25
Two Equivalent (Left-linear) Regular Grammars
<q0> -> λ
| <q0> a
<q1> -> <q1> b
| <q0> a
<q2> -> <q1> b
<{q0}> -> λ<{q0,q1}> ->
<{q0,q1}> a
| <{q0}> a
<{q1,q2}> ->
| <{q0,q1}> b
| <{q1,q2}> b
cs466(Prasad) L14Equiv 26
From Grammars to Finite Automata
S -> aA | c
A -> bB | bA
B -> λ
S -> aA | cF
A -> bB | bA
B -> λ
F -> λ
SA
BF
a b
b
c
cs466(Prasad) L14Equiv 27
From Grammars to Finite Automata
S -> aA | c
A -> bB | bA
B -> λ
S -> λ
A -> Sa | Ab
B -> Ab
F -> Sc
ZZ -> B | F
SA
BF
a b
b
c