Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
1K views
90 pages
TOC Unit 3 (CFG) Context Free Grammar
Theory Of Computation
Uploaded by
projectdemo969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save TOC Unit 3 (CFG) Context Free Grammar For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
1K views
90 pages
TOC Unit 3 (CFG) Context Free Grammar
Theory Of Computation
Uploaded by
projectdemo969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save TOC Unit 3 (CFG) Context Free Grammar For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save TOC Unit 3 (CFG) Context Free Grammar For Later
You are on page 1
/ 90
Search
Fullscreen
Context Free Grammar (CFG) and Languages (4) Structure Grammar, Context Free Grammar, Context Free tanguages(CFL), Production Rules, Formalization, Derivation and. Derivation Trees, Ambiguous Grammar, Removal of Ambiguity and Inherent Ambiguity, implification of Grammar-Removal of Unit Production, Useless Production, useless Symbol, and Production; Normal Forms(Chomsky Normal Form and Greibach Normal Form),Chomsky Hierarchy, an Exam) le to Explain Grammar : ‘We have seen that every finite automata M accepts a language L, which is represented wyL Oo. “We have seen that a regular language can be described by a regular expression, ‘We have seen that there are several languages which are not regular. L1=(a"| pis a prime) is not regular. Pe) = (a'b"|n20) isnot regular, L3=(a" [12 1) is mor regular, L4=(ww|we (a, b)*) is not regular. | we (a,b)*) is not regular, We have seen two ways for representing a language ; 1, Using finite automata.Tid a” I Y 42 Context Free Gramma hil ot PU-IT) HCE) ay 1 * Grammar is another approach for representing a language. iia | 1. In this approach, a language is represented using a set of equation, t 2. Equations are recursive in nature. a i 3. A finite automata asa ‘Set’ of states: context free erimma, - i Variables, a, 4. Finite automata defined over am alphabl. Silay, «grammes, ‘ wsetof terminals. fing i | 5. A finite automata has a set of transitions; a grammar has 4 eh (productions), Table 4.1.1: A set of DEA represented using an equivalent set of procinctog, Sr. DFA Equivalent (Noc}unniants | oor ue. uel /grammar I «)— X>a oat X aX a= Xb 3 Xax * The production X — a should read as GMGEG Teac + ©The production x! S'aX ia tay Of definiig 4’string containing one or Tore a's If X stands for a set ee a tea ee aS then a can be terms of X. The concept is shown below in Fig. 4.1 ae Aahogan ‘peg my easy A string of 6ia’scan be generated by X A string of 5 a’ mens byX, sl aaaaaa od x aohinge lisse gna AA & yoann binge et tom ewe # playyrne 2eguugta| tou golinsrenga wit band 6 emi axel sonst 2014-3 Context Free Grammar (CFG) and ‘Fig. 4.1.2: DFA taken as an example he language of the DFA is ee below = (€,a, aa, aaa, .....) jet vs eee _ wan given below and see if it can generate the language FA of Fig, bythe D X > aX (4-1) Xe ; (4-2) ae an be generated by the production X > €_ 1% % polwabeng sf ¥ a fee Ketersiedar shay iaig 414. neitsubeng ,X as aX, secondly by replacing X on RHS with ax and findlly replacing” Hpdsialdssibany wit ‘a nikon m stevaeeg on est pt XasaX—e nsgeggenxewn 9 AY Kaateascommu 4 x1) \ wanton
aXb i.e. If we have a string of the form a’b", after removing the first a ang é string remains in the form a’ b’. \ ‘Thus the language. © Lex (aot]n21) can be represented using X — aXb X = ab L 2 The production X — aXb can recursively generate a string a°b* ang é 4 X > ab is used for termination of recursion, Let us try to generate a string a’b” using the two productions (4-3) and (64) x © 3 Wing X08 ax x wating Xas axb . et 'b Writing Xas.ab ‘Fig. 415 : Generation of2°b? icom tation (PUTT) 45 Contoxt Free Grammar (CFG) and Languages. a2 f m context free grammar G is a quadruple (V, T, P, S), ‘vy is.a sevof variables, ‘ris asct of terminals. pisa set of productions. gis a special variable called the start symbol $e V. ‘a production is of the form wy, 966 where Vie V and cy is a string of terminals and variables, \ Notations : terminals are denoted by lower case letters a, b,c... or digits 0, 1, 2 -... etc. Non-terminals (variables) are denoted by capital letters A, B, ..., V,W, X ... string of terminals ora word w € L is represented using u,v, w, x,y. 2. ‘Assentential form is a string of terminals and variables and it is denoted by «, B, y etc. é xplained through an example : totus consider English sentences of the form ; 1, Mohan eats, 2. Soham plays. 3, Ram reads, ‘the first word of in the above sentences is a noun and the second word is a verb. A sf the above form can be written as sae ~
—
‘Here, noun can be replaced with Mohan, Soham or Ram and
can be replaced vith reads, plays or cats, ‘We can write ; ;
—> Mohan
—> Soham
—> Ram he ‘
— cals
—9 plays
—> reads Inthe above example :
,
and
are variables or non-terminals. Mohan, Soham, Ram, eats, plays and reads are terminals. ‘The variable:
is the start symbol as a sentence will be formed using the ‘start symbol
, a & eps47__ Context Free Grammar (CFG) and. tial Form sider grammar given below: 5 > AIB (Production 4-5) A OA (Production 4-6) p > OBJIB|€ (Production 4-7) Gis givenby (TP, ) wher) = (5, A,B) with pe (0,1) p = (Productions 4-5, 4-6 and 4.7) g = Start symbol to generate the string 00101 from the given grammar. 5 > AIB [Starting production) = OAIB. [Using the production A > 0A] = OOAIB [Using the production A > 0A] — 001B [Using the production A — e] — 0010B [Using the production B + 0B] 9 00101B [Using the production B > 1B] — 00101 [Using the production B ->'€] string 00101 € L(G). form, derivation starts from the start symbol through a finite application of ived so far consists of terminals and non-terminals. s 2 alae (VUT)* g consists of terminals. ntial form, leftmost symbol is picked up for expansion. {ential form, rightmost symbol is picked up for expansion. be derived in many ways. But we restrict ourselves to : \ mpof tion (PU-IT) 4-8 Context Ftee Grammar (Cre, San Example 4.2.1; For the grammar given below S>AIB A>0Ale B= 0B| 1B/e Give leftmost and rightmost derivation of the string 199), Solution : (@—Leftmost derivation of 1001 (Leftmost variable is picked up for expansion (SS AB. [Derivation stars from the start symboi} = ip [Using the production A > e] , = 10B [Using the production B > OB} = 100B [Using the production B > 0B) > 10018 [Using the production B > 1B] = 1001; E \/ (Using the production B > e} (i) Rightmost derivation of 1001 (Rightmost variable is picked up for expansion S > AIB {Derivation starts from the start symbol} — A10B [Using the production B — 0B) > A100B~ [Using the production B — 0B] > A1001B [Using the production B — 1B} — A1001 [Using the production B — e] > Ooi F: _ [Using the production A + e] 4.2.22 Parse Tree : 7 A set of derivations applied to generate a word can be represented using a tree, 5,, tree is known as a parse tres. A parse tree representation gives us a better understacig 4 1. Recursion 2, Grouping of symbols ; A parse tree is constructed with the following condition : Root. eres sepresented by sar symbol. ay eee tree is seen from left to right. a Example 4.2.2: For the grammar given below wi peasy ab SS9 ALB) an Wi, Alderbe bueret wil_bslain, yee i) “get eh pan Give parse t tree for leftmost and rightmost derivation of the sting 1001A At 8 | @S>A1p a : A i re oS A oO B ee 4 (B+ 0B 000° -§ . At B 18 \ ex 2 ee ° 8 °o 8 A, 1 8 / 2 & | ©B>1B — OBS. Fig. Ex. 4.2.2 n of 1001 is shown by series of Figs. 4.2.2(a) to 4.2.2(f), st derivation of 1001,
0B @B0Bi } ot tation (PUst 4401_Conont Free Grammar (CF) ayy | rn il . : A A Hy || YIN RS hs mS J nA ae TX han so \ ne A A o B 8 Hl “ A A wx 1 r NY : | OBB Boe Fig :A +e Fig. Ex. 4.2.2 Rightmost derivation of 1001 is shown by a series of Fig. Ex.4.2.2(e) 0 Bx. 42.94 Ttmay be noted that the final parse trees Ex. 4,2,2(0) and Ex. 4.2.2(0) eid, Example 4.2.3: Forthe cure pares aps) NV, 7 Give Gerivation of 000111.” “ Solution : 1. Derivation in sentential form f S$ 0S] (Using production S981) ) = / 1 S = 00si1 [Using production S > OS1) S + 000111 [Using production $— 01) 2 Derivation using parse tree. = [Prebaton 8-081 avg = tah 9 § 1 += [Productions +081) © < tn » tay +— [Production $ -».01] i eaFroe Grammar (GFG) 6nd ot ( Al lel boob Fig, Ex. 4.24: Derivation of aabbb ence, aabdb € L(G). 7 For the grammar given below e425: eam ESE+T|T ToOT+F IF F(E)lalb Give the derivation of (a+b) +a+b. jon : For the grammar given in Example 4.2.5, Set of variables V = (E,T, F) Set of terminals © = (+, *, (a, b} golutl | ESE+T|T ‘| Setof productions P = ) T>T*F|F, troll F>@|alb Start symbol = E (Derivation in sentential form E>E+T [Using production E > E +7] ST+T [Using production ET] 3 T*F+T)) 4.0» [Using production TT * F) Fe F+T +) {Using production T— F) Waiay 20. q0iil Tk (E)aB+T [Using production P+» (E)) SES TFET [Usiiig production EE +7) > (T+T)*F+T [Using production E > T] 3 (F+F)* FSF (Using production T > F] (a+b) a+b [Using production F > a| blof 412 __ Context Free Grammar (cra, sy Derivation using parse tree: IN he 62 j6 + blo Rotenre ronan potest 423 Wing Grins for x te ty Productions for an infinite Ia Tecursive if its left side variable occurs For example = (1) Sais recursive Q) S+bfaa pera ng 7413 Context Free Grammar (CFG) and — € is taken as member of L, — aS can generate one or more a's qe PO Generation of the string aaaa, pny forr we ees (sing production 5 + asy BS 1Using production § as} =>amS [Using production $ — as > aasaS [Using production Ss as] Sas (Using production $ e] Fig. 4.2.1 : Parse tree for anaa L=(a, aa, aaa,...) @ ‘The productions required to generate the above language are : ‘ S —as Sa roam S — aS can generate one or more a’s. The Production, S sa is for The production 5 of recursion, ‘gxample : Generation of the string aaa 52445 [Using production Sas) aS [Using production S — aS} —+aaaS [Using production § -> aS)ton (PU:IT) 14 _ Context Free Grammar cp ‘ 3 Parse tree ; y > /\. a os wos a os a 8: te Fig. 4.22: Parse tree for aaaa G3) Language L={b, ab, aab, aaab, ...} The productions required to generate the above languages are : S aS Sb The production § — aS can generate one or more a's. The production, Ss termination of recursion and thus generating zero ot more a's followed by ab, Example : Generation of the string aaab. Sh Sentential form ; S aS [Using production S > aS} > aaS (Using production S > aS] = anaS [Using production S — aS) > aaab —__[Using production S — b] Parse tree : s a oe iv b Fig. 42.3; Parse tree for aaah (4) Language L = (we (a,b)*) The above language can also be written as L = (e,a,b, aa, ab, ba, bb, ....4 tion (PUTT) 4 Context rammar (CFG) and Languages, 2 ing that can De derived fom the alphabet (a,b) belongs to La THI Tah gUSEE us b 5 ted ns gener ab ne) ‘AM pF Jar expression (a +b)*, the ee" orb uctions required {0 Senerate the above language are: er 5s 30S s obs . soe actions S — aS, S — bS can generate any number of a's or b’s with the he? as either # oF b. The production S ~» eis for termination of recursion. Since € is er of L. S > €is taken for termination of recursion. e : Generation of the string abba im a form: ; § as (Using production S — as} = abS [Using production s bs) — abbS {Using production § 5 pS] = abbaS [Using production § — as] — abba {Using production § e) eee: s | Fig. 4.2.4 : Parse tree for abba Language L={€, ab, aabb, ...,a"b")form : 5 > aSb [Using production S — aSb} =+aaSbb [Using production S— aSb] —saaabbb [Using production § > ab] s a sb JN a Sb a b Fig. 4.2.6: Parse tree for aaabbb or ab? L= (we (a, b]* |w is a palindrome of odd length} *a’ is palindrome of odd length. a palindrome of odd length abababa is palindrome, The palindrome nature of abababa can be as given shown in Fig, 4.2.7. abababa — 2 palindromeyyctions S ~> bb are for termination of recursion. It ee generated by the above grammar are aa and bb. The two productions S— ®S® pe scat generate a palindrome of arbitrary length. g genera of the string ababbaba con form ae oes ea [Using production § > aa} > abSba [Using production § + bSb] —abaSaba [Using production S 3 aSa} —rababbaba [Using production S > bb) a derivation tree : : s . asa 1 b b Fig. 4.2.9 : Derivation tree for ababbaba L= (we (a, b}* | w isa palindrome of either even length or odd length with | juctions required to generate the above language are ; ,aSa] bSb| aa] bb|a|b i ‘4 , aa or S — bb are for termination of recursion for even length palindromes. d $— b are for termination of recursion for odd length palindromes. or S — bSb can generate a palindrome of an arbitrary length. — Rule for Grammar: a.S+ sige , is generated by a grammar with start symbol S, and Lis generated by a -d withaa tion (PU. 4.21 { S>0S,01s1 S| 05)|1S\le ) where Set of variables V = (5, 5,) Setof terminals T = {0, 1) Start symbol = § 7; Construct the conte) ie 4 oo xt ffee grammar corresponding to the regular = (0+ 1)1°(4 + (01)*) ee for (0 + 1) is given by ton 5, 2011 {union rule] gamma for 1* is given by S, > IS,le arn at for (1 + (01)*) is given by S$, 11S Where S, stands for (01)* Sy 7 O1Ss fe ig the concatenation rule, we can write a set of proouestons for = O+D1"0+ 0") . =\( S4S\s;s, S$; 01 S,318,]e S$, 1S, : S,> 01S,Je 4 usin} ) where, : Set of variables V = {S,,S;, Ss, S,) Set of terminals T = (0, 1) Start symbol is}s2ilz1) ution: Astring of L has to meet the following requirements ‘A finite number of a's followed by a finite number of b’s. Number of b's should be at least as many as number of a's. + Number of b's should not be more than twice the number of a’s, iyP tion (PU-IT) | _ Generation ofthe string aabbbeccee WN qual numbar of a's and o's ‘equal number of b’s and ca Fig. Ex. 4.2.9(a) + Parse tree for aabbbeecee r Find context free grammars h of these languages: ple 4.2.10 9 ‘generating each of these languag' ie (1) Lele’ izj+u (2) Lefadch|j=i+k) (8) by={ado*|i=jorj=k) Lede lizj+e) w S 9 aSc [aX X — aXb|ab @ petit |j=ik) “The string a'b/c* can be written as abl phe a) as and b's are equal B’sandc’s are equal (generated by X) (generated by Y) ens: XY r — X > aXb [ab Y¥ > bye) be - Outer a’s should be matched with c's then the remaining a's should be matched with b's.[Some a's followed by number of b's and c's] (a) “(011 4.1)" (01) Soliton: (b) d'i**o' where i, k>=0 (@) CFG for (011 +1): (01): Letus assume that (O11 + 1)* is generated by the variable X._ “=X + O1X|1X]e Let us assume that (01)* is generated by the variable Y. * Y¥ Soryje Using the concatenation rule, the set of productions for (O11 + 1)* P= { Soxy XO1IXXe Y501Y|e ) where, the set of variable V = (S.X,Y} the set of terminals T = (0,1) ‘The start symbol = S (0) CFGforo'1'**o" | ik>=0 ‘The language L can be written as : L= (o'r io) We oethat 0'1' is generated bY the variable Xe yas “X= OXI fe that 1°0" is generated by y= 1Yile productions Pis given by: sox ¥ the Variable Y. 1yOe ‘The set of variable y — (S,X,y) The set of terminals T — {0,1} The start symbol = g ‘Show that the language, (YL = (aC ij >= 4) ang Q)le= {abe | ijs= ‘are context free language. languages can be shown to CFL, by writing the Tequired productions in each =falb'c!|ij>=1 S— xy X— aXblab [X generates ab and YoY¥|c — Y generates c} j= (able | Us: 1: S—+XY {X generates a! and X aXla Y generates be!] Y bY |bcGEEtion (PU-IT) 4-27 Froe Grammar (CFG) and pets assume that 1” is generated by the variable X. ens a IxXle ys assume that (0+ 1)* is generated by the variable Y. PY > 0Y|iyle give concatenation rule, the set of productions for 1*01"0(0 + 1)* can be written as = yet P= { S+X0x0Y 1 = X7 1X|e YO0Y|1Y/e ) where, the set of variables V = (S, X,Y} the set of terminals T = (0, 1) / the start symbol = $, 46: Give CFG for set of odd length stings in i De fe middie symbol 1 «airing generated by the above language could be shown as given below: ng of length n from (0, 1}*| 1 String of length n from (0, 1)" Pe | $— 080 0S1| 180] 181} 1 ) jon S— 1, terminates the recursion with 1 as a middle character, set of variables V = (S)} set of terminals T = (0,1)Ns Been A Conpten pT) bet St ar ey bb i String of length n from (a, b, c,d)" H ae dd ‘Sq The hidden recursion can be understood from the fact that Seletion og ‘character will not change the basic nature of the string. "iy i.c.,ifS is a string of the given form then S are : 8a, aSb, aSe, aSd,bSa, bb, bSe, BSI, &S8, CSP, CSC, Sd, dSa, dsp, gc, Thus, the set of productions for the above language is given by ; P =(S—+aSa|aSb [aSc| ad] Sa | bSb | bSc | bSd | c$a||cSb|eS¢|eS4 Sa | dSb | dSc | dS4 | aa| bb |cc| dd + dy “where, setof variables V = (S) : set of terminals T = {2,.¢ 4) ‘Solution : There could be three possitil jes on number of a's and number of y', g Casel: m>q,a™b" cP d® can be written as — ara” “bor 7 pal Spool where a™"%'c? is generated by the variable X (say).wn: m= ab'e"d’ can be written as eh eetan 2eay) re b'cTis generated by Z (say) Z = bZcle hus the set of productions for the p ={ S>aSd|x|/y X— aXe |Z ¥ > bYd|Z Z—bZc|e above language are given by : i Set of variables V = {s, X,Y,Z) hs Set of terminals T Start symbol = $, 2.19: Give OFG forL = (a’b"e"| m, n> =) : ree ‘The production S — aSc can generate equal number of a’s and b's, wus the set of productions for the given language is : Pp =( S92 aSe|X X—bX|b paviie) production S —» X, terminates the recursion. The’ variable X can generate one or 2 b's. ire b ee Set of variables V = {S, X) — Set of terminals T = {a, b} a Start symbol = S. “Give CFG for L = {x| x contains equal number of a’s and b's). PU - Dec. 2006, May 2009 ‘generates a string with equal number of a’s and b's. generates a string in which number of a’s = 1 + number of b’s.™~ of Computation (PU 4:30 _Contort Free Grammar (org), We can write the set of production using indirect recursion by relating the three ‘ S,A.and B, i * The relation between $ and B is given by S— aB, B represents a string in which number of b’s is one more than a’s. If we Pre, to ‘B’, both a’s and b’s will become equal. Similarly, the relation between S and A is given by S—bA * Aistelated toS by ; A — aS, removing an ‘a’ from a string represented by A will render boy, ay et : ten a Ais related to A by A DAA, one band two A’s on the right hand side will mean number of ;», ote than number of b's. . Similarly, Bobs S and B > aBB ey i Thus a set of productions for the above ln are given ys pal S>aB|bA understood with the help of the following exany yaababbi) leninof ton (PULIT) 492 Context Free Granmar Gr, a Example 4.2.24: Give CFG forL = {a’b” | n ¢ mired s Solution: A string belonging to L can have either of the two forms given below 1. ald! wherej>0 or 2. alb/b' wherej>0 Let us assume that ais generation by A and b! The set of productions for the above language is given by : P=( S—aSb/A|B AraAla B>bB|b is generated by B, ) where, Set of variables V = (8, A, B) Set of terminals T = (a, 5) Start symbol = 5. Example 4,2.25 : Give CFG for the language L = {a'b"c" | h=m orm =k) ~ Solution : The language Lis union of two languages Ly and L, where, L, = (ape! |n =m) = {a'b'c*) Ly = (a’b"e |msk) = {a'b"c" "| p20) = (a"b"c%e!| p20), The productions for languages L, = {a’b"c') are given as : S, = AB, where A generates a"b" and B genirates c', A= aAble B= cBle The productions for language {L,=a"b"c"c” | p20) are given as: S; = XYB, where X generates a’ and ¥ generates b"c”, X aXe Y—bYo|e [jal Now, we can write productions for the given language Lusing the rule of union, = Unt Pe{ S>S|S; 8, AB A-oAble B>cBle fat S)>XYBput 4-33 Context Free Grammar (CFG) and X>aXle Y>bYcle ) ‘The set of variables V = (S,5,,5,,A, B, x, ¥] ‘ ‘The set of terminals T = (a,b) = 1 Give CFG forthe language L={0"1"0""" | m,n>=0) - anguage L can be written as : L=fo"r'o™")
1) (0) L=(@"b" |n>m) Solution : ® L ={a'b"|n>1) S = aSbb|aabbbb ©) L =[{a"b" |n>m) S Sb] B B ~ bBib Example 4.2.29: Give CFG for the following language * The set of dd engi, > }* whose first, middle and last symbols are all same, th Solution : A string belonging tothe language wll have any ofthe tWo forms, Form 1: a astring of length nover {a,5)* 4 fing of eat non, Generated by X Form 2: b a string of length n over (a, bj* b ‘a string of length a oye, Ne i Generated by Y The set of productions for the given language is + P ={ S—aXa|bYb . > aXal aXb| bXa] bXb/ 2 Y > aYa|aYb| bYa] bYb|b } : where, The set of variables V = {S, X,Contoxt Free Grammar (CFG) and Langs recursion in X can be understood from the fact that deletion of first and last ene change the basic nature of X, igstning ofthe given OFM then X are X—> aXa] aXb |bXa|bxb eet rotons for the above language is given by, Pe={ S—> xb X— aXa| aXb| bXa| bXb|a on X — a, terminates the recursion with as the middle character of X. The set of variables V = (s, xj ‘The sct of terminals T The start symbol “FG which generates the language L defined by the regular (a+b)tbbb(a+ by that the start symbol is S. (§ 2 XbbbX, — where X generates a stringin (a+ b)* x ak |bXle ey 2 G= (.T.P.S) v = (S.X) r= (ab) ie XbbbX_ x9 aX|bXleContext Free Grammar (CFG) and Languages. 4.8, generates a+b + in two different ways. The two derivations are 1(o) and 4.3,1(b), derivation (Fig. 4.3.1(9)) says that (b+ 9) is evaluated first and then the *, value is added to @. Thus the right side + Operator gets a precedence over the ste ator ‘The Expression a+b +a is treated as (a +(b + a), pt derivation (Fig. 4.3.1(b)) says that a + b ig evaluated first and then ithe “cea is added to. Thus the let side + operator will get precedence over right vs or. The expression a+b + ais treated as ((n 4b) + a), _ambiguity : There is no general rule for remov ipiguty fom graMMar involves rewritin forevery string belonging to L(G) iy from the grammar £ OE+E|alb wed by strictly assigning higher precedence to left side This will mean evaluation of an expression of the form a can be incorporated in the &rammar itself by sui ing ambiguity from CFG. ig Of grammar so that there is only one » language generated by grammar G. * + operator over right +b-+a,, from left to itably modifying the e of Fig. 4.3.1(b) is based on left to right evaluation, i evaluation in grammar(48) ean be enforced by introducing one more friable T can not be broken by + operator, 1s grammar for the grammar of (4.8) is given in (4.9) before an atomic T can be added to it. E can be broken down in E + T be broken further. This ensures hi igher precedence to left side + ‘operator for the stringa +b +a,In general, 1. Sometimes we can remove ambiguity from a grammar by hand. 2. There is no algorithm for either deletion of ambiguity or for remoy 3, Some context free languages are inherently ambiguous, ambiguous CFG. An example of inherently ambiguous language is L= Luk, Where, L, = {a’b"c"d"|n, m>0} L, = (a’b’c"d"|n, m>0} Example 4.3.1: Consider the grammar EsE+E/E*E|(E)II Isalb a) ‘Show that the grammar is ambiguous. b) Remove ambiguity. W Solution ; There are two problems in the given grammar 1. Both + operator and * operator are at the same precedence level. 2, An expression can be evaluated either left to right or right to left, These problems can be removed by introducing more variables, each reps, expressions that share a level of “binding strength.” . A variable T is an expression that cannot be broken by + operator Let us calli aj, A term can be expressed as product of one or more factors. R * A variable Fis a factor that can not be broken by + operator or * operator. A facto, a) Identifiers (b) Literals (©) Parenthesized expressions An unambiguous grammar is given below : E>E+T|T T 3 T+F|F F>@®[alb } A parse tree fora +b * ausing both ambiguous and unambiguous grammar is shown Fig, Ex. 4.3.1,(©) Using unambiguous grammar ees Sl Pate ies fora tng 4.3.1(2) and Ex. 4.3.10) are using the ambiguous gram (c) is using an unambiguous ‘grammar, i ar given in the ‘example is an & Well known problem in programming language, if statement in 2 if(x>y) a=atl; if&>y) a=a+] else substitute the condition x > y with C and § for a= a + 1, With these i f statement in two forms can be written as : of understanding, a reserve word ‘then’ has been introduced. ‘if statement can be written with two interpretations. It is shown inof PU. 440 _ Context Free Grammar (CFG) a, a Fig, Ex. 4.3.2 : Two interpretations of a nested if-statement 1 ! i | | | le aw nested if statement can have two interpretations. Problem: An ambiguous grammar orif statement may have dangling else probiom, Solution : An unambiguous grammar should attach the dangling else with inner if-statemeny _ Anambiguous grammar for if-statement is given below ; en - S— ifCthens Jif C then S else S ; [a [termination of astatement by ‘a'] Cel Sicislicrses|a Ie Where, i stands for if, ee tstandsforthen, Ye coanapy yitases and ¢ stands for else Example : Grammar (4-11) can be shown to be ambiguous by drawing two differen derivation trees for the string icyticst aea, Two different derivations are shown in the Fi Ex 43.260), ie Pea mg A TS ree bh eakinterpgenles see Wem apni jiion PUT) 4-41 _Context Free Grammar (CFG) and Languages. rors De j i 1cC18a ie 1! (a) ) Fig: Ex. 4.3.2 : Two derivations for ic,ticytaea ving ambiguity = The ambiguity from the grammar (4-11) can be removed by gongling else with inner if statement, We will introduce two more variables. in U = For if-statement without else part, M — For if-statement with else part, mbiguous grammar is given below ; a fg9U1M M—iCIMeM |a ~ (Grammar 4-12) iets | icuMeu 5 eee working of grammar (4-12) can be understood with the help of derivation tree for sigeas [tis shown in Fig, Ex. 4.3,2(c), 8 Fig. Ex. 4.3.2(c) : Derivation tree for ic,tic,taea |) Outer if-statement is without else part, + Imerif-statement is with else part.4-42 __ Context Free G: wutation (PU-IT), mar (CFq) ang & Which generates all hat the CFG given below. tings secanses is ambiguous. Give an equivalent unambiguo,,« rant, hay S+SS](S)|¢ Examp! Solution ; Let us consider derivation of the string (( ))(). TWo derivations te y, Fig. Ex. 4,3.3(a) and 4.3,3(b). _ o Syl Ah AD | | ol (a) (b) Fig. Ex. 4.3.3 : Two different derivations for ((})(). Sinee, there are two different derivation for the string (())() the grammar is ap, An unambiguous grammar is given by S > ST|T } TA (S/O F ! } * Sideways parentheses can be generated by § + ST. where T is atomic as far ag ik, : generation is concerned. It forces left to right generation of balanceg Daten, Nesting of parenthesis is generated by T — (S). i Example 43.4: Write an unambiguous CFG for arithmatic expressions with Operaion: +, *,/,4, unary minus and operand a, b,c, d, ef, ut A\6o, if should be possible to generate brackets with your grammar. q Derive (a +b) “d/e+(~1) from your grammar, Mbiguoy, ) 44 Solution : An unambiguous grammar is given below. | } E SE+T|T [+ has lowest priority with L — R associativity) WT OT*FIT/F|F [+ and / has higher priority over + with L > R Associativity) F SFAG|G [*has higher priority over * and/ with. > R Associativity] G >-H|H [unary — has the highest priority] H ~a|b]c|dJe|£](&) [to handle brackets and identifiers)Fig. Ex. 4.3.7: Two derivations for aab et of productions: resemble produ jn a similar way through int ) Moved in # eet ctions 18 * so is for if-statement f-statement. Thus the ambi; uity can be ion of two variables U and M ah reeoltlog a: Let G be the grammar 438° 6, aB|bA ‘ A> al aS | DAA p> b|bS|aBB Ri rake aaabbabbba find eft most derivation (i () tars Tree (ii) Right most derivation (iv) Is the grammar unambiguous 7 ill be worth while 10 draw the parse tree and from the parse tree, one can easil oni ily re 2 rai right most derivation. A parse tree . i,aN Theor ol Computation pu. #48 —_ oer Fina Samer (orc) % ~ by Re (1) Left most derivation : SaB — aaBB — aaaBBB — aaabBB ~ aaabbB — aaabbaBB — aaabbabB — aaabbabbS — aaabbabbbA — aaabbabbba (ii) Right most derivation : S—aB—yaaBB—aaBaBB—aaBaBbS—aaBaBbbA —aaBaBbba —sanBabbba—>aaaBBabbbaaaaBbabbba~aaabbabbba (iv) The grammar is ambiguous as we can draw two parse trees for aabapy,, s : i /\ 2 ; EX a8 AN, AN a = cm: Ss o—o o—o as (b) (a) Fig. Ex. 43.8 Example 4.3.9: In each case, show that the grammar is ambiguous, and find the eo a acl = unambiguous grammar (a) lajb (b) SABA, A adle, B bBje (c) S— aSbjaaSble Solution : (@) S—SSlalb is ambiguous ‘Two parse trees can be generated for the string ab. s ‘A i ee ag [al Ll a a Fig. Ex. 43.%a)es 2 447 8 —Conter Free alee ~ e- _jous grammar pagwos eam Lae raajabjbal00 (CEG) and Languages ier nah Bp PA wrees cats DE Benerated for the su Ng aa ino s a Pie eS | Lt] Fig. Ex. 4.3, ae inss grammar: vn > asbXe (String of 2 — bxly onlyla's Will be Benerated by S—raS|e] vy > aYle iaaSble is ambiguous san raw 02 gests trees for anabb oS ~ gensth ec ST = Fig. Ex. 4.3.9(c) us grammar ta is of the form = (ab/|izjandij20) ‘ > aSb| X x oaxle + Consider the grammar G=(V=(E, FI T= (aE P) where P consists of rules : E> F-E,F>a E>E-F, (a) Show that G is ambiguous “a FobE>F (b) Remove the ambiguity.enteu. 4-48 _Conten Foe Gama (ora) ne al, e Solution : The production rules ean be re-written as given below : E> F-E|E-F|F Falb (@) The grammar ean be shown to be an ambiguous grammar by drawing | derivation trees for the string a—D. oi, A . E ‘ /\ /\ ear | ple fel Fig, Bx. 43.10 : Two derivations for ab (6) The production E> F—E, makes the evaluation from right to left which ig, allowed. orally Thus the ambiguity can be removed by deleting the product the production Es, The resulting unambiguous grammar is ; Po EE-F|F ‘Solution : 1, §>0s1s,|1sos|e ‘The given grammars ambiguous as we can have two different parse trees 101. For theo ‘i 8. isAA joe |baale jven grUMMar is amb ned! "BUS, We & derive Wo di » ifferent parse {Tees for the string BRANDS ey \ A 6 ‘ Bee! t | FeEaasy @) i ings a8 ey p Say sf gommar. Simpl tion oF CRG fava Contain eestictions ae j . a ‘"esttictions are imposed ame sis eta FSrcons on ge Aare a 7 OSSD Simpy einnning ‘yeu ination of Useless Symbols : ammar may contain symbols and Productions which are he i ee spe ee ne roe ch are NOL useful for derivation of generating symbols, able symbol. every Variable must generate a string of terminals, Grammarof tion (PU 4-50 _ Context Free Grammar (cra) re Ble, ‘ S - Aa|BbJa|b t A—Aala ...Grammar (4-14) B > bB Requires simplification as the symbol B is non-generating. Only production a B bb ae : and it can not generate a string of terminals. The Grammar (4-14) can be ra se a HIER SRE OS aes ; deleting every Production containing the useless symbol B. A simplified gramme, , eg ( in (4-15), s ting S = Aala|b A> Aala -..Grammar (4-15) A grammar containing a non-generating symbol V, should be simplitieg ,, om Every production containing the non-generating symbol Vj. ti Fini nage ing non-generating symbols ; There are two niles for finding a set of generating symbols for the given grammar, 1. Every symbol in T (terminal) is generating. 2. If thete is a production A ot and every symbol in is generating, then A is pen ‘Where ae (V+ 7)’, A symbol not in a sevof generating symbols is said 10 be non-generating, Exam Find non-generating symbols in the grammar given below ——.. erating S— AB|CA B BC|AB Ata C+ aBlb. Solution : Step 1: Every terminal is generating GD — s104 gonoraing symbols Step 2: A and C are generating as'U-IT) J $81 con Fee it gaat ~artmar (CFG) and v0 there I Production ory. the set Of ge i Stheratin, 5 2 oy form 4 +4 8 Symbols Using the Rule 2, e * gener : and every Symbol in cis generating le i‘ symbol S is generating 4. there at generating. ere is Prolicton $c, With both C and Aas a a Sie Salat it does Hot belong to the set of omit Example 40 can be « Mplifi I ppliied ermimari giver mae Ned bY deleting Productions with the useless wn 5 S—>CA symbol generatingtext Free Gra of fon 4-52__ Con! mmnar (CFG) Sada A+ Sb|bCC| Dad ‘> abb|DD Esac D> aDa 4.4.1.2 Non-reachable Symbols: A symbol X is reachable if it can be reached from the start symbol S. ie. if $3 cand a contains a variable X then X is reachable, c Finding non-reachable symbols : Non-reachable symbols ean be located with the help of a dependently graph, X.is said to be dependent on S if © Say) ee) eer Sa, xd, Fig. 44.1 : Depending Grapy, A Varig, The dependency graph a i ary fan * We must draw a dependency graph for all tions, ) If there is no path from the start symbol § to a variable X, then X is non-reachable reachable anasto the given grammar.ee production S$ aAa, A is dependent on §, It is shown using a directed edge ait La i production A BCC, C is dependent on A, From the production A —> Sb, Sis + fo tne fo gent of ; ye prowuetion E aC, Cis dependent on E. fo? seo path from S 10 EE isnon-teachable, 1 nese ification of grammar : . a ean be simplified by deleting every production containing the non-reachable gam pitied grammar is given below : Si é & P= (S—aAa, A > Sb|bCC,C— abb) gore P= (S— aBa|BC,A—aC|BCC,Ca,B > bCC,D—E, Ed) 2. P=(S—> aha, A—bBB,Bab,CaB}. 3. P={S > aS| AB, A bA,B Aa} Dependency graph Non- Reduced reachable symbols A, D and S — aBa| BC Eare non- | Ca reachable | ps pCc Every e symbol is | original reachable | grammar‘ =! mea yo ae | ah ot thon (PU: 4-54 Context Free Grammar IF) a, La, 4.4.2 Elimination of e-productions : A productions of the form A — ¢, is called a null production or €-progt.g ‘Context free grammar G with e-productions, we can find a context-free frammey ta, ‘productions such that tha Mb L(G, = L(@)-(e) " ‘The procedure for finding G, (equivalent grammar without productions) isa. Step 1; Find nullable variables Step 2: Addition of productions with nullable variables removed Step 3: Remove e-productions. Step 1: Find nullable variables : A symbol X is nullable if 1) There is a production of the form X — €. 2) If there is a production of the form X > cand all symbols of c are Tilley Example : In the grammar with productions S— ABA, A— aA | e, Bot), Ais nullable as there is a production A> € B is nullable as there is a production B + € Sis nullable as there is a production > ABA With both A and B as nullable. +. The set of nullable symbols = {S, A.B) Step 2: Addition of productions with nullable variables removed. An €-production has an effect. This effect must be added as productions to the e, grammar before €-productions are removed. My Productions compensating the effect of e-productions : For each production of the form A —+ Gj, create all possible productions of tes A — 0, where (, is obtained from c, by removing one or more occurrences of variables. Pal low, [Sa is written as $5 aang | S$ aS. is nullable and henceContext Free Grammar (CFG) and Lm Grammar after addition of effect of nullable symbols <> saa AD Productions derived A and B are nullable as from S -» ABA by A cand Be. is null making one or more as every symbol on the symbols null. right of S— ABA is nullable, «. Nullable symbols ={A,B,S) S— aS S53] Derived from$ — As S— AB aA S+B | Derived fromS > AB Sse Ate Boe Nullable set = (A, B, S) Remove €-productions from the grammar obtained in step 2. sas la) {S— ABA |AB|AA|BA|A|B} (522512 /AB|S>A|S>B) Remove e-productions from the given grammar. § > ABA, A aA|e, 8 bB|c Cae ge Find nullable variables oe gba on the right as nullable. Nullable set of symbols = (A, B, S) = q i jTreey ot Compaen pur __—_— #58 Content Five Grammar (CF Sy { Step 2; ‘Addition of productions with nullable variables removed. , $—> ABA SAB s— BA SAA SoA SB Se | A — aA can be written as) 4 4 ee B ~+ bB can be written aS] g , ++ Equivalent set of productions. {sane} Pe S — ABA can be written as AsaAlale B+ bB|bJE Step 3; Remove ¢— productions The final set of productions is given by S$ ABA|AB|BA|AA|A|B P, AvaAla B—bB|bjon (PUT) =.
Ay Ay Ag and Ay A; | Thesis for elimination of unit production areas follows: up! ‘Add all non-unit production of G to G,. gp: Locate every pai of variables (A,, Ay such that A, A. xp3: From pairs constructed in step 3, we can construct a chain like (Ay? AgesAj > O where Aj —> is anon unit production, ach variable A, to A, will derive a.ot ton (PU 4.56 Cerio Five Gramma ig, a a 4.4.7: Eliminate unit productions from Le, SN P= { §-—ABA|BA|AA|ABA|B \ A-aA|a By bB|b ) s - Solution : Let G, with productions P; is an equivalent grammar without ynjy re Step 1: Add all non-unit productions ofthe given grammar to P,. Net, 5 ABA|BA|AA|AB p,=yAraAla (p> 0B|b * Step 2: Locate every pair of variables (A,. Aj such that A,—> A, 1, (8, A) [Due to unit production S— A) 2, (S$, B) [Due to unit production S > B] Step 3: Unit production $ —» A can be removed by expanding A. A derives aA | a. Unit production $ > B can be removed by expanding S — B. B derives bay Set of final productions for G; are given below : i Productions: From step I S$ ABA|BA|AA|AB AsaAla B—bB|b ~ Pair (S, A) SoaAla Pair (S,B) S$ bB|b ‘Thus, ‘(S—ABA|BA|AA|AB|aA|a|bB|b P, = yA>aAla B->bB|b Example 4.4.8: Eliminate unit produ {from the grammar = P= (| non-unit producti , Add all IONS OF the py, af Baber Sen grammar to p p= 4 l>T : 1= ) Fo) Malbliany ios it of vari , Locate every pair o atables (a4. ; 2 ) maha A (E,T) [Due to unit Production, Est @F) (Dee t unit production y I. 4 «@D (Due uit reduction 5 4 é&h [Due to (E, T) and ¢r, ry By er) fae © ED. ,F) and ety 6 @D (Due ot (T, F) and (Fr, 1) 3; Unit productions are removed as shown below i Fomstep1 | By pyp ToTsr * F5® 1alb] lal hon Pair (E, T) E> TF Pair (I, F) T3@) Pair (F, 1) Falb[la |b {10|11 Pair (E, F) E+ (€) Pair (E, 1) E>alb]la|Ib|10 j11 Pair (T, 1) T>alb]la |i {10/0 “Thus, the final grammar is given by E>E+T|T*F|(E)[a|b|1a|16|10\ 0 TTF |(E)|a|b|Ja| Ib] 10] 11 Py =) F>©)[a[b/ la] i |10|11 I>alb]Ia|Ib]10|11 44.9: Simplify the following grammar S—ASB Ie AsaAS|a B-— SbS| A|bbTheory of wtation (PU-IT), 4-60 _ Context Free Grammar (cr; Slang Solution : Following sequence should be followed to simplify @ grammar, 1. Eliminate to €- productions from G and obtain Gi. 2. Eliminate unit productions from G, and obtain Go, 3, Eliminate useless symbols from G, and obtain 0. Step 1: Eliminate e - productions from Gand obtain Gi. The set of nullable symbols = (S} 28S € Grammar with production (G)] Grammar after taking effet or ! ® > mmbels (Gina st S— ASB S$ ASB §— AB ] By making symbol S as null, Sve Soe A> adS A> aAS ‘A-—>aA ] Bymaking symbol S as null Ava B— SbS a By making one or more S nul) B—bS Bob BoA B-bb BoA B- bb Final G, , after deletion of €-productions is given below ; S—ASB|AB G, = )A>aAS|aA fa | B—SbS|Sb|bS|b] A] bb Step 2: Eliminate unit productions from G; and obtain G;, ‘The grammar G, contains a unit production B > A. A derives aAS |4A|b i can be written as. > [Baas|aa)b Gz. after elimination of unit productions from G, is given by <, nation (PU-IT) 4-61 Contax Free Grammar (CFG) and Languages aiminate useless symbols from G; and obtain G,, sf ee variables S, A and B are both reachable and generating. Hence the grammar Jess symbols. ; $ ye th ane Ls S> ASB AB {Assia pose ean pono” § > 0A0| 181 | BB ASC BoS|A GoSle 2 Gy = ont ‘ ‘ oO iminate €-production ftom G (given grammar) and obtain Gy. Set of nullable git! ymols are as shown in Fig. Ex. 44.10: Fig. Ex. 44.10 mar after removal of null production is given below : §>0A0/00[1B1[11|B|BB] Aoc.B>S/A.C>S eae) sup?! Following unit productions are there in G,. § 5B APG BSBA C>S There is.a chain. poAoC>S>B wm S9B>S ‘These chains are cyclic in nature of each is terminating in S.FThomy Fo tusiss eu: 4.62 __Context Free Grammar (CFG) ang The grammar without unit productions is given below + S$ 0A0|00|1B1| 11 [BB A 0A0|00|1B1|11| BB B~0A0/00|1B1|11| BB © 0A0]00{1B1| 11| BB Step3: The symbol C is not reachable and hence it can be deleted. The set of productions is given below : S$ ~ 0A0}00| 1B1] 11|BB A — 0A0|00| 1B1]11|/BB _ B + 0A0| 00] 1B1| 11 {BB Example 4.4.11; Simplify the following grammar S— Ab Aa B>C|b C+D D+E Esa ‘ Solution : Following sequence should be followed to simplify a grammar : 1. Eliminate e productions from G and obtain G,.. 2. Eliminate unit productions from G, and obtain G. 3. Eliminate useless symbols from G, and obtain Gy. Step 1: Eliminate e productions from G and obtain Gy. Grammar does not have e-productions. . G=G Step 2: Eliminate unit productions from G, and obtain G,. Step 2.1 : Add all non unit productions of the given grammar G, to producti P, of G,, ee fs Ae Acts 2 lB Step 2.2 : Locate every pair of variables (A, A, such that A, A, Gy 1. | (B,C) | [Due to unit production B > C} (C, D) | [Due to unit production C > D) (D, E) | (Due to unit production D—> E} (B,D) | [Due to (B, C) and (C, D)] 5. | (B. E) | [Due to (B,C), (C, D) and (B, E)) 6. | (C, E) | [Due to (C, D) and (D,E)) Ls >y compuration (rus 4-63, Contoxt Free Grammar (CFG) and Languages. a step 2 from SteD2 5 Pait B.C) | B va | [there is achain 8 C+ DE a} [there is a chain B > C+ D> E> a) : Unit productions are removed through expansion S 3 AbA+t,E a pair (C,D) | Ca | [there is achainB +> C+ D—+E > a] pair (D, E) | D >a | {there is achain B-»C >» D=» Ba] Pair (B, D) | B 4 | [there is achainB—>»C— DE a} Pair (BE) | B->a | [there is achain B->C > D-+E— a] Pair (C, E) | Ca | [there is a chain B >» C+ D E> a} hus the productions after ¢limination of unit productions is S— Ab A>a x E>a Py =) pipe Coa D>a imination of useless symbols ; Every symbol, in the given grammar is generating. 1 Reachable symbols can be located by drawing a dependency graph. / Fig. Ex. 4.4.11: Dependency graph wo symbols (S, A) are reachable. Other symbols (B, C, D, E} are non-reachable, Final grammar G, with productions P, is obtained by deleting useless symbols. S—rAb ys lace } h ET : Eanple 4.4.12: Find @ reduced grammar equivalent to it S—aG|SB \ A bSCa é im Heel | BSB | bBC C—aBC| ad Wee ate (TEC | il Selttion, a Set of generating symbols can be found as shown in Fig, Ex, 4.4.12: K MfY» H Context Free Grammar (CFG) a Theory of Computation (PU-IT) 464 rele ey 1 (Cad [a and d aro generating and hence C} Fig. Ex 4.4.12 ++ Non generating symbols = (B] Thus the productions after elimination of non-generating symbols is = - Sac P, =} A>bSCa Cad The set of reachable symbols can be found by drawing a dependency graph, sac A> bSCa A-bSCa Fig. Ex, 4.4.12(a) : Dependency graph The symbol (A) is non-reachable, Thus the final set of productions after elimination of non-reachable Symbols is : Sac a=lea} 4,5 Normal forms for CFG : Productions in G, satisfying certain restrictions are said to be in normal form, There are two normal forms for CFG, 1. Chomsky Normal Form (CNF) 2. Greibach Normal Form (GNF) 4 d plegconputaton (PUTT) 4-65 _Context Free Grammar (CFG) and Languages. context free grammar (CFG) without e-production is said to be in CNF if every satin i of the Form : e 4) BC, where A,B, Ce V. Aa, where A € Vanda T. ar should have no useless symbols, 2 The grammar S it a very CFG without € productions can be converted into an equivalent CNF form. si Algorithm for CFG to CNF Conversion : Fliminate €-productions, unit productions and useless symbols from the grammar. very variable deriving a string of length 2 or more should consists only of variables. je. every production of the form A ~> a with] a | 22, c should consists only of variables. Example : Consider a production A > V,V,aV,bV,, Terminal symbols a and b can be removed by rewriting the production A> V,V,0VsbV, as A OVVCV.CV, ‘And adding two productions Goa and C, 9b Every production deriving 3 or more variables (A > 0 with | «| > 3) can be broken down into a cascade of productions with each deriving a string of two variables, Example : Consider a production A —> X,X;...X, where n 23 and as X;'s are variables. ‘The production A — XX... X, should be broken down as given below ; A +X, CRG C, > XC) Ga XaiKe Esch with two variables on the right, ‘ample 45.1 Find the CNF equivalent to S— aAbB, A aA, B > bB|b. ie. 2, ; aTheory of Computation (PUT) 4-66 _Conlext Free Grammar (CFG) ang Solution : Step 1: implification of grammar. The grammar is already in a simple form without 1. e-productions. 2. Unit-productions. 3. Useless symbais. Step2; variable This can be done by adding two productions. Qa and Gb The sct of productions after the above changes is SSC,ACB ABCA Py = ) BOOB |fS, Coa Cob Step 3: Convert to CNF sSce Cc; SAC, Corresponding to S C,AC,B C+ OB A SGA BGB|b Qa f Gob SCC), C, AC; C, 9 6B * Py = | AICA,BGB[b,C, >a Cab ery symbol in ot, in a production of the form A —> ct where | ¢ | > shold, 1 Example 4.5.2: Convert the grammar given below to its equivalent CNF » S— POP P0P|e | Q510/e Solution : Step 1: Simplify the grammar Step 1.1 : Eliminate © productions Nullable symbols = (P,Q, S) P and Q are nullable as P > € and Q— €. § is also nullable as S > PQP with ever) symbol on the right as nullable,a eee productions, We get a set of productions P, e ai {esonan | P= Po Q>19)1 : Eliminate unit productions : rg two unit produetions S—> Pand SQ. sininatiNe unit productions from P,,, we get a set of productions P; Sa nek P,= Q>1Q]1 Every symbol in ct, in @ production of the form A —» a with | c | 22 should be a variable. toot ris can be done by adding two productions G = sep 1? 30 C1 The set of productions after the changes is given by P,. Po Osea ee POGPI|O aS Py = 7 QE QII Qo Gant 3; Convert to CNF : [isin pronucons in CXF] © —> QP feeisee ai oeeennEneEcaaneeeeeee Theory of Computation (PU-MT) 4-68 _ Context Free Grammar (cp, J +. The set of final productions in CNF is ‘S> PC,|PQ| QP] PP|CoP/O/CQ| 1 G9 QP P—>C,P|0 QC, QI ! G0 C41 Example 4.5.3; Check whether the given grammar is In CNF S—bA|aB A-—»bAA[aS| a BBB bS|b Iti is not in GNF, find the equivalent CNF, Solution : The given grammars notin CNF. Following productions are not allowed in gy S > bA|aB A > bAA|aS B — aBB| bs Finding an equivalent CNF : Step 1: Simplification of grammar — already simplified Step 2 Every symbol in a, in production of the form A —> ct where | | > 2 should te, variable. ‘This can be done by adding two productions. Ce and Gab The set of productions after the above changes is S3GA/CB A> GAAICS BC,BBIGS Ca, Gb Step 3: Finding an equivalent CNF : Original production | Equivalent productions in CNF S>GAICB S3GA|CB A GAA ACC, CAAyoomoon pus) 4-69 Context Free Grammar (CFG) and Original production | Equivalent productions in CNF AICS ACS B>CBB BGC, C3 8BB __ The set of final productions in CNFis SoC A|CB A 2CCICS imple 4.5.4! Design a CNF grammar for the set of strings of balanced parenthesis. : ition: Acontext free grammar for balanced parentheses is given by V = [(S), (G)}.(S),8 + $8,Se},S} where the set of productions S$ (S) P= )S—>SS Soe An equivalent set of productions without € -productions can be written as sais na fSsQlO} Lh Conversion of P, SS eae i p11 Addition of two productions [C9 fina feels (RI [5] win change the set of : 1 productions to : Pre oe } = |sS8,C, 96.07)a Theory of Computation (PU-IT) 4-70 _ Context Free Grammar (CFG) eng Step 2: Finding an equivalent CNF Production in CFG | Equivalent productions in CNF | S GSC; SoCG, ic SC, S30G, S20G | [ SSS s—+SS z G>( r G9) The set of final productions in CNF is { S3,6,1C,¢,|S8 ages C1 G3) Example 4.5.5; Convert the genres eines to CNF. a S-sAba, Saab, Em Solution : Step 1: Symbol B is non-reachable, The symbol can be deleted. The grammap in * simplification is : SAbalaab Step2; Every symbol is a, in a production of the from A —ct with la] = 2 shoutd be, variable : ‘This can be done by adding two productions Casa and Cb >b The set of productions after above change: S > AGC, |¢,¢,c, Step3: Convert to CNF SAC, > GC, Ss 7.0c¢ Gaoc Example 4.5.6: Convertthe following grammar to CNF S— AACD A aAble Cala A aDa| bDb/eP . tation (PU 471 Context Free Grammar (CFG) and First of all, the grammar must be simplified, juin moving null productions. ip}? Re Nullable set = (A) productions are removed with the resulting set of production as : S— AACD|ACDICD A— oAblab Cc aCla A aDalbDb 3: Remo ving non-generating symbol symbol § and D are non-generating. ~ owes sort +ab,C— ince, the starting symbol itself is non-generating, GareD itisan invalid grammar. pull Fig. Ex. 4.5.6 32 Greibach Normal form (GNF) : A context free grammar G = (V, T, P, S) is said to be in GNF if every production is of form = A a0, where a Tis a terminal and cr is a string of zero or more variables. ‘The language L (G) should be without €. Right hand side of each production should start with a terminal followed by a string of non-terminals of length zero or more. 52.1 Removing Left Recursion ; Elimination of left recursion is an important step in algorithm used in conversion of a #6 into GNF form. recursive grammar : A production of the form A=Acr is called left recursive as the left hand side variable pears as the first symbol on the right hand side, inguage generated by left recursive grammar : Letus consider a CFG containing productions of the form A> AG .«. [Left recursive) ASB «a. (For termination of recursion}of (Pus 472 Context Free Grammar, rare [From production A Aci] “y + Aaa [From production A Aa] n + Acca [From production A+'Aa} - Aa” [From production A= Act) + fot [From production A B} Right recursive grammar for fat": A right recursive grammar for fia" can be written as : As pBI/B {where B generates a string prodoction Ap for termination of recursion) B— aBla Thus a left recursive grammar can be fight recursive grammar as : » A Aalb 2 A>Aalbic A ble[>B/ cB B-aBla 3. AL AAA, AAy ArAy AyAyAAy, ... 5] ser (ASAD 4. APA AAIAAIAA, | [AAPA AAA) AA(AzAy, ADAyASAVALA ASA, (AAs) 5. S—+S10J0 | {0, 010, 01010, .... 0 (10)*) SS0eal B- 108/40ee 4, Modify the productions to ensure of tion (PUT an Context Free Grammar (CEG) and 4522 Algorithm for Conversion from CFG to GNF : Eliminate €-productions, unit productions and useless symbols from the gram jn production of the form i eu r A-*X)X3...X,...X,, other than X,, every other symbol should 2 bea variable. X, could be a terminal. Example : Consider a production A — V,V.aV,bV, Terminal symbols a and b can be removed by rt ed by rewriting the A vate i the production A — V,V3C,V5C,V, and adding two productions, Goa Gb Thus, at the end of step 2 all productions must be of the forms. (a) Asa (b) Ava (©) Aaa where ‘a’ is a terminal and exis a string of non-terminals. 3, Rename variables as Aj, Az, Ay... A, to create A-productions. Example : Consider a grammar given below S — aXSY|YSX|b ‘The variables S, X and Y can be renamed as Aj, Az and As respectively. Then the productions become A, aAsAAy|AsAiAs| — [A-productions] sa production A, > A, at then i should that if there i productions be $j. If there is a production Aj —> Aye with j/>]j. then we must generate substituting for A Repeating step 4, several times will guarantee that forevery production A > Aoi Si. Remove left recursion from every produc should be added to remove left recursion. ctions to the form A, —? a0, where a is a terminal and & isa string of tion of the form’ Ay —> Ae. B-productions 7, Modify A-prodw non-terminals. 8, Modify B,-productions to the from By —» ach where 2 is-a terminal and ct is a string of non-terminals. marin GNF which Is equivalent to the grammar Example 4.5.7: Construct a gram’ S—AA|a,A>SS|b.4-74 Step 12 Grammar is already in a simple form without: 1. &-productions. 2. Unit productions, 3. Useless symbol. ‘ We can proceed for renaming of variables, Variables S and A are Fenamed as 4 H Tespectively, The set of productions after renaming becomes : tts A, AJA, ! A\>a Productions after renaming A. AA, Alb Step 2: Every production of the form A, —» Aya with i > j must be modified to Make ic, Ay ~ production A, >. A\A, should be modified. y ‘We must substitute A.A; | a for the first A,. We should not touch the second Ay AgAsA, [A> AAV) Sneae A OF AA, ‘The resulting set of productions is : Ai AA, a Ar> AJA.A,|aA,|b Step 3: Removing left recursion : The A, ~ Productions A, A,A,A, | aA, | b contains left recursion. Left recursion from Arproduction Can be removed through introduction of B,-production, A:> aA,B,| dB, Bi AJA,B;/A,A, The resulting set of productions is As Ayla Ar aA,B,| 4B, | aA,|b BL" A,A\B; | A,A; Step 4: A, ~ productions are in GNF. A\ and B: productions cari be converted to GNF with the bet A: aA,B;|bB, | aA P Of A;-productions. ib... in GNF- ih vom ration (PU- 4-75 _ Context Free Grammar (CFG) and Ai AsAy U Substitute A,B, | bB; | aA, |b for first Ay A; 9A,ByA; | B,A,| aA,A3]/bA, A\—? &.. in GNF f for B, — Production Te a B)—> AA\By F ih Substitute A,B, |B, | aA, |b forthe first Ay un By —> AsAy h Y Substitute aA, B, |b B; [a A, |b for the first Ay B)—> &A\B,A,]0B,A, | aA,A, | DA, ‘he final set of productions Is: A, aAjB,| bB;| aA, |b A, aA\B3A,|bB,A, | aA,Ay | bAg] a A set of productions P B, > 2A,B,A,B, | bB,A\B,|aA,A,B; | bA,B,| 4 A\B,A, | BA) | aA\A, | bA, Now ves Set of variables V = (Aj, Ay, B,) Set of terminals T = (a, b) Start symbol = A, Set of productions P = Given above, fample 45.8: Ce ears een Ah TOTO FF fee ee pe Fo(E)|a solution s Step 1: Grammar does not contain &- productions and useless symbol. Grammar has unit productions, We first eliminate unit productions : + Tand T —» F are two unit productions with the chain E> T + F Non unit productions are taken as it is E+ EB+T ToTek F (Elax Theory of Computation (PU-) 4-76 _ Context Free Grammar. rele Productions for the following pairs are added : (E,T) > (E>T+F) (E, F) > (E> (E)|a} (T, F) > (T(E) | a} ‘The resulting set of production is = E SE+T|T*F((@la T +T*P/() la F + (E)[a Step2: Bringing every productions to the form A — aa, where Gis a string of Variables, We can make the following substitutions : A for +, B for * and C for) ‘The resulting set of productions after the above substitutions is: . E > EAT|TBF|(EC|a T > TBF|(EC|a F>(EC\a A >4+,B3+*,05) Step 3 Renaming of variables : The variables E, A, T, B, F, C are renamed as Aj, Ay Aj, Ay Ay, Age The resultant set of productions after the above substitutions Ay > AAAs | AsAaAs | (Aig La Ay S AVAAs | (AAs | a As 9 (AA, |a, A, 9 +,Ay 3 #, Ag) Step 4: Every productions of the form A, A, a with i> j must be modified to make i
AsAASB, | (A\AB, | aB, B, — A,A;B, | A,A,a tion (PU 477 __ Context Free Grammar (CI LS Left recursion from A,-production can be removed through introduction of p,— production Ayo ArAcBs 198s By? ABs | AAs The resulting set of productions fs: Ay 2 AsAVASB) | (A\A(B) | AB, | AVAVAS| (A\Ag | a By 7 ArAsBi | Aas Ay 2 (ALAGBs [aBy | (A,Ag 1a B, > AsAsBy| AvAs Ay (AAG | At A* (Saas Re: Ag) 4; Productions for A;, A;, Ay As and A, are in GNF, Productions for A;, By and Bs a can be converted to GNF. : Apt Ay = (A\AgB; | aB; |(A\Ag | | Already in GNF A Ay > (A\Ac|a Ag >) Ay DAAAB, : 4 Substituting (A, AvB,|4B,|(A, Asaf first A, A, 2 (A\A,B; |B, ...in GNF av) ae Ai AWAWAs Tipiesa SOO wend Ca eR U Substituting (AyAsBy [aBy|(AiAs [a for the first Ay A, > (AVASBsAWAs [aBsAGAs | (AVAAAS| AAAs | j Ay (A, Ao|a...in GNF bettion (P' 4-78 _Contex Free Grammar (CEG) ay, By AZAgBi | AzAa By + AAsBal AvAs Substituting * for Ay The final set of productions is : A, + Ay > (AiAGBs | aBy | (AAg| a A oe As > (Asa As >) A, > (A\AsB,A,ASB, | AByA,ASB, | (A\A,AVASB, | 8A, A,B, | (A,AGB, | aB, | (A\AgByAJAs | AByAAs | (A\AGA4AS | BAAS | (ALA, [a B, > +A,B,[+A, B, — *A,B,| +A. Example 4.5.9: Give the GNF for following CFG — i‘ i S +AB A+BS|b B4SAla BB PU Dec. 2 Solution : Step 1: Renaming of variables : ‘The variables S, A and B are renamed as A,, A, and A, respectively,ltant Set of productions after above substitutions is = yy Aa Ay AAO A, ALI e duction of the form Aj —> A, ce with {>}. must be modified to make i $j. Ay A,A; should be modified UA, is changed as per A, + AA, AAA 4 Apis changed as per A, =» A,A, |b AsAVAsAg| BAAS. _ resulting se of productions is; Ay > AsAy Ay AAD ‘Ay AyAiAdAs | DASAg | a 1 Remove left recursion i A? Production has left recursion, Left recursion from A, — production can be i 4 removed through introduction of B, — Production : A> bAVA:B)| 4B, 4 Bo ArAyA2Bs | AyAyAy rpereslting set of production is A, AAs Ay AJA, |b Ay 2 DAJA,B; | 0B, |DA,A, Ja B, > A\A)A;B, | A\ASA; ,Aj-productions are already in GNF a ‘A; production can be converted to GNF with the help of A, productions. ; \ Ay ASA\|b fh } 4 Substituting bA,A,B, | aB,| bA,A,| a for A,. i ! ‘Ar DAADBSA, | aByAy | BAYADA, | @Ay |b i i ~ production can be converted to GNF with the help of A; — productions : iF A, > AAy Bey J Substituting bA,A,B,A, | aB,A,|bA,A,A, |aA, |b for A, | { Ay = bAA:ByA)Ay | aByAiAy | BAYAZA)Ay | aA,Ay | BAy I 1~ Theory of Computation (PU-T) 4-80 _ Context Free Grammar (cra) productions can be converted to GNF with the help of A, ProdUSton, ‘The set of final productions in GNF is: Example 4.5. Solution ; Step 1: Step 2: By = bA,A,B,A,AyAjA; | aByA\AyAyA3 | BAYADA ASASA, | aA, By SA,AyA\B, |A\ASAz YU Substituting bA, 4A,A)A,A; By|A,A,A3By ASA, 1Ay Aba, Ay > DAA,B,A,A| aB\A\As| DAs A3AjA3/@A,A,[bA, Ay ~9 bA,A,B,A, | BJA, | BA,A2A,| @A\| Ay = bA\A,B, | aB,| DAA; ]a By bA\A;B,A\AyAA.By [aB,A,A\A,A,B, | DA,A,A)AyA,A2By |aA,A,A,A,B, | DA,A,A,B, [DA A,B A,AAJA, [aB,A,A,A\A, [DA\A,A)AASAy aA\A,A,Ay [DA AA, Reduce the following grammar to GNF, S— AB, A» BSB|BB[b B—aAbla CET; Making every symbol other than the first symbol (in derived string «in > asa variable: Variables C, is substituted for b with resulting set of productions give as: S AB A + BSB|BB|b B —aAC,]a,C,>b The variables S, A, B and C, are renamed as A,, Az, Ay and A, respectively. Th resulting set of productions is 10 given below. A, > AYA, A, > AJA\A,|A,A\ |bAged = ASE Ao aAiAy|a = As aba] a Apa Aas u ETRY fg thy Au AyAy | MAR Mh y Substituting Ay) Ag+ AA,A,Ay| aA, Ayrd — Awd Ay-*Aahy y EEA Ay BAAWA AYA A Ay VeAyAsArAaAa | MaMa DAs, ‘4 The final set of produictions is : Ay > aA\AVA\AsAs | 8A) ASA, | A)A\ASA, | 2A,Ay| DAY A, > aA,AiA\Ay|aA,Ay|aA,A,Ay| ay | b A; > aA,A,|a A, ob. inanple 4.5.11: Convert the following grammar to Greiback normal form (GNF), S—BS,S—> Aa, A— be, B Ac {aiutlon = ‘pl: Modifying productions to ensure that on RLS, other than the first symbol every other symbol must be a variable. Xa YcTheory of Computation (Pt 4-82 Context Free Grammar (Eq, S ~ BS|AX A > bY BAY Step 2: Remaining of variables, ‘The Variables 8, A,B, X, Y are renamed as A,, Az, Ay Ay Ay Ay oa Ay > c¢ A, SAVAIALA, A, > bAy Ay 9 Ay As Step 3: Prodiictions for A, As, Ay are in the required form, Productions for 4 1 and 4 be converted to the required form. ey Ay > A, Ay U Substituting bA, for A, Ay > bAS A, Ay AA ALAy ‘Substuting bAsAg for Ay DAs for Ay The final set of productions is given by A, > bASAsA, [DASA, A, > bAg A, > bA,A, Aya Asc Step 1: Making every symbol other than the first symbol (in derived string cin A-+@) as a variable :po cant (CFG) and Languages. Variable Cy is substituted for b with resulting set of productions given as : S — ABAG|ac, B > ABAla A > alb Gob substituting A + 8 |b. in S + ABAG, and B. —» ABA, we can convert $197 coguctions in GNF. The final set of productions is given by : S$ = aBAC,|bBAC, | ac, B — aBA|bBAla A >alb Cyst. pample 4.5.19: Write a equivalent GNF for the following grammar, A, AAAs A> AAY|b Ay AyAa| 8 soution* Refer Example 4.5.4, 4.5.14: Find the GNF equivalent to the CFG ed SAB A-»aA|bB |b Bob solution: A-productions A—aA|bB|b are in GNF B-production B-— bis in GNF S production S— AB is not in GNF. Itcan be brought into GNF through substitution. SAB u S —aAB | BB | bB 4. The required get of productions in GNF is : S— aAB | bBB | bB A aA|bB|b Bbee eee 4.6 Chomsky Classification for Grammar + ‘A grammar can be classified on the basis of production rules. Chomsky sag grammars into the following types : 1. Type3:R 2. ‘Type 2: Context free grammar 3. Type 1: Context sensitive grammar 4. Type 0: Unrestricted grammar. Jar grammar 4.6.1 Type 3 or Regular Grammar : A grammar is called type 3 or regular grammar if all its productions are of the follow forms ’ Ave Ara AaB A> Ba where a€ and A, Be V. A language generated by type 3 grammar is known as regular language, 4.6.2 Type 2 or Context Free Grammar : A grammar is called type 2 or context free grammar if all its productions are of following form A — o where A € V and a< (VUT)*. V is a set of variables and Tis a set of terminals. The language generated by a type 2 grammar is called a context free language. A regu language but not the reverse, 4.6.3 Type 1 or Context Sensitive Grammar : A grammar is called a type 1 or context sensitive grammar if all its productions afe0 the following form. a B, where f is atleast as long as cr. ‘Example 4.6.1: Write a set of production for the strings of the form a’b'c™.- ion (PUTT) 485 Context Free Grammar (CFG) and Languages Je on juctions is given by : sex of prod Hd S$ aSBC| aBC P BBC ah. | bC be, cC co string of the form a'b’c" can be generated as given below. s 5 a's(eoy""! {by applying S + aSBC, (n—1) times} =a" 'aBC(BC)""' [by applying § > aBC) =a’ 'abC(BO)""' [by applying aB > ab} = a""!abB"=!c" [by applying CB > BC, n— 1 times } = a'b"'bC" [by applying bB — bb several times} >a'b"'bec?! [by applying bC = be} = a'b"c" [by applying cC — ce several times ] .1 Type 0 or Unrestricted Grammar : ae Productions can be written without any restriction in a unrestricted grammar, If there is Action of the ct B, then length of o could be more than length of B. Every grammar also is a type 0 grammar. Atype 2 grammar is also a type | grammar Atype 3 grammar is also a type 2 grammar. | University Questions and Answers : | Give CFG for the following : 0) tablisjs2iiz1) (Example 4.2.8) ( Leable’ i+j=9,i,j21) (Example 4.2.9) (6 Marks) t Wie a note on simplification of grammars, (Section 4.4) (6 Marks) | Write an. unambiguous CFG for arithmetic expressions with operators ; ~+.").6, unary minus and operands a, b, ¢, d, €, f. ‘so, should be possible to generate brackets with your grammar. Ostive (a+ by’ d/e+ (- f) from your grammar. (Example 4.3.4) (10 Marks)Free Gr Theory of Computation (PUT) 4-86 _Context Free Grammar (CFG) ayy @.4 Give the GNF for following CFG. Q.10 a.11 Q.12 SAB A—BS|b B+ SA|a (Example 4.5.9) ( _ Write CFG for the following languages () b= (O'ro"|joi+k) (Example 4.2.13) (i) Matching parenthesis (Example 4.2.14) (iil) All strings with atleast 2 a's, 5 = (a,b) (Example 4.2.15) (10 ty ‘White a note on simplification of grammar. (Section 4.4) (6a Design a CFG, that 's unambiguous, for arithmetic expressions that consiss dt following operators +=) %, %,, () (Example 4.3.4) (8 Mart, Write CFGs for the following languages 1) = fa, b} number of a's = number of b's. tl) Z= (a, b) number of a's is a multiple of 3. (Examples 4.2.20, 4.2.32) (4 Mart) Find GNF equivatent to the CFG : ESE4T|T EoT*FIF F(E)/ (Example 4.5.8) (12 Mar) Write @ note on simpitication of grammar. (Section 44) (4 Mars) ‘Simplify the following grammar S-> Ab, A-+a,B-+C|b,C + D, DE, E-+a (Example 4.4.11) (6 Marks) Find CNF equivalent to: S aAbB, A> aA|a, B + DB |b (Example 4.5.1) (6 Maris) Wrkte a short note an ‘Ambiguous grammar’ (Section 4.2) (4 Maris)
You might also like
Context-Free Grammar (CFG) : Example 1
PDF
No ratings yet
Context-Free Grammar (CFG) : Example 1
9 pages
Unit 5 Toc
PDF
No ratings yet
Unit 5 Toc
56 pages
Derivation Trees
PDF
100% (2)
Derivation Trees
16 pages
CD - Sem 7 - GTU - Study Material - 15112016 - 100740AM PDF
PDF
50% (2)
CD - Sem 7 - GTU - Study Material - 15112016 - 100740AM PDF
100 pages
Nfa To Dfa C Code
PDF
100% (1)
Nfa To Dfa C Code
10 pages
Compiler Design Notes
PDF
100% (1)
Compiler Design Notes
156 pages
Getting Started With Competitive Programming - Unit 3 - Week 1
PDF
0% (1)
Getting Started With Competitive Programming - Unit 3 - Week 1
4 pages
Flat Unit-3
PDF
No ratings yet
Flat Unit-3
31 pages
Finite Automata (DFA and NFA, Epsilon NFA) : FSA Unit 1 Chapter 2
PDF
100% (1)
Finite Automata (DFA and NFA, Epsilon NFA) : FSA Unit 1 Chapter 2
24 pages
Daa Lecture Notes
PDF
No ratings yet
Daa Lecture Notes
120 pages
TOC Module 1 Complete Solutions
PDF
No ratings yet
TOC Module 1 Complete Solutions
31 pages
Module1 - Central Concepts of Automata
PDF
No ratings yet
Module1 - Central Concepts of Automata
21 pages
DAA Unit 5
PDF
No ratings yet
DAA Unit 5
29 pages
Unit V Undecidability: 5.1.1 Decidable Problem
PDF
No ratings yet
Unit V Undecidability: 5.1.1 Decidable Problem
23 pages
Turing Machine Notes
PDF
No ratings yet
Turing Machine Notes
11 pages
Unit 1 - Analysis and Design of Algorithm - WWW - Rgpvnotes.in
PDF
No ratings yet
Unit 1 - Analysis and Design of Algorithm - WWW - Rgpvnotes.in
19 pages
Module-3 Syntax Analyzer
PDF
No ratings yet
Module-3 Syntax Analyzer
80 pages
FALLSEM2020-21 CSE2002 TH VL2020210106983 Reference Material III 27-Aug-2020 CFGPDANOTES PDF
PDF
100% (1)
FALLSEM2020-21 CSE2002 TH VL2020210106983 Reference Material III 27-Aug-2020 CFGPDANOTES PDF
79 pages
Toc Important Questions
PDF
No ratings yet
Toc Important Questions
2 pages
Unit 2 TOC - CSE - 1595997221
PDF
No ratings yet
Unit 2 TOC - CSE - 1595997221
18 pages
Updated - Final ADS LAB MANUAL 21-22 - Finalized
PDF
No ratings yet
Updated - Final ADS LAB MANUAL 21-22 - Finalized
88 pages
Pushdown Automata (PDA) : Unit Iii-Push Down Automata
PDF
No ratings yet
Pushdown Automata (PDA) : Unit Iii-Push Down Automata
27 pages
Properties of Recurisve and Recursively Enumerable Languages PDF
PDF
100% (2)
Properties of Recurisve and Recursively Enumerable Languages PDF
2 pages
QB Compiler Design
PDF
100% (2)
QB Compiler Design
13 pages
DAA Notes PDF
PDF
No ratings yet
DAA Notes PDF
55 pages
Design and Analysis of Algorithms: III Year II-sem (CSE)
PDF
No ratings yet
Design and Analysis of Algorithms: III Year II-sem (CSE)
79 pages
Ant Ma8551 U1
PDF
No ratings yet
Ant Ma8551 U1
73 pages
Theory of Computation 1
PDF
No ratings yet
Theory of Computation 1
131 pages
Simplification of CFG: Presented To Presented by
PDF
100% (2)
Simplification of CFG: Presented To Presented by
12 pages
Gate Questions On DFA - Deterministic Finite Automaton - AcademyEra3 PDF
PDF
No ratings yet
Gate Questions On DFA - Deterministic Finite Automaton - AcademyEra3 PDF
3 pages
Compiler Design
PDF
No ratings yet
Compiler Design
31 pages
Theory of Computation and Automata
PDF
100% (1)
Theory of Computation and Automata
104 pages
@vtucode - in Module 2 ATC 5th Semester 2021 Scheme
PDF
0% (1)
@vtucode - in Module 2 ATC 5th Semester 2021 Scheme
49 pages
Compiler Design Left Recursion and Left Factoring
PDF
No ratings yet
Compiler Design Left Recursion and Left Factoring
14 pages
SPPU Pattern2019 Fds Unit 6
PDF
No ratings yet
SPPU Pattern2019 Fds Unit 6
32 pages
CD Unit-2
PDF
100% (1)
CD Unit-2
60 pages
PPL Mid-1 Mcq's
PDF
100% (1)
PPL Mid-1 Mcq's
5 pages
Theory of Computation
PDF
100% (1)
Theory of Computation
48 pages
1 Types of Parsers in Compiler Design
PDF
100% (1)
1 Types of Parsers in Compiler Design
4 pages
Formal Language and Automata Theory: UNIT-1
PDF
No ratings yet
Formal Language and Automata Theory: UNIT-1
38 pages
Cs6402 DAA Notes (Unit-3)
PDF
No ratings yet
Cs6402 DAA Notes (Unit-3)
25 pages
Context Free Grammar: 1. G (V, T, P, S)
PDF
No ratings yet
Context Free Grammar: 1. G (V, T, P, S)
37 pages
Assignment No. 1 Class: T.E. Computer Subject: Theory of Computation
PDF
No ratings yet
Assignment No. 1 Class: T.E. Computer Subject: Theory of Computation
6 pages
Theory of Computation - Part - B - Anna University Questions
PDF
100% (1)
Theory of Computation - Part - B - Anna University Questions
15 pages
Atcd Unit 1
PDF
No ratings yet
Atcd Unit 1
58 pages
Unit 1 TCS
PDF
No ratings yet
Unit 1 TCS
40 pages
Unit-5 Push Down Automata
PDF
No ratings yet
Unit-5 Push Down Automata
47 pages
Toc Unit Iv
PDF
No ratings yet
Toc Unit Iv
6 pages
TOC-UNIT - 1 (Written Notes)
PDF
No ratings yet
TOC-UNIT - 1 (Written Notes)
29 pages
Studocu DAA Unit 1 Notes
PDF
No ratings yet
Studocu DAA Unit 1 Notes
52 pages
Decode - (DM) Unit - 1
PDF
No ratings yet
Decode - (DM) Unit - 1
37 pages
Compiler Design Question Papers
PDF
No ratings yet
Compiler Design Question Papers
6 pages
Practice Questions CNF GNF PDA
PDF
No ratings yet
Practice Questions CNF GNF PDA
1 page
Types of Data Structure
PDF
No ratings yet
Types of Data Structure
8 pages
TOC Unit 3 Context Free Grammer
PDF
No ratings yet
TOC Unit 3 Context Free Grammer
58 pages
TOC UNIT 4 PDA (Pushdown Automata)
PDF
No ratings yet
TOC UNIT 4 PDA (Pushdown Automata)
56 pages
Unit 4 Question Bank Solutions-1
PDF
No ratings yet
Unit 4 Question Bank Solutions-1
11 pages
Theory of Computation Unit-1 - Notes
PDF
100% (15)
Theory of Computation Unit-1 - Notes
100 pages
CFG To PDA Conversion
PDF
No ratings yet
CFG To PDA Conversion
4 pages
DST Nirali Publication
PDF
No ratings yet
DST Nirali Publication
85 pages