0% found this document useful (0 votes)
65 views26 pages

TAFL Unit-3

The document provides a comprehensive overview of the Theory of Automata and Formal Languages, including concepts such as regular and non-regular grammars, context-free grammars (CFG), and automata theory. It covers definitions, derivations, properties, and programming problems related to finite automata, pushdown automata, and Turing machines. Additionally, it discusses simplification of CFGs, ambiguity in grammars, and various derivation techniques with examples.

Uploaded by

Sonal12a4080
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
0% found this document useful (0 votes)
65 views26 pages

TAFL Unit-3

The document provides a comprehensive overview of the Theory of Automata and Formal Languages, including concepts such as regular and non-regular grammars, context-free grammars (CFG), and automata theory. It covers definitions, derivations, properties, and programming problems related to finite automata, pushdown automata, and Turing machines. Additionally, it discusses simplification of CFGs, ambiguity in grammars, and various derivation techniques with examples.

Uploaded by

Sonal12a4080
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
You are on page 1/ 26
THEORY OF AUTOMATA AND FORMAL LANGUAGE _ (BCS-402) SIMPLE AND EASY EXPLANATION + HANDWRITTEN NOTES PDF Regular and Non-Regular Grammars: Context Free Grammar(CFG)-Definition, Derivations, Languages, Derivation Trees and Ambiguity, Regular Grammars-Right Linear and Left Linear grammars, Conversion of PA into CPG and Regular grammar into PA, Simplification of CFG, Normal Forms- Chomsky Normal Form(CNB), Greibach Normal UNIT-3 2 GNP, Chomsky Hierarehy, Programming problems based on the properties of CFs, (road ENGINEERING LExpRESS —) Theory of Automata and Formal Languages Basic Concepts and Automata Theory: Introduction to Theory of Computation- Automata, Computability and Complexity, Alphabet, Symbol, String, Formal Languages, Deterministic Finite Automaton (DFA)- Definition, Representation, Acceptability of a String and Language, Non Deterministic Finite Automaton (NFA), Equivalence of DFA and NFA, NFA with e-Transition, Equivalence of NFA’s with and without e-Transition, Finite Automata with output- Moore Machine, Mealy Machine, Equivalence of Moore and Mealy Machine, Minimization of Finite Automata. Regular Expressions and Languages: Regular Expressions, Transition Graph, Kleen’s Theorem, 1 | Finite Automata and Regular Expression- Arden’s theorem, Algebraic Method Using Arden’s, Theorem, Regular and Non-Regular Languages- Closure properties of Regular Languages, Pigeonhole Principle, Pumping Lemma, Application of Pumping Lemma, Decidability- Decision properties, Finite Automata and Regular Languages. Regular and Non-Regular Grammars: Context Free Grammar(CFG)-Definition, Derivations, nguages, Derivation Trees and Ambiguity, Regular Grammars-Right Linear and Left Linear grammars, Conversion of FA into CFG and Regular grammar into FA, Simplification of CFG, Normal Forms- Chomsky Normal Form(CNF), Greibach Normal Form (GNF), Chomsky Hierarchy, Programming problems based on the properties of CFGs. Push Down Automata and Properties of Context Free Languages: Nondeterministic Pushdown | Automata (NPDA)- Definition, Moves, A Language Accepted by NPDA, Deterministic Pushdown v Automata(DPDA) and Deterministic Context free Languages(DCFL), Pushdown Automata for Context Free Languages, Context Free grammars for Pushdown Automata, Two stack Pushdown Automata, Pumping Lemma for CFL, Closure properties of CFL, Decision Problems of CFL, Programming problems based on the properties of CFLs. ‘Turing Machines and Recursive Function Theory : Basic Turing Machine Model, Representation of v__ | Turing Machines, Language Acceptability of Turing Machines, Techniques for Turing Machine ‘Construction, Modifications of Tt Machine. Turing Machine as Computer of Integer Functions. Engineering Express Headline — Black Color Sub Headings — Orange Color Paragraph — Blue color | Note - Red color UNIT = 3 #REGULAR AND NON REGULAR GRAMMAR Context free grammar(CFG) CFG stands for context free grammar. It_is a formal grammar which is used to generate all possible patterns of string in_a given formal language. | Context free grammar is denoted by G. or Me icall ni ft he G=IV,TP,S]_ or Mu, %, P,S] or [MuVr,P,S] Where. V /Vy = 4 finite , non-empty set of variables(non-terminal) generally represented by capital letters. — 6.9. A,B,C,D.. ep =/ Vr / T = A finite , non-empty set of terminals(constant) generally represented by small letters. e.g. a,b,c. S= Starting non terminal cal) starting symbol of grammar. S eVy P= Set of rules or production values in CFG. E gineering Express |, Reverse subscription is not pebmltted If [S-> AB] is a production Then we can replace s by AB but we can’t replace AB by S. 2. No inversion operation is permitted, If [S-> AB] is a production , it is not necessary that AB->S is a production Notation used: We will use following notations:- alpha , beta , gamma !, All capital letters A,B,C... are use as variables 2. All small letters a,b,c... are use_as terminals 3.X,y,2,w denote string of terminal 4.08, y (alpha beta gamma) denote the elements of(Vu UE) "| ie. i includin I) staring S, Any symbol to the power zero is equivalent to null, That is, X= € (null) Where,X «Wy VU ) J If A is any set, then A” denotes the set of all string over A. A” _| denotes A*= fe? Where, € is the empty string ____|| Derivation _[ meaning of ‘->’= derive] = = sd If [a-> B]_Is a production in grammar ‘G’ ,then [a1=>B] is called || one step derivation or production If a-> a1=> a2=> a3.....=> an=> B Than n @ => 8 is called n step derivation, 6 Engineering Express The notation => Represents relation for grammar(G). G Eg= uestion|:-consider a grammar G define as G=CES? _,fa,b fs-> aS, S-> €2,5) Solution:-_we have, V,=S? z= fab? P= fs-> aS, S-> €} S= starting symbol S=>aS [by using S->aS] S=>aaS__ [by using S->aS] S=>aaaS [by using S->aS] S=>a"S [as a is repeats many time (n)] S=>a" € [by using S-> €] S=> a” S= starting symbol S=>0S) [by using S->0S1] S=200SIl_ [by using S->0SI] S=>000SIi)_ [by using S->0S1] S=>0"S!” [as a is repeats many time (n)] S=>0" € !” [by using S-> €] S=>0" |” Therefore, language L(G)=f0"!"|n>=0? Engineering Express estion3.- For generating a langu ‘hat_genera ual number of a’s and b in the form, a”b”, then CFG will be defined as. | G=CES,AP, fab? , £S-> ab, A->aAb/ £3) Solution:- given Vi=tSAP = = fab? P= £ S-> atb, A->aAb/ 7 a S=>aAb S=>aahbb S=>aaahbbb S=>aaa & bbb S=> a" & bP S=> a" br Therefore, language (Geta n>=0} Practice question, ____|| Questionl:- Consider a grammar _ ee | G=CES?, fab? , §S-> SS,7S) | Find L(G)=? aA ____|| Question2:- Consider a grammar _G=CES,A,B?,la,b3,P,5), where P ____|| consist of S-> aha, A-> baABb, B->Aab, ah->baa, bBb->abab | | test wether W=baabbabaaabba is in G Question3:- Constructors CFG for a language L= a” b’” where n>=! Engineering Express Derivation input string through these production rules. During parsing, we have to take two decisions. These are as follows, We have to decide the non terminal, which is to be replaced. Derivation in the seguence of production group. It is used to get the|| 2, || We have to decide the production rule by which the non terminal will be replaced. Derivation tree / Parse tree. Derivation tree is a graphical representation for the derivation of the | given production rule. For a given CFG, ____|| the derivation tree is also called parset tree. = ___ || The fe Hy 1e_pr ie ivati i __1, || The root node is always a node indicating start symbol. 2, || The derivation is used from left to right: 3, || The leaf nodes are always terminal nodes. __4, || The interior node are always the non-terminal nodes. __S. || The collection of leaves from left to right denotes the string W. | There are two types of derivation “oO Left_most derivation Right _most derivation. | [left to right] [right to left] Leftmost derivation:- If at each step we replace the left most variable by one of its production bodies, such derivation is called left_most derivation. Engineering Express Or The geometrical representation of leftmost derivation is called as a leftmost derivation tree. E.g:- given , S->aAB A->bBb B->A/€ Solution= S->aAB [by using S->ahB] S-> abBbB [by using A->bBb] S-> abe bB [by using B-> €] S-> abb € [by using B-> €] S-> abb 2 ig ivation:-_If variabl 1e_of i luctio| lies, such derivation i: ____|| called right most derivation: E.g:- given, S->aAB A->bBb B->A/€ (s) Solution= S->aAB using ahB S-> ah € [by using B-> ¢] S-> ah S-> abBb [by using A->bBb ] S-> abeb [by using B->€] S->abb Engineering Express Practice Question Question|:-Consider the production rule of a grammar ‘G’: S->S+S]S"S]alb, Find the left most and right most derivation for the string W:-a"atb and right most derivation using a CFG given by || Question2;-derive the string W.- aabbabba with left_most derivation || S-> aBlbA | A-> alaS|bAA B-> blbS]aBB _ #Derivation Form & Parse Tree | Questionl:- consider the grammar {S->bB /aA? __fA->b /bS J ahAR F $B a aS | bBB? For the string w=bbaababa, Find leftmost derivation , right most derivation, parse tree Solution:- * LEFT MOST DERIVATION:- S->bB S-> bbBB [by using B->bBB ] S->bbaB Lby using B->a ] S->bbaaS Lby using B->aS J S->bbaabB [by using S->bB ] S->bbaabaS [by using B->aS ] S->bbaababB [by using S->bB] S->bbaababa [by usingB->a] Engineering Express "RIGHT MOST DERIVATION S->bB S->bbBB [by using B->bBB d S->bbBaS Lhy using B->aS ] S->bbBabB Lby using S->bB J S->bbBabaS [by using B->aS ] S->bbBAbabB [by using S->bB ] S->bbBababa __[by usingB->a] ___ S->bbaababa aN Practice Question Questionl:- Consider the Grammar-_ S->AIB A->0A] € B->0B/IB] € For the string W=0010) find, left most derivation, roght most derivation , parse tree Question2:- Consider the Grammar-_ S->bAb|alb For the string W=bbabb find, left most derivation, roght most derivation , parse tree Engineering Express —ae A grammar G is said to be ambiguous if. The grammar produce HW more than one parsec tree for same string. An ambiguous grammar is one that produces more than one leftmost or rightmost derivation for same string. “NOTE 1, A Grammar G is unambiguous if there exist exactly one Parse Tree or left most derivation | Right most derivation for all string We LG) 2.1f @ Grammar G is ambiguous , it doesn’t mean language (L)is ambiguous | E.g= E->E+E Eo E E->id Find for the string w= id-+id*id Solution:- :Left_most derivation [ Parse Tree ] ! E->E+E [By using E->E+E ] E->id+E By using E->id E->id+E"E [By using E->E"E ] E->id+id"id [By using E->id ] 2. EEE [By using E->E*E ] E->E+E"E [By using E->E+E J E->idt+E*E [By using E->id ] E->id+id"E [By using E->id ] E->id+id"id [By using E->id ] Engineering Express ‘ion:- What is ambiguity? Sh S->aS|Sala is an Ambiguity grammar for the string w= aaa uestion:- Explain why the grammar below that generate strin S->0A]IB with an equal no of zeros A->0AAIS]I and one’s is ambiguous B->IBB]0S/0 W=0001I! #Simplification of CFG In CFG, sometimes all the production rules and symbols are not needed for the derivation of strings. Beside this, there may also be some null productions and unit productions. Elimination of these productions and symbol is called simplification of cfg. LE : inal of G ; Ae of some string in L 2, There should not be any production as X->Y where X and ¥ _are non terminal. Ye ee 3. If & is not in the language L then there is no need of thi production X-> € _____ Reduced a Grammar | a | 2 Remove of Elimination Removal of unit Useless symbols of € production production Engineering Express | Question:- G->C Vw , ©, P,S) where Vu=ES,T,X?; £=£0,)3; S->0TIITIOlI|x(Rule I) T->00(Rule 2) S->IT S->0 S->) S->X Solution:- _S->0T S->000 S->100 (Useful) (useful) | Cusefull)| Cuseful) |_Cuseful) Remove S->X Reduce grammar is Vni=0S,TP P->[S->0T | IT} 0] 1) r=(0,)7 S=> Starting Symbol T->00 ___|| Question:- Find CFG with no useless symbol Equivalent to C->aBlb | S->ABICA_; B->ACJAB_; A->a_; | Solution:- S->AB. S->CA B->BC B->AB A->a S->0B S->ba B->AB C->b S->aBC | i rom ee (Useless) | (useful) | (useless) | (useless) | (useless) P= _S->CA 3 C->b } A->a Wu= £5,A,C? x=fa,b? S-> Starting Symbol For practice Question Remove useless symbols from the following grammar S->aA|bB ; A->aAla_; B-> bB ; D->ablea ; € ->aCld ____|| Elimination of ¢ production:- If CFG non-terminal variable or | symbol a_is nullable variable, if there is a production A-> €_or there | is a derivation that starts at A and leads to €. Engineering Express := Find out all the nullproductio and then find out all nullable variables (If it directly produce A-> ¢_or after some steps , it generates null then that variable is called nullable variable) Step2:- After finding nullable variable , 90 to R.H.S of every variable and wherever that variable is present write that with it or without it, which means that with A or without A and than eliminate A-> &. Questionl:- Remove the null production S->ah _ sA->b] € Solution:- So if we replace S->a €. Lhy using A-> e] S->a Therefore , S->ab Ja A->b Question2:- consider the following grammar nd remove null prduction, S->ABAC ; A->aA| ¢ ; B->bB]e; — C->¢ Solution;- if we replace non terminals in S by giving values one by | one we get _ es S->ABAC A->ah -> 0 B->bB->b By using A-> € By using B-> S-> ABAC S-> ABAC S-> ABAC | By using A-> € By using B-> € By using A->€. S->BAC S->AAC ABC S-> ABAC S-> ABAC S-> ABAC | By usingC->c A]B->€| By using C->c A->€| By using AIB-> € S->Ac S->Be S->€ Engineering Express Therefore, S->ABAC AC JAAC ec c A->aAéla B->bB/b C->¢ Practice guestion Question:- consider the following grammar and remove the null }, S->aSa S->bSb] & 2, S->alXblaYa_ X->Y/ € Y->b] € | 3,S->AbbA rein ee A->ah|bAl € Removal _of unit production:- The unit production are the productions|| _ i id La, B € Vy "NOTE: Only variable to variable production is considered small letter and more than one variable is production is not considered Always remember there should produce same language before and after removal of unit vectors Engineering Express Eo = S->AB; A->a ; B->Clb; C->D ; D->E ; E->0 Solution= so unit variables are ;- B->C_; C->D ; D->E B->C->D->E->a ____|| That means we can replace all productions As S->AB A->a B->alb C->a D->a E->a Therefore , the new productions are S->AB A->a _B->alb | E.g= S->aA/B A->balbb B->A|bba Solution:- the unit productions are S->B B->4 S->B->A | That means we replace all productions are rah S->albbalba|bb 4A->balbb B->bbalbalbb Therfore , the new productions are_S->a|bbalbalbb A->balbb Engineering Express Practice Questions Questionl:- consider CFG and remove unit production S->Albb ; A->Blb ; B->Sla Question2:- S->0A]IBJC _A->0S/00__B->I]A___C->0) Then remove the unit vector #Normal Forms of CFG |. Chomsky Normal Form (CNF) 2. Greiback Normal Form (GNF) Chomsky Normal Form (CNF):- j iy ONES INED ; rules are of types- |, ->_ < Terminal > 2, -> _ Eg N KIN ne eo A->a ; A->AB e S->BAla ; B->q ; A->b e S->AB/BD_; A->CDJaJAC ; B->b ; C->DE ; D->d ; E->f Algorithm to convert CFG to CNF. Stepl:- If start symbol occurs on RHS of production rule, create a new start symbol s’ & a new production as a S’->S Step2:- Remove null production. Step3:- Remove unit production. Step4:- If RH.S pf production contains more than 2 variables then two consecutive variables can be replaced by a new variable . E.g = A->XY2_ => A->XP. or A->P2 P->Y2 P->XY Engineering Express s- IF RHS of ‘ion contains combination of terminal an variables then each terminal symbols is replaced by new variable E.g= A->aB => A->XB X->a Question:- Convert equivalent CNf for given CFG S->aSalbSb]alb Solution:- Since _S apperas in RHS , we add new production , we have:- S’->S__ (not in CNF) S->aSa__(not in CNF) S->bSb (not in CNF) S->a___ (CNF) S->b _ (CNF) No nulllunit production ic => =>) ee ere ; 3 We have S->AX And S->BY X->SA Y->SB A->qB->b Find production set we obtain is as follows :- £S°->AX|BY ; S->AX]BY]alb X->SA Y->SB | A->a NL Practice Question Questionl:- convert the given CFG to CNF S->aAD A->aB/bAB B->b D->a Question2:- convert CFG to CNF S->aAbB A->ahla B->bBl/b

You might also like