You are on page 1of 13
Chaptarii Regular expression, Regular Grammar and Regular Language Regular expression are used for representing certain sets of string in an algebraic fashion 1. Any terminal symbol belongs to the Y including A (empty) and 4 (null) are regular expression Example abe Ag 2-The union of two regular expression is also a regular expression Example: R1 and R2 two expressions then union represented as R=RI+R2 3. The concatenation of two regular expression is also a regular expression Example: RI and R2 two expressions then concatenation represented as R=RLR2 +The iteration (or closure) of regular expression is also a regular expressions Example: R>R* a*=A,a, aa, aga XK enc 00K a 5 The regular expression over 5 are precisely those obtained recursively by the application of ey the above rules once or several times, . . Regular expression examples Describe the following sets as Regular Expression 1)(0,1,2) Answers ItisO orl Or2 R=0+142 2) (A ab} 5){abb,a,b,bba) Answer: Itis abb ova orb or bba Reabbtatbebba 4) (A, 0, 00,000, Answor; Closure afd R=0* itis closure of the symbol with A S) (M111 } RI" tis a closure of the symbol without A IDENTITIES OF REGULAR EXPRESSION S.no IDENTITIES ! @#R=R g ORIRQ = @ 2 e*=eand Q*=e ha h R+R=R i R* ReRt RRR RR ARDENS'§ THEOREM IPP and Q are two regular Xpression o% cquations in R given by R=Q4RP hag Proof-1 R=QURP -. =Q+QP¥P Apply R=Qp* ver 3, and if P does not contain e, then the following @ unique solutions ic R-QP* =Q(e+P*P) (Take out Q) Apply e+R* R=R¢* R=QP* hence proved Proof-2 R=QeRP =Q+[QERP]P =Q+QP+RP? =Q4+-QP+(Q+RP)P* =QQP+QP*+RP? 2. (ab)e 3, a(be)* 4. (a/b)* (abb/a*b) 4.15 CONVERSION FROM F) TE AUTOMATA TO REGU XPRESSION OM FINI’ ‘A TO REGULAR EXPRESSI I= et q2b tq arnnnnnnnnne- aaa q2=qla- aeeonteneee2, 3b raed) q4=q2atq3b+qdatadb-———-4 ‘Take ql since it is final state and apply the value of q2 and q3 qi=etglabiqlba i, Take out qi since it is common : lhe Reqular Expression for the Following NPA a A b ee o> @ ) Be ‘ Z b %2 =A,> —— ree an ag a 2 4 2 £4424 %b — © a= At = Git + 40> +%4h) ~ g: Ge = Het taba tubs — &. 2 “ ( al Ans Aa 2 Aye t4rb tab fon ost ves) . + 28k =e 4H P42 BxReP es er = a an, Cb +4) aid S Mi ieee. Ly" ag, 2 AO ** b nS aeci ; te b aye) bah) Bee ivi ah by Gerace 2 2 PAS 5 R 5 2RIR ~ & Ce Chem) ) te 4 pa Cbtaby bY Vind the regular expression for the following DFA A) BE () Oro = Any 4%) —@ fey 78 OE ee Rint dale & pres tO 5 Raa the ay a 2 of" 3D erak : 1+00*1)(0- REGULAR GRAMMAR ‘Noam Chomsky gave a mathematical model of Srammar Which is effective for writing computer language, Gronmar A grammar G ean be formally written as a 4-tuple (N, 1, S, P) where - + Nor Vyis a set of variables or non-terminal symbols, + Tor), is asset of Terminal symbols, + Sisa special variable called the Start symbol, S € N + Pis Production rules for Terminals and Non-terminals, A production rule has the form a — f, where a and f are strings on Vy U ¥: and least one symbol of a belongs to Vy. Example Grammar G1 -({S, A, B}, {a, b}, 8, {S > AB, A a, B— b)) Here, + §,A, and B are Non-terminal symbols; + aand b are Terminal symbols « Sis the Start symbol, S EN + Productions, P: $—> AB, Aa, Bb ‘Example Grammar G2-(({S, A}, {8,6}, S,(S— Abad aah, Ae }) ‘hepa gular grammar can be divided into two types 1.Right linear grammar A grammar is said to be right linear if all production are of the form ADxB AM ‘Where A,B e V and xe. 2.Left Linear grammar. A grammar is said to be left linear if all production are of the form ADBx ADx Where A,B e Vand xe T Example S>abS/b—---- Right linear S>Sbb/b —------Left Linear, REGULAR LANGUAGE : ‘A language is said to be a regular language if and only if some finite state machine recognizes it. ‘So what languages are not regular? ‘The languages ei © Which are not recognized by the Finite State Machine © Which requirememory Memory of Finite State Machine is very limited Tt-cannot store or count strings Pumming lemma Bumming lemma is used to prove that a language is not regular Tt cannot be used to prove that a language is regular If Ais a regular language,then A has a pumming length ‘P* a such that any string ‘S’ where ISPP may be divided into 3parts s=zyz such that the followi ing conditions must be true 1, xy'z belongs to A for every 1>0 2. lyPo 3. kxyisP To prove that a language is not regular using pumming lemma, follow the below steps (We prove using contradiction) Assume that A is regular Ithas to have a pumming length (Say p) All strings longer that P can be pumbed |S|2P Now find a string ‘S’ in A that |S[>P Divide $ into xyz Show that xy'z not belongs A for some i Then consider all ways that S can be divided into xyz, Show that none of these can satisfy all the 3 pumming condition at the same time S cannot be pumped=CONTRADICTION eer per am Example Using pumming lemma prove that the language A= {a'b*|n20) is not regular Proof L Assume A is regular 2.pumming length =p si py ‘S-asaaaaabbbbbbb Case 1 ‘The Y is in the a part angaaaabbbbbbb. ISN ec see The ¥ Is ti the b part aaaanaab ebb Ry) = Caup 3 ‘The Y is in the a and b part ‘aaanonabbbbbbb K eres eo First condition Caso1 xyeeny'e ‘auanacanaaabbbbbbb Here number a (11) is not equal to number b (7) Case 2 aaaadaabbbbbbbbbbb ~ Here number a (7) is not equal to number b (11), Case3 aaaaagabbaabbbbbbb It does not follow the pattern of a"b" Second Condition Alll three cases satisfied the second conditions ‘Third Condition:

You might also like