Presentation is loading. Please wait.

Presentation is loading. Please wait.

Finite-state automata

Similar presentations


Presentation on theme: "Finite-state automata"— Presentation transcript:

1 Finite-state automata
Module 04.2 COP4020 – Programming Language Concepts 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 Σ ∪ {ε} → 2Q 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
R F aba ε b a 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. R X a X Y b Y U a

5 Finite-state automata
TWO “SYMPTOMS” OF NON-DETERMINISM: NOTE: is not a problem. X a ε 1. 2. F a

6 Finite-state automata
Advantage of FSA’s: What language does this grammar generate? S → aA A → aB B → aC → ε → E → D C → bD D → bE E → bS Difficult to see. Try FSA. Answer: L*, where L={ab, aabb, aaabbb} F ε S A E D C B b a

7 Finite-state automata
Conversion: FSA to Right-linear regular grammar Φ = Q A → aB if B  δ (A, a) A → a if f  δ (A, a), and f  F Start symbol = Start state A → aB B → bB D → cE → a → bD → c E → F → b G → H H → A F → dG → ε Conclusion: Right- linear regular grammars and FSA’s are equivalent A G F ε b a d H B D E c

8 Finite-state automata
Conversion between FSAs and Left-linear regular grammars F → Sa U → Sb R → Sb → Ub → R S → Ua → Raba → Sbb ... F => Ub => Rb ... Rabab ... Sa => Uaa ... a => => => =>

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

10 Finite-state automata
Conversion: Left-linear regular grammar to FSA: if A → B. if A → , S’ is a new start state. F = {S}, S is the start symbol. F → Sa U → Sb R → Sb → Ub → R S → Ua → Raba → B A α S’ A α S U R F aba ε b a S’

11 Finite-state automata
R F aba ε b a S’ Is “babaaa” in the language ? State Input Derivation S’ babaaa babaaa <= S babaaa Sbabaaa <= R abaaa Rabaaa <= U aa Uaa <= S a Sa <= F F F → Sa → Ub U → Sb → R → Raba R → Sb S → Ua

12 Finite-state automata
Conversion: FSA to Left-linear regular grammar: A → B if A →  if S’ → F if Conclusion: Left-linear regular grammars and FSA’s are equivalent. B A α S α A F New start symbol

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


Download ppt "Finite-state automata"

Similar presentations


Ads by Google