1 / 25

Regular Languages

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

Download Presentation

Regular Languages

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Regular Languages Programming Language Translators 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 = (Φ, Σ, 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? → bR U → b → S G2: S → a R → Uaba → Ub U → 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 • Every sentential form (except sentences) has exactly one nonterminal. • The nonterminal occurs in the right-most position. • 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 . 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 ε a F aba b U

  9. Regular Languages In general, Right-linear grammar → Transition diagram: • Nodes: Φ  {f}, f  Φ • if A → B • if A →  α A B α A F S

  10. 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.

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

  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 b a R b a ε F aba b U

  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} a R X b X Y a Y U

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

  15. 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.

  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 → RGR. a a F S A B ε ε a b b b E D C

  17. 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

  18. 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

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

  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 → , S’ is a new start state. • F = {S}, S is the start symbol. α B A α S’ A

  22. 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

  23. Finite-State Automata State Input Derivation S’ babaaa babaaa S babaaa Sbabaaa <= R abaaa Rabaaa <= U aa Uaa <= S a Sa <= F F

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

  25. Finite-State Automata Summarizing: RGR RGL RE FSA Note: Beware of attempts at direct conversion between left and right-linear grammars. Done Soon

More Related