regular languages l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Regular Languages PowerPoint Presentation
Download Presentation
Regular Languages

Loading in 2 Seconds...

play fullscreen
1 / 25

Regular Languages - PowerPoint PPT Presentation


  • 255 Views
  • Uploaded on

Regular Languages. Programming Language Translators. Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida. Regular Languages. We will study: Regular grammars Relation to finite-state automata Regular expressions Equivalence among representations

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Regular Languages' - daniel_millan


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
regular languages

Regular Languages

Programming Language Translators

Prepared by

Manuel E. Bermúdez, Ph.D.

Associate Professor

University of Florida

regular languages2
Regular Languages

We will study:

  • Regular grammars
  • Relation to finite-state automata
  • Regular expressions
  • Equivalence among representations
  • Elimination on non-determinism
  • State minimization
regular languages3
Regular Languages

Definition: A grammar G = (Φ, Σ, 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  Σ*, and A, B  Φ.

regular languages4
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

regular languages5
Regular Languages

Let’s devise a machine that accepts L(G1).

Observe that

S => a

bU => 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.

=>

=>

=>

=>

=>

regular languages6
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”

regular languages7
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

regular languages8
Regular Languages

Example: S → a R → abaU U → b

→ bU → U →aS

→ bR

S

b

a

R

b

ε

a

F

aba

b

U

regular languages9
Regular Languages

In general,

Right-linear grammar → Transition diagram:

  • Nodes: Φ  {f}, f  Φ
  • if A → B
  • if A → 

α

A

B

α

A

F

S

regular languages10
Regular Languages

Example: Is “babaa” in L(G)?

Node Input Derivation

S babaa S =>

U abaa bU =>

S baa baS =>

U aa babU =>

S a babaS =>

F babaa Yes.

finite state automata
Finite-State Automata

Definition: A (non-deterministic) finite-state automaton is a 5-tuple M = (Q, Σ, δ, s, F), where

Q is a finite set of states,

Σ is a finite set of transitionsymbols,

δ: Q x Σ  {ε} → 2Q is a partial function called the transitionfunction,

s  Q is called the startstate, and

F  Q is the set of finalstates.

finite state automata12
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 < 1.

The state diagram

is described by the FSA

S

b

a

R

b

a

ε

F

aba

b

U

finite state automata13
Finite-State Automata

({S, R, U, F, X, Y}, {a, b}, δ, S, {F}), where

δ (S, a) = {F}

δ (S, b) = {U, R}

δ (R, ε) = {U}

δ (R, a) = {X}

δ (U, a) = {S}

δ (U, b) = {F}

δ (X, b) = {Y}

δ (Y, a) = {U}

a

R

X

b

X

Y

a

Y

U

finite state automata14
Finite-State Automata

TWO“SYMPTOMS”OFNON-DETERMINISM:

Note: is not a problem

a

ε

1.

X

2.

a

X

a

a

F

finite state automata15
Finite-State Automata

Advantages of FSA’s:

Question: What language does the following grammar generate?

S → aA A → aB B → aC

→ ε → E → D

C → bD D → bE E → bS

Difficult to see. Try FSA.

finite state automata16
Finite-State Automata

ε

Answer: L*, where L = {ab, aabb, aaabbb}

Summary: FSA’s are as powerful as right-linear regular grammars.

Are they more powerful? No. Can transform

FSA → RGR.

a

a

F

S

A

B

ε

ε

a

b

b

b

E

D

C

finite state automata17
Finite-State Automata

Transition Diagram (FSA) → Right-linear regular grammar

  • Φ = Q
  • A → aB if B  δ (A, a)
  • A → a if f  δ (A, a), and f  F
  • Start symbol = Start state
finite state automata18
Finite-State Automata

b

a

b

c

Example:

FSA:

RGR: A → aB B → bB D → cE

→ a → bD → c

→ b

E → F F → dG G → H

→ ε

H → A

Conclusion: Right-linear regular grammars and FSA’s areequivalent.

A

B

D

E

ε

ε

ε

d

H

G

F

finite state automata19
Finite-State Automata

Relationship between Left-linear regular grammars and FSA’s:

Example: F → Sa U → Sb R → Sb

→ Ub → R S → Ua

→ Raba →

Derivations: Sbb ...

F => Ub => Rb ...

Rabab ...

Sa => Uaa ...

a

=>

=>

=>

=>

finite state automata20
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.

finite state automata21
Finite-State Automata

Left-linear Regular Grammar → FSA

  • if A → B.
  • if A → , S’ is a new start state.
  • F = {S}, S is the start symbol.

α

B

A

α

S’

A

finite state automata22
Finite-State Automata

Example:

F → Sa U → SB S → Ua

→ Ub → R → ε

R → Sb → Raba

S’

ε

S

b

a

R

b

a

ε

F

aba

b

U

finite state automata23
Finite-State Automata

State Input Derivation

S’ babaaa babaaa

S babaaa Sbabaaa <=

R abaaa Rabaaa <=

U aa Uaa <=

S a Sa <=

F F

finite state automata24
Finite-State Automata

FSA → Left-linear Regular Grammar:

  • A → B if
  • A →  if
  • S’ → F if

α

B

A

α

S

A

F

New start symbol

finite state automata25
Finite-State Automata

Summarizing:

RGR RGL

RE FSA

Note: Beware of attempts at direct conversion between left and right-linear grammars.

Done

Soon