Presentation is loading. Please wait.

Presentation is loading. Please wait.

Regular Languages Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Translators.

Similar presentations


Presentation on theme: "Regular Languages Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Translators."— Presentation transcript:

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

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 = (Φ, Σ, 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  Φ.

4 Regular Languages Examples: G1: S → a R → abaU → bU → U Regular? Why? → bRU → b → S G2: S → aR → Uaba → UbU → b Regular? Why? → Rb → aS

5 Regular Languages Let’s devise a machine that accepts L(G1). Observe that S => a bU => bb … bR bS … babaU 1.Every sentential form (except sentences) has exactly one nonterminal. 2.The nonterminal occurs in the right-most position. 3.Applicable productions depend only on that nonterminal. =>

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. SU RU SF b  a

8 Regular Languages Example: S → a R → abaUU → b → bU → U → aS → bR S U R F aba ε b b a b a

9 Regular Languages In general, Right-linear grammar → Transition diagram: 1.Nodes: Φ  {f}, f  Φ 2.if A →  B 3. if A →  4. AB S AF α α

10 Regular Languages Example: Is “babaa” in L(G)? NodeInputDerivation SbabaaS => U abaabU => S baabaS => U aababU => S ababaS => Fbabaa Yes.

11 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 transition symbols, δ: Q x Σ  {ε} → 2 Q 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 < 1. The state diagram is described by the FSA S U R F aba ε b b a b a

13 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} RX XY YU a b a

14 Finite-State Automata TWO “SYMPTOMS” OF NON-DETERMINISM: Note:is not a problem F a X a a X ε a 1. 2.

15 Finite-State Automata Advantages of FSA’s: Question: What language does the following grammar generate? S → aAA → aBB → aC → ε → E → D C → bDD → bEE → bS Difficult to see. Try FSA.

16 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 → RG R. F ε SA EDC B b ε b aa ε b a

17 Finite-State Automata Transition Diagram (FSA) → Right-linear regular grammar 1.Φ = Q 2.A → aBif B  δ (A, a) 3.A → aif f  δ (A, a), and f  F 4.Start symbol = Start state

18 Finite-State Automata Example: FSA: RGR:A → aBB → bBD → cE → a → bD → c → b E → FF → dGG → H → ε H → A Conclusion: Right-linear regular grammars and FSA’s are equivalent. A GF ε ε ba d H BDE b c ε

19 Finite-State Automata Relationship between Left-linear regular grammars and FSA’s: Example:F → SaU → SbR → Sb → Ub → RS → Ua → Raba → Derivations: Sbb... F => Ub => Rb... Rabab... Sa => Uaa... a =>

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

21 Finite-State Automata Left-linear Regular Grammar → FSA 1. if A → B . 2. if A → , S’ is a new start state. 3.F = {S}, S is the start symbol. BA S’A α α

22 Finite-State Automata Example: F → SaU → SBS → Ua → Ub → R → ε R → Sb → Raba S U R F aba ε b b a b a S’ ε

23 Finite-State Automata StateInputDerivation S’babaaa babaaa SbabaaaSbabaaa <= R abaaa Rabaaa <= U aa Uaa <= S a Sa <= F

24 Finite-State Automata FSA → Left-linear Regular Grammar: 1.A → B  if 2.A →  if 3.S’ → F if BA SA α α F New start symbol

25 Finite-State Automata Summarizing: RG R RG L REFSA Note: Beware of attempts at direct conversion between left and right-linear grammars. Done Soon


Download ppt "Regular Languages Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Translators."

Similar presentations


Ads by Google