Create Presentation
Download Presentation

Download Presentation
## Language Recognition

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Language Recognition**MSU CSE 260**Outline**• Introduction • Regular Expressions & Regular Sets • Kleene’s Theorem • Regular Sets and Regular Grammars • Examples • More powerful Types of Machines • Exercise 10.4**Introduction**• The sets (languages) recognized by FAs are those formed from: • null (empty) set , • empty string (), and • singleton strings by taking (in arbitrary order): • concatenations, • unions, • Kleene Closures. • Regular languages**Regular Expressions**• Definition. The regular expressions over a set I are defined recursively by: • the symbol is a regular expression; • the symbol is a regular expression; • the symbol x is a regular expression whenever x I. • the symbols (AB), (AB), and A* are regular expressions whenever A and B are regular expressions. Examples. The following are regular expressions over I={0,1}: 10*, (10)*, 001, 0(01)*, (0*1)* Note.AB is sometimes represented as A+B. Precedence rules: Kleene closure(*), concatenation, union**Regular Sets**• Each regular expression represents a (regular) set. Reg. Exp.Set represented the empty set the set {} xthe set {x} (AB) the concatenation of the sets represented by A and by B (AB) the union of the sets represented by A and by B A* the Kleene closure of the set represented by A Examples.10*: strings consisting of a 1 followed by any number of 0s (10)*: any arbitrary combinations of string 10 (including ) 0 01: the set consisting of the two strings 0 and 01 0(0 1)*: the set of strings which begin with 0**Kleene’s Theorem**• Kleene’s Theorem. A set is regular if and only if it is recognized by a finite-state automaton. Proof. The proof is done by construction of NFAs for sets represented by regular expressions.**NFAs for Basic Regular Sets**recognizes Start s0 recognizes {} Start s0 a recognizes {a} Start s0 s1**NFA for Concatenation**• Let A be recognized by MA=(SA, I, fA, sA, FA), and B recognized by MB=(SB, I, fB, sB, FB) MAB f MA MB Start f i sA sB i • A transition to final state in MA produces a transition to sB. • A transition from sB in MB produces a transition from sAB=sA if sA is a final state. • Start state of MAB is sAB=sA, which is final if both sA and sBare final. • Final states of MAB include all final states of MB.**NFA for Union**• Let A be recognized by MA=(SA, I, fA, sA, FA), and B recognized by MB=(SB, I, fB, sB, FB) i MA i sA MAB Start sAB MB i sB i • Start state of MAB issAB, which is final if sA or sBis final. • Final states of MAB are the final states of MA and MB.**NFA for Kleene Closure**• Let A be recognized by MA=(SA, I, fA, sA, FA). i MA Start i MA* sA* sA i • Transitions from sA produce transitions from sA* and all final states of MA. • Start state of MA* is sA*, which is a final state. • Final states of MA* include all final states of MA.**NFA for a Set Generated by a Regular Grammar**• Theorem. A set generated by a regular grammar is regular. Let G = (V, T, S, P) be a regular grammar. Then the corresponding NFA is M = (S, I, f, s0, F): • S contains a state sA for each nonterminal symbol A of G, and an additional (final) state sF. • Start state is s0 = sS. • Transitions are formed from the productions: • A aB produces a transition from sA to sB on input a • A a produces a transition from sA to sF on input a • F also includes s0 if P includes production S .**Example**• Let G=(V,T,S,P) where V={0,1,A,S}, T={0,1}, and the productions in P are: • S1A, S0, S, A0A, A1A, A1 • The corresponding NFA is M=(S, I, f, s0, F): • S={sS, sA, sF}, s0=sS, F={sF}, I={0,1}, and state diagram 0,1 1 sA Start sS 1 0 sF**Regular Grammar Generating a Regular Set**• Theorem. If a set is regular, then there is a regular grammar that generates it. Let M = (S, I, f, s0, F) be the NFA recognizing this set. Then the regular grammar generating it is G = (V, T, S, P): • Assign a nonterminal symbol As to each state s of S; • Assign a terminal symbol toeach input symbol in I; • Start symbol S corresponds to start state s0. • Productions are formed from the transitions: • A transition from sto t on input aproduces As aAt • A transition from sto a final stateon input aproduces As a • P also includes production S if L(M).**Example**• Let NFA M=(S, I, f, s0, F), where: S={s0, s1, s2}, I={0,1}, F={s0, s2}, and state diagram: 0 0 s1 Start s0 1 0 1 1 s2 • The corresponding regular grammar G=(V,T,S,P) • V={S=A0, A1, A2, 0, 1}, T={0, 1}, and productions in P: • S0A1, S1A2, A10A1, A11A2, A20A1, • A21A2, A11, A21, S1, S**More powerful Types of Machines**The set {0n1n | n = 0, 1, 2, …} is not regular; has no FA. The limitation of FAs is their finite memory. More powerful models of computation: • Pushdown automata • Include all FA’s features, plus a stack for unlimited memory. • Recognize languages generated by context-free grammars. • Example: {0n1n | n=0, 1, 2, …} • Linear bounded automata • Context-sensitive languages. Example: {0n1n2n | n = 0, 1, 2,…} • Turing machines • Include FA’s features and a tape (infinite in both directions) for read and write. ►All languages generated by grammars.