Regular Languages - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Regular Languages

Description:

Rb aS. Regular Languages. Let's devise a machine that accepts L(G1). Observe that. S = a ... F = Ub = Rb ... Rabab ... Sa = Uaa ... a. Finite-State Automata ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 26
Provided by: manuelb9
Category:
Tags: languages | rb | regular

less

Transcript and Presenter's Notes

Title: Regular Languages


1
Regular Languages
Programming Language Concepts Lecture 4
  • Prepared by
  • Manuel E. Bermúdez, Ph.D.
  • Associate Professor
  • University of Florida

2
Regular Languages
  • We will study
  • Regular grammars
  • Relation to finite-state automata
  • Regular expressions
  • Equivalence among representations
  • Elimination on non-determinism
  • State minimization

3
Regular Languages
  • Definition A grammar G (F, S, P, S) is regular
    iff either (but not both)
  • Every production is of the form
  • A ? ?
  • or A ? ?B (right linear)
  • Every production is of the form
  • A ? ?
  • or A ? B? (left linear),
  • where ? ? S, and A, B ? F.

4
Regular Languages
  • Examples
  • G1 S ? a R ? abaU
  • ? bU ? U Regular? Why?
  • ? bR U ? b
  • ? S
  • G2 S ? a R ? Uaba
  • ? Ub U ? b Regular? Why?
  • ? Rb ? aS

5
Regular Languages
  • Lets devise a machine that accepts L(G1).
  • Observe that
  • S gt a
  • bU gt bb
  • bR bS
  • babaU
  • Every sentential form (except sentences) has
    exactly one nonterminal.
  • The nonterminal occurs in the right-most
    position.
  • Applicable productions depend only on that
    nonterminal.

gt
gt
gt
gt
gt
6
Regular Languages
  • Encode possible derivation sequences with a
    relation ? on pairs of the form (q, ?), where
  • q current state
  • ? remaining string to accept
  • So, S ? bU implies
  • (S, bß) ? (U, ß)

State sentential form ends in S
moves to
state sentential form ends in U
7
Regular Languages
  • Define a graph, one node per nonterminal,
    describing the possible actions on each
    sentential form. So,
  • S ? bU implies ,
  • R ? U implies ,
  • S ? a implies .

b
S
U
?
R
U
a
S
F
8
Regular Languages
  • Example S ? a R ? abaU U ? b
  • ? bU ? U ?aS
  • ? bR

S
b
a
R
b
e
a
F
aba
b
U
9
Regular Languages
  • In general,
  • Right-linear grammar ? Transition diagram
  • Nodes F ? f, f ? F
  • if A ? ? B
  • if A ? ?

a
A
B
a
A
F
S
10
Regular Languages
  • Example Is babaa in L(G)?
  • Node Input Derivation
  • S babaa S gt
  • U abaa bU gt
  • S baa baS gt
  • U aa babU gt
  • S a babaS gt
  • F babaa Yes.

11
Finite-State Automata
  • Definition A (non-deterministic) finite-state
    automaton is a 5-tuple M (Q, S, d, s, F), where
  • Q is a finite set of states,
  • S is a finite set of transition symbols,
  • d Q x S ? e ? 2Q is a partial function
    called the transition function,
  • s ? Q is called the start state, and
  • F ? Q is the set of final states.

12
Finite-State Automata
  • An FSA is the formal accepting mechanism of a
    regular language. It requires that each
    transition be labeled by a string of length lt 1.
  • The state diagram
  • is
    described by the FSA

S
b
a
R
b
e
a
F
aba
b
U
13
Finite-State Automata
  • (S, R, U, F, X, Y, a, b, d, S, F), where
  • d (S, a) F
  • d (S, b) U, R
  • d (R, e) U
  • d (R, a) X
  • d (U, a) S
  • d (U, b) F
  • d (X, b) Y
  • d (Y, a) U

a
R
X
b
X
Y
a
Y
U
14
Finite-State Automata
  • TWO SYMPTOMS OF NON-DETERMINISM
  • Note is not a problem

a
e
X
1.
2.
a
X
a
a
F
15
Finite-State Automata
  • Advantages of FSAs
  • Question What language does the following
    grammar generate?
  • S ? aA A ? aB B ? aC
  • ? e ? E ? D
  • C ? bD D ? bE E ? bS
  • Difficult to see. Try FSA.

16
Finite-State Automata
e
a
a
F
S
A
B
e
e
a
b
b
b
E
D
C
  • Answer L, where L ab, aabb, aaabbb
  • Summary FSAs are as powerful as right-linear
    regular grammars.
  • Are they more powerful? No. Can transform
  • FSA ? RGR.

17
Finite-State Automata
  • Transition Diagram (FSA) ? Right-linear regular
    grammar
  • F Q
  • A ? aB if B ? d (A, a)
  • A ? a if f ? d (A, a), and f ? F
  • Start symbol Start state

18
Finite-State Automata
  • Example
  • FSA
  • RGR A ? aB B ? bB D ? cE
  • ? a ? bD ? c
  • ? b
  • E ? F F ? dG G ? H
  • ? e
  • H ? A
  • Conclusion Right-linear regular grammars and
    FSAs are equivalent.

b
b
a
c
A
B
D
E
e
e
e
d
G
F
H
19
Finite-State Automata
  • Relationship between Left-linear regular grammars
    and FSAs
  • Example F ? Sa U ? Sb R ? Sb
  • ? Ub ? R S ? Ua
  • ? Raba ?
  • Derivations Sbb ...
  • F gt Ub gt Rb ...
  • Rabab ...
  • Sa gt Uaa ...
  • a

gt
gt
gt
gt
20
Finite-State Automata
  • Similarities with right-linear grammars
  • Sentential forms have at most one nonterminal.
  • Sentences have none.
  • Applicable productions depend only on the one
    nonterminal.
  • Differences with right-linear grammars
  • Nonterminals appears on left-most position.
  • String generated right-to-left, versus
  • left-to-right for right-linear grammars.

21
Finite-State Automata
  • Left-linear Regular Grammar ? FSA
  • if A ? B ?.
  • if A ? a, S is a new start state.
  • F S, S is the start symbol.

a
B
A
a
S
A
22
Finite-State Automata
  • Example
  • F ? Sa U ? SB S ? Ua
  • ? Ub ? R ? e
  • R ? Sb ? Raba

S
S
b
a
R
b
e
a
F
aba
b
U
23
Finite-State Automata
  • State Input Derivation
  • S babaaa babaaa
  • S babaaa Sbabaaa lt
  • R abaaa Rabaaa lt
  • U aa Uaa lt
  • S a Sa lt
  • F F

24
Finite-State Automata
  • FSA ? Left-linear Regular Grammar
  • A ? B? if
  • A ? ? if
  • S ? F if

a
B
A
a
S
A
F
New start symbol
25
Finite-State Automata
  • Summarizing
  • RGR RGL
  • RE FSA
  • Note Beware of attempts at diirect conversion
    between left and right-linear grammars.

Done
Soon
Write a Comment
User Comments (0)
About PowerShow.com