COSC 341 Lecture 9 - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

COSC 341 Lecture 9

Description:

RE = the collection of all languages over represented by regular expressions ... More complex languages in RE are formed by union, concatenation, and Kleene star. ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 9
Provided by: MOL52
Category:
Tags: cosc | in | lecture | re

less

Transcript and Presenter's Notes

Title: COSC 341 Lecture 9


1
COSC 341Lecture 9
  • Let ? be an alphabet.
  • The following are equal - the languages
  • accepted by NFA-?s ( non-deterministic finite
    automata)
  • accepted by DFAs
  • represented by regular expressions
  • generated by regular grammars.
  • Let
  • RE the collection of all languages over ?
    represented by regular expressions
  • NFA the languages accepted by NFA-?s
  • RG the set of languages generated by regular
    grammars.
  • Stephen Cole Kleene proved that
  • RE NFA RG.

2
RE ? NFA
Claim if L is a language represented by a
regular expression, then there is some NFA-? that
accepts L. Justification The building blocks of
RE are ?, ?, and a for every a ? ?. Here are
NFA-?s to accept them
q0
q1
?
q0
q1
a
q0
q1
More complex languages in RE are formed by union,
concatenation, and Kleene star.
3
Example
An NFA-? for (a?b)
a
a
b
b
a
a?b
?
?
?
?
b
(a?b)
?
?
?
a
?
?
?
?
b
?
4
NFA ? RE
Claim If L is accepted by some NFA-?, then L is
represented by some regular expression. Justificat
ion An expression graph is like a state diagram
but it can have regular expressions as labels on
arcs. An NFA-? is an expression graph. An
expression graph can be reduced to one with just
two nodes (proof by induction). If we reduce an
NFA-? in this way, the arc label then corresponds
to the regular expression representing
it. Example
p
s
q
r
is shrunk to
prs
5
Other example
Find a regular expression for L accepted by
c
c
1
2
3
b
b
First get 2 graphs each with 1 accept
state G1 G2 Reducing G1 in two steps
gives with reg. exp. b, while from G2 we get
reg. exp. bccb.
c
c
1
2
3
b
b
c
c
1
2
3
b
b
1
b
cc
1
3
b
So full r.e. is b?(bccb).
b
6
Regular grammars
  • Recall that a regular grammar has rules of form
  • X ? aY, or
  • X ? a, or
  • X ? ?.
  • Easy to rewrite regular grammar so that has no
    rules of form X ? a. Just use new nonterminal A
    to replace X ? a by the pair of rules
  • X ? aA
  • A ? ?.
  • This is a bad idea if youre worried about
    ?-rules and CNF, but a good trick for proving
    that
  • RG NFA.
  • (See page 206 of the textbook.)

7
RG ? NFA
  • Let G be a regular grammar without X ? a rules.
    Build the NFA (Q, ?, ?, S, F)
  • Q the set of nonterminals of G
  • initial state is start symbol S
  • F set of non-terminals A with A ? ? in G
  • B ? ?(A,a) iff the rule A ? aB is in G.
  • Example
  • G S ? aS ? aA
  • A ? bA ? bB
  • B ? ?

a
b
S
A
B
a
b
Both accept the language ab.
8
NFA ? RG
Let M be any NFA. From M build regular grammar G
by taking Q as non-terminals, q0 as start symbol,
? as terminals. Whenever B ? ?(A,a), add the rule
A ? aB, and if A ? F, add A ? ?. Example
M
b
b
q0
q1
q2
a, b
G q0 ? aq0 ? bq0 ? bq1 q1 ? bq2 q2 ? ? The
language consists of all strings ending in bb,
with regular expression (a?b)bb.
Write a Comment
User Comments (0)
About PowerShow.com