Download presentation
Presentation is loading. Please wait.
1
Language Recognition MSU CSE 260
2
Outline Introduction Regular Expressions & Regular Sets
Kleene’s Theorem Regular Sets and Regular Grammars Examples More powerful Types of Machines Exercise 10.4
3
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
4
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
5
Regular Sets Each regular expression represents a (regular) set.
Reg. Exp. Set represented the empty set the set {} x the 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
6
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.
7
NFAs for Basic Regular Sets
recognizes Start s0 recognizes {} Start s0 The NFA is easier to build and understand than the equivalent FA. a recognizes {a} Start s0 s1
8
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 The NFA is easier to build and understand than the equivalent FA. 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 sB are final. Final states of MAB include all final states of MB.
9
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 The NFA is easier to build and understand than the equivalent FA. i sB i Start state of MAB is sAB, which is final if sA or sB is final. Final states of MAB are the final states of MA and MB.
10
NFA for Kleene Closure Let A be recognized by MA=(SA, I, fA, sA, FA).
Start i MA* sA* sA i The NFA is easier to build and understand than the equivalent FA. 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.
11
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 .
12
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 sF
13
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 to each input symbol in I; Start symbol S corresponds to start state s0. Productions are formed from the transitions: A transition from s to t on input a produces As aAt A transition from s to a final state on input a produces As a P also includes production S if L(M).
14
Example Let NFA M=(S, I, f, s0, F), where:
S={s0, s1, s2}, I={0,1}, F={s0, s2}, and state diagram: s1 Start s0 1 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
15
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.
16
Exercise 10.4
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.