You are on page 1of 17
Q11 Define derivation . Mention the different types of derivation. Derivation is a sequence of production rules. It is used to get input strings. During parsing, we have to take two decisions, which are as follows ‘e We have to decide the non-terminal which is tobe replaced. fe We have to decide the production rule by which the non-terminal will be replaced. Two options to decide which non-terminal has to be replaced with the production rule are as follows ~ ‘@ Left most derivation ‘e Right most derivation. Left Most Derivation In the leftmost derivation, the input is scanned and then replaced with the production rule from left side to right. So, we have to read. thet input string from left to right, Example Production rules: E=E+E rulet E=£-E£ rule2 E=alb rules Let the input be a-btra Now, when we perform the Left Most Derivation, the result will be as follows ~ E=E+E E=£-E+E from rule2 E=a-E+E from rule3 E=a-b+E from rule3 E=a-b+a from rule3 Finally, the given string is parsed Right Most Derivation In Right most derivation, the input is scanned and replaced with the production rule right to left. So, we have to read the input string from right to left. Example Production rule: E=E+E rule1 E-E rule2 =a|b rule3 Let the input be a-b+a Now, when we perform the Right Most Derivation, we get the following result - -E -E+E from rule1 -E+a from rule3 -b+a from rule3 -b+a from rule3 Qes 2 . State any two properties of CFL's. Closure properties : The context-free languages are closed under some specific operation, closed means after doing that operation on a context-free language the resultant language will also be a context-free language Some such operation are: 1. Union Operation 2. Concatenation 3. Kleene closure 4. Reversal operation 5, Homomorphism 6. Inverse Homomorphism Decision Properties: 1. Test for Membership: Decidable, 2. Test for Emptiness: Decidable 28. Test for finiteness: Decidable Rest the decision properties of context-free language. undegigfable in Deterministic property The context-free languagéeah be: 1. DCFL-Deterministic (which can be recognized by deterministic pushdown automata) context-free language 2, NDCFL-Non-deterministic (can't be recognized by DPDA but NPDA) context froe language. Concatenation If Ly and Lg are context free languages, then LyL2. is also context free. Union Let Ly and Lz be two context free languages. Then Ly ULg Is also context free. Kleene Star IFL is a context free language, then L* is also context free State and prove the pumping lemma for regular languages. 10. Difference between Chomsky Normal Form (CNF) and Greibach Normal Form (GNF)? (CNE (Chomsky Normal Ferm) and GNF (Greibach Normal Form) are both forms used in the context of formal grammars, specifically in the feld of theoretical ‘computer science and formal language theary, These narmal forms define specific restrictions and structures for grammars, making them easier to analyze and process. Here are the differences between CNF and GNF: 1. Chomsky Normal Form (CNF): ~ Inv CNF. ail production ules (productions) ofa grammar are in one of yw Tolmns 1.A+BC [where A,B, and Care nerterminal symbels) 2.Ax a (where A isa non-terminal symbol and @ is terminal sfipbel ENF prohibits production ules with (empty sting) on they lgh-hand side ~CNF allows for productions that directly derive e termifal Symbol ENF does not allow for unit productions {produetions where a single nonterminal symbol derives another non-terminal symbol. 2 Greibach Normal ‘orm (GNF): In. GNE, all production rules (pradyétidns) of a grammar ate in the form: 1. Aaa (where A is.@ non-teAnihal symbol, a is a terminal symbol, and iis @ sting of ‘an-terminal symbols) GNF allows for productions that directly derive a terminal symbol GNF allows for unit productions (productions where a single non-terminal symbol enves another nen-terminal symo). GNF prohibits the presence of (empty string) as a right-hand side of a production. In summary, CNF and GNF are different forms that impose different restrictions on the structure of production rules ina grammar. CNF disallows e-productions and unit productions, while GNF allows unit preduetions but prohibits e-productions, Beth forms have thelr own advantages and applications in formal language theory and parsing algorithms. 11. Whatis Derivation trees? How many types of derivation trees are there Pe Example: For the Grammar 6={V,TP.$} where $~OB, A-1AAle, 8~OAA Root Vertex: Must be labelled by the Start Symbol Pee ees reas Dee See eee ed 12. Difference between deterministic and non-deterministic PDA Difference between NPDA and DPDA: DPOA(Determinstic Pushdown Automata) Ie stess powerful than NPOA camels We canony 1. constrict DPDA for coeeength palindromes and not foreveniength patndiomes Intepossile to convert every DPDA toacoresponaing NPOA. NPDA(Non- deterministic Pushdown Automata) Ite more powerful than Poa. somal: NPDACcan be conetucted for both even length and odctongtn palingsomes posotie to convert every NPDAtoa comtesponting Poa. The language accepted by NPDA is not a The language accepted by DPDA is a subset of the subset of the language accepted | language by NDPA, accepted by DPDA. The language accepted by DPDA is called DCFL(Deterministio\ Context-Free | Language) wii a subset of NoFL(Non- deleninistic Context-free The language accepted by NPDA is called NCFL(Non- deterministic Context-free Language). ‘SEanguage) accepted by NPDA. ‘There may or maynot be ‘more than one ‘There is only one state tranattion from state transition 5. | one state to another state for an input ‘symbol fromone state to another state forsame Input symbol. ‘There is one more difference as follows: PDA: For every input with the current state, ‘there only one move, M=(Q7790.2F 2) norma & NPDA: For every input with the ore We can have multiple moves. cy oO M= (Q2,2.40,2ZF,?) KS arempnn20gr Non: Deterministic path 13. Chomsky Classification of Languages can be expressed in how many ways? Chomsky Hierarchy in Theory of Computation According to Chomsky hierarchy, grammar is divided into 4 types as follows: 1. Type 0 is known as unrestricted grammar. 2. Type 1 is known as context-sensitive grammar. 3. Type 2 is known as a context-free grammar. 4. Type 3 Regular Grammar. LUnristigael Gsafnmar ine eet Si sate é am Typed \ (Accepted by Linear - sons Context Free Grammar (Accepted by Push ‘Down Automata) Regular Grammar 14. What are the Applications of various Automata? Explain Applications of different Automata ‘The applications of the different automata in Toc are explained below ~ Fh fe Automata (FA) ‘The applications of Finite Automata are as follows ~ @ Design of the lexical analysis of a compiler. e Recognize the pattem by using regular expressions. e Use of the Mealy and Moore Machines for designing the combination and sequential circuits. e Helpful in text editors. Used for spell checkers. Push Down Automata (PDA) The applications of Pushdown automata are as follows ~ Used in the Syntax Analysis phase, Implementation of stack applications. @ Used in evaluations of the arithmetic expressions, @ Used for salving the Tower of Hanoi Problem. Linear Bounded Automata (LBA) The applications of linear bounded automata are as follows ~ @ Used in the genetic programming implementation. e Construction of syntactic parse trees. Turing Machine (TM) The applications of Turing machine are as follows - e@ Used to solve the recursively enumerable problem. e@ Used for knowing complexity theory. e@ Used for neural networks implementation. e@ Used in Robotics Applications. e@ Used in the implementation of artificial intelligence. 15. Ambiguity Grammaris what? Explain with an exampl Ambiguous grammar: A CFG is said to be ‘ambiguous if there exists more than one derivation tree for the given input string le, more than one LeftMost Derivation Tree (LMDT) or RightMost Derivation Tree (RMDT). Definition: ¢ = (VITPS) is @ CFG that ls sald to be ambiguous if ‘and only if there exists a string in T* that has ‘more than one parse tree. where Vis a finite set, of variables, Tis a finite set of terminals. Pis a finite set of productions of the form, A-> ?, where Aisa variable and ?? (V?)*Sisa designated variable called the start symbol For Example: Let us consider this grammar: E -> EtElid We can create a 2 parse tree from this grammar to obtain a string id+id+id. The followingvare the 2 parse trees generated by left-mostderivation: Both the above parse trees are derived from the same grammar rules but both parse trees are different. Hence the grammar is ambiguous. 2. 16. What is grammar? How can we classify it? Grammar Wis a finite set of formal rules for generating syntactically correct sentences or meaningful correct sentences. Constitute Of Grammar Grammars basically composed of two basic elements ~ 1. Terminal symbots ~ “Terminal symbols are those which are the ‘componente ofthe eentences generated using a grammar and are represented using small case letter ike a,b, cet. 2, Non-Terminal Symbols ~ 'Non-Terminal Symbols are those symbols \Wihich take part in the generation of the ‘sentence but are not the component ofthe ‘sentence, Non-Terminal Symbols are also called Auxiliary Symbols and Variables. These symbols are represented using a capital letter Tike A,B,C, et. Formal Definition of Grammar : Any Grammar can be represented by" tuples + N~Finite Non-Empty Set of Non-Terminal symbols. + T-Finite Set of Terminal Symbols. + P Finite Non-Empty Set of Production Rules. + S~Start Symbol (Symbol from where we start producing our sentences or strings). Different Types Of Grammars : Grammar can be divided on basis of - « Type of Production Rules « Number of Derivation Trees « Number of Strings On the basis of Types of Grammar On the basis of Number Type of Production Rules °f derivation Trees > Type 0 [> Type-t > Type2 +> Type-3 [> Ambigous Grammar |» Uiambigous Grammai On the basi ‘Number of Strings — [> Recursive Grammar |-»Non-Recursive Grammar 19. Write an algorithm for construction of CFG to given PDA? Pe Identify Terminal and Non-Terminal rich may a 2, Construct Productions for ¢-Transitions: COCR ny Pera er Xp, where Xq and ree =%q Pers Ces Pee ese Tic eZ eae Cas For each transition 6(q, a, X) in the PD) Pro) a Dee cary state (other than the initial state), Cee ct Moteur ae Pec ma Choma ee sont rs tea eon) eee eect Seneca eee atoann CeCe anc} Ceres a acl Rae Crete] yaa If the PDA has a final state F, create a production rule for each state q leading to F through a sequence of transitions: = Xq = €, where Xq is a non-terminal representing state q. 5. Combine Productions (Optional): Optionally, merge productions with identical left-hand sides (non-terminals) to create a more concise CFG.

You might also like