Presentation is loading. Please wait.

Presentation is loading. Please wait.

FINITE-STATE AUTOMATA COP4620 – Programming Language Translators Dr. Manuel E. Bermudez.

Similar presentations


Presentation on theme: "FINITE-STATE AUTOMATA COP4620 – Programming Language Translators Dr. Manuel E. Bermudez."— Presentation transcript:

1 FINITE-STATE AUTOMATA COP4620 – Programming Language Translators Dr. Manuel E. Bermudez

2 TOPICS Define Finite-State Automata Non-Determinism Conversion from FSA to Right-Linear Grammar Conversion from Left-Linear Grammar to FSA (and back)

3 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 the (partial) transition function, s  Q is called the start state, and F ⊆ Q is the set of final states. An FSA is the formal accepting (parsing) mechanism of a regular language.

4 FINITE-STATE AUTOMATA FSA: ({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} FSA requires each transition labeled by a string of length < 1. S U R F aba ε b b a b a RX a XY b YU a

5 FINITE-STATE AUTOMATA TWO “SYMPTOMS” OF NON-DETERMINISM: NOTE: is not a problem. X a aX ε a 1.1. 2.2. F a

6 FINITE-STATE AUTOMATA Advantage of FSA’s: What language does this grammar generate? S → aAA → aBB → aC → ε → E → D C → bDD → bEE → bS Difficult to see. Try FSA. Answer: L*, where L={ab, aabb, aaabbb} F ε SA EDC B b ε b aa ε b a

7 FINITE-STATE AUTOMATA Conversion: FSA to 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 A → aBB → bBD → cE → a → bD → c E → F → bG → H H → A F → dG → ε A GF ε ε ba d H BDE b c ε Conclusion: Right- linear regular grammars and FSA’s are equivalent.

8 FINITE-STATE AUTOMATA Conversion between FSAs and Left-linear regular grammars F → SaU → SbR → Sb → Ub → RS → Ua → Raba → Sbb... F => Ub => Rb... Rabab... Sa => Uaa... a =>

9 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.Nonterminal appears on left-most position. 2.String generated right-to-left, versus left-to-right for right-linear grammars.

10 FINITE-STATE AUTOMATA Conversion: Left-linear regular grammar to FSA: 1. if A → B . 2. if A → , S’ is a new start state. 3.F = {S}, S is the start symbol. F → SaU → SbR → Sb → Ub → RS → Ua → Raba → BA α S’A α S U R F aba ε b b a b a S’ ε

11 FINITE-STATE AUTOMATA Is “babaaa” in the language ? StateInputDerivation S’babaaa babaaa SbabaaaSbabaaa <= R abaaa Rabaaa <= U aa Uaa <= S a Sa <= F S U R F aba ε b b a b a S’ ε

12 FINITE-STATE AUTOMATA Conversion: FSA to Left-linear regular grammar: 1.A → B  if 2.A →  if 3.S’ → F if Conclusion: Left-linear regular grammars and FSA’s are equivalent. BA α F New start symbol S α A

13 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 "FINITE-STATE AUTOMATA COP4620 – Programming Language Translators Dr. Manuel E. Bermudez."

Similar presentations


Ads by Google