Automata 4

You might also like

Download as pdf
Download as pdf
You are on page 1of 5
REGULAR GRAMMARS ee ‘After going through this chapter, you should be able to understand : 4s Regular earmmar 1 amatence oeween Keguar Grammar ana FA, 1 nterconversion 44 REGULAR GRAMMAR. Definition : The grammar G=(V,T,,$) issaid tobe regular grammer if the grammaris rightlincaror lef near A gramma Gis said tobe right linear fall the productions are ofthe form AWB and/or Aw where 4, 2 eV and ye 7" ‘Agaammar Gs said to be lef linear fall the productions are of te form A-pBw and/or AoW where 4, BEV and y cr". Example 1: ‘Thegammar S > mB | BA © A > aAlb Boo bBlale ‘saright linear grammar. Notethat¢ and string of terminals cn appear on RHS ofa production and ifnon -temninal is present on R.H. Sof any production, only one non -terminal should be present and it hasto be the right most symbol oa R. HLS. Example 2: ‘The grammar S > Baa] Abb | A Aalb Bo Bblalc ‘saleft linear gram. Note that and string of erminals can appear on RHS of any production ‘and ifnon -temminal is present on LH. Sof any production, only one non- terminal should be present and ithasto bethe let mostsymbol on. HS. FORMAL LANGUAGES AND AUTOMATA THEORY Example 3: ‘Consider the grammar so aA A + Bib Boo Abla Inthis grammar, each productions either left inear or ight linear. Bus te grammar isnatither Jeftlinear aright linear Such type of grammar scalled linear grammaz So, a grarnmar which bas ‘atmos one non terminal onthe right side of any production withoutrestiction onthe postion of ‘this non - terminal (note the non - terminal ean be leftmost or right most) sealed linear omina, "Note thatthe language generated from the regular grammars called regular language. So, there shoald be some relation between the regular grammar andthe FA, since the language accepted by PAisalso regular language. So, we can constructa finite automaton givenaregula gramanst, 42 FAFROM REGULAR GRAMMAR ‘Theorem : Let = (V,7,P.S)be a rightlinesr grammar. Then there exists language L(G) which is aoceptod by FA. ie, the language generated from the regular grammar {is regular language. Proof :Let ¥ =(gs, gi) bethe variables and the start stato $= q, Letthe productions in the grammarbe > a> 5a 4 > Hm 467 le “Assume that the language L(G) generated fom these productions is w. Corresponding to each ‘production nthe grammar we canhave a equivalent transitions inthe FA to accept the string w. ‘After aceepting the string w, the FA will be in the final state. The procedure to obtain FA from these productions is given below: FORMAL LANGUAGES AND AUTOMATA THEORY ‘Stop 1: g, whichis the start symbol inthe grammars the start state of FA. Step 2: Forcach production of the form a >, the corresponding transition defined will be Sawa) ‘Step 3: Foreach production ofthe form g, + the conesponding transition defined willbe 6 (g, w) =< swhere 4, isthe fina stat, ‘Ao the string w © £(G) ia also accepted by FA, by applying the ttaustions vblained fou stepl through step, the language i regula. So, the theorems proved. Example 1. cunseusta orate accept ne language generated oy me ttowng grammar sa ou A> 108 Bo» oAlll Solution : [Note that foreach production of the form As wR, the enreespanding tancitian will he (4, ») = B. Also, foreach production -» w, we can introduce th transition 8(4.") =4, ‘where q isthe inal state. The transitions obtained from grammar Gis shown using the following table: Productions ‘Trastions ss: tS, ON =4 > 84, 10)=B ‘The FA corresponding to the transitions obtained is shown below FORMAL LANGUAGES AND AUTOMATA THEORY M=(Q,, 8,44.) where Q=(S,A.B, 4.90 Gs) » B= (0) y=5 5 date) 8 isa obtained from the above table. ‘The additional vertices introduced ae 4,454 45+ ‘Examplo 2: Construct a DFAtoaoceptthe language generated bythe fowing orommar. re A 3 aAbBl« 5 > bBle Solution : Note thet for each production ofthe form 4» wit, the corresponding transition will be {84yn)~ D-Also foreach production > w We canintroduce the transition 8(4,¥) = 4 ‘where ¢ ithe final state, The transitions obtained ffom grammar Gis shown usingthe following table Productions Transitions SistheFinal tate 8(4,a)= 4 BAD=B, Aste inal sate 30.) =2 isthe final ae, FORMAL LANGUAGES AND AUTOMATA THEORY Note : Forcach transition ofthe form 4-y<,makeAasthe final state, ‘The FA corresponding to the transitions obtained is shown below 4.3 So, the DFA Mf =(0,3, 8, gy, A) Where Q={S, 4B) ,2=(a,b) 2S, AR=(S, AB) ‘is as obtained from the above table. 4.3 REGULAR GRAMMAR FROM FA Theorem : Let IF =(0,2,5,49,4) bea friteaulomaton.ILiethe regular language accepted by FA then there exist aright near grammar G = (VT, P, $0 that L= L(G). Proof : Let if =(0,2,6,a9,4) bea finite automata aecepting L where O= (441-6) E={ay2emdy) ‘Aregular grammarG=(V,T,P,S )eanbe constructed where Pa bgedirnted S=a ‘The productions P from the transitions canbe obtined as shovm below: ‘Step 4: Forcach transition ofthe form 8(@,,@)=4, the corresponding production defined willbe 4, > ag, ‘Stop 2: fq €4 i.e, ifqisthe inl state in FA, then introduce the production qe Asthese productions ar obtained from the transitions defined for PA, the language accepted by FAs also accepted by the grammar, FORMAL LANGUAGES AND AUTOMATA THEORY

You might also like