Context Sensitive Grammar
Total Page:16
File Type:pdf, Size:1020Kb
Context Sensitive Grammar Aparna S Vijayan Department of Computer Science and Automation December 2, 2011 Aparna S Vijayan (CSA) CSG December 2, 2011 1 / 12 1 Definition of CSG 2 Context Sensitive Language(CSL) 3 Example of CSL 4 Chomsky Hierachy Contents Aparna S Vijayan (CSA) CSG December 2, 2011 2 / 12 2 Context Sensitive Language(CSL) 3 Example of CSL 4 Chomsky Hierachy Contents 1 Definition of CSG Aparna S Vijayan (CSA) CSG December 2, 2011 2 / 12 3 Example of CSL 4 Chomsky Hierachy Contents 1 Definition of CSG 2 Context Sensitive Language(CSL) Aparna S Vijayan (CSA) CSG December 2, 2011 2 / 12 4 Chomsky Hierachy Contents 1 Definition of CSG 2 Context Sensitive Language(CSL) 3 Example of CSL Aparna S Vijayan (CSA) CSG December 2, 2011 2 / 12 Contents 1 Definition of CSG 2 Context Sensitive Language(CSL) 3 Example of CSL 4 Chomsky Hierachy Aparna S Vijayan (CSA) CSG December 2, 2011 2 / 12 Definition Context Sensitive Grammar(Type1 Grammar) A context-sensitive grammar (CSG) is an unrestricted grammar in which every production has the form α ! β with jβj ≥ jαj (where α and β are strings of nonterminals and terminals). The concept of context-sensitive grammar was introduced by Noam Chomsky in the 1950. In every derivation the length of the string never decreases. The term "context-sensitive" comes from a normal form for these grammars,where each production is of the form α1Aα2!α1βα2,with β 6= . They permit replacement of variable A by string β only in the "context " α1 - α2. Aparna S Vijayan (CSA) CSG December 2, 2011 3 / 12 N=Set of non terminal symbols. Σ=Set of terminal symbols. S=Start symbol of the production. P=Finite set of productions. All rules in P are of the form α1Aα2!α1βα2. A 2 N ( A is a single nonterminal) + α1; α2; β 2 (N [ Σ) . Formal Definition A Context Sensitive Grammar is a 4-tuple , G = (N,Σ, P, S) where: Aparna S Vijayan (CSA) CSG December 2, 2011 4 / 12 Σ=Set of terminal symbols. S=Start symbol of the production. P=Finite set of productions. All rules in P are of the form α1Aα2!α1βα2. A 2 N ( A is a single nonterminal) + α1; α2; β 2 (N [ Σ) . Formal Definition A Context Sensitive Grammar is a 4-tuple , G = (N,Σ, P, S) where: N=Set of non terminal symbols. Aparna S Vijayan (CSA) CSG December 2, 2011 4 / 12 S=Start symbol of the production. P=Finite set of productions. All rules in P are of the form α1Aα2!α1βα2. A 2 N ( A is a single nonterminal) + α1; α2; β 2 (N [ Σ) . Formal Definition A Context Sensitive Grammar is a 4-tuple , G = (N,Σ, P, S) where: N=Set of non terminal symbols. Σ=Set of terminal symbols. Aparna S Vijayan (CSA) CSG December 2, 2011 4 / 12 P=Finite set of productions. All rules in P are of the form α1Aα2!α1βα2. A 2 N ( A is a single nonterminal) + α1; α2; β 2 (N [ Σ) . Formal Definition A Context Sensitive Grammar is a 4-tuple , G = (N,Σ, P, S) where: N=Set of non terminal symbols. Σ=Set of terminal symbols. S=Start symbol of the production. Aparna S Vijayan (CSA) CSG December 2, 2011 4 / 12 All rules in P are of the form α1Aα2!α1βα2. A 2 N ( A is a single nonterminal) + α1; α2; β 2 (N [ Σ) . Formal Definition A Context Sensitive Grammar is a 4-tuple , G = (N,Σ, P, S) where: N=Set of non terminal symbols. Σ=Set of terminal symbols. S=Start symbol of the production. P=Finite set of productions. Aparna S Vijayan (CSA) CSG December 2, 2011 4 / 12 Formal Definition A Context Sensitive Grammar is a 4-tuple , G = (N,Σ, P, S) where: N=Set of non terminal symbols. Σ=Set of terminal symbols. S=Start symbol of the production. P=Finite set of productions. All rules in P are of the form α1Aα2!α1βα2. A 2 N ( A is a single nonterminal) + α1; α2; β 2 (N [ Σ) . Aparna S Vijayan (CSA) CSG December 2, 2011 4 / 12 If G is a Context Sensitive Grammar then ∗ + L(G)= w (w 2 Σ ) ^ S )G w . Eg 1 of a context sensitive grammar G = ffS; A; B; C; a; b; cg ; fa; b; cg ; P; Sgwhere P is the set of rules. S! aSBC S ! aBC CB ! BC aB ! ab bB ! bb bC ! bc cC !cc The language generated by this grammar is fanbncnjn ≥ 1g : Context Sensitive Language The language generated by the Context Sensitive Grammar is called context sensitive language. Aparna S Vijayan (CSA) CSG December 2, 2011 5 / 12 Eg 1 of a context sensitive grammar G = ffS; A; B; C; a; b; cg ; fa; b; cg ; P; Sgwhere P is the set of rules. S! aSBC S ! aBC CB ! BC aB ! ab bB ! bb bC ! bc cC !cc The language generated by this grammar is fanbncnjn ≥ 1g : Context Sensitive Language The language generated by the Context Sensitive Grammar is called context sensitive language. If G is a Context Sensitive Grammar then ∗ + L(G)= w (w 2 Σ ) ^ S )G w . Aparna S Vijayan (CSA) CSG December 2, 2011 5 / 12 Context Sensitive Language The language generated by the Context Sensitive Grammar is called context sensitive language. If G is a Context Sensitive Grammar then ∗ + L(G)= w (w 2 Σ ) ^ S )G w . Eg 1 of a context sensitive grammar G = ffS; A; B; C; a; b; cg ; fa; b; cg ; P; Sgwhere P is the set of rules. S! aSBC S ! aBC CB ! BC aB ! ab bB ! bb bC ! bc cC !cc The language generated by this grammar is fanbncnjn ≥ 1g : Aparna S Vijayan (CSA) CSG December 2, 2011 5 / 12 S ) aSBC ) aaBCBC ) aabCBC ) aabBCC ) aabbCC ) aabbcC ) aabbcc Context Sensitive Language The derivation for the string aabbcc is Aparna S Vijayan (CSA) CSG December 2, 2011 6 / 12 ) aaBCBC ) aabCBC ) aabBCC ) aabbCC ) aabbcC ) aabbcc Context Sensitive Language The derivation for the string aabbcc is S ) aSBC Aparna S Vijayan (CSA) CSG December 2, 2011 6 / 12 ) aabCBC ) aabBCC ) aabbCC ) aabbcC ) aabbcc Context Sensitive Language The derivation for the string aabbcc is S ) aSBC ) aaBCBC Aparna S Vijayan (CSA) CSG December 2, 2011 6 / 12 ) aabBCC ) aabbCC ) aabbcC ) aabbcc Context Sensitive Language The derivation for the string aabbcc is S ) aSBC ) aaBCBC ) aabCBC Aparna S Vijayan (CSA) CSG December 2, 2011 6 / 12 ) aabbCC ) aabbcC ) aabbcc Context Sensitive Language The derivation for the string aabbcc is S ) aSBC ) aaBCBC ) aabCBC ) aabBCC Aparna S Vijayan (CSA) CSG December 2, 2011 6 / 12 ) aabbcC ) aabbcc Context Sensitive Language The derivation for the string aabbcc is S ) aSBC ) aaBCBC ) aabCBC ) aabBCC ) aabbCC Aparna S Vijayan (CSA) CSG December 2, 2011 6 / 12 ) aabbcc Context Sensitive Language The derivation for the string aabbcc is S ) aSBC ) aaBCBC ) aabCBC ) aabBCC ) aabbCC ) aabbcC Aparna S Vijayan (CSA) CSG December 2, 2011 6 / 12 Context Sensitive Language The derivation for the string aabbcc is S ) aSBC ) aaBCBC ) aabCBC ) aabBCC ) aabbCC ) aabbcC ) aabbcc Aparna S Vijayan (CSA) CSG December 2, 2011 6 / 12 Example2 CSG L = (#a = #b = #c) G2 =(fS; A; B; C; a; b; cg ; fa; b; cg ; P; S) S! ABC S !ABCS AB! BA AC ! CA BC ! CB BA ! AB CA !AC CB ! BC A ! a B !b C !c Aparna S Vijayan (CSA) CSG December 2, 2011 7 / 12 Hierarchy of Formal Languages Aparna S Vijayan (CSA) CSG December 2, 2011 8 / 12 Relation between Formal Languages The CFL's not containing are properly contained in the context sensitive languages Not all Context Sensitive Languages are Context Free. Every Context Sensitive Language is recusive. Aparna S Vijayan (CSA) CSG December 2, 2011 9 / 12 Chomsky Hierachy Described by Chomsky in 1956. Four classes of language Type 3,Type2,Type1,Type 0 from most restrictive to most general(Unestricted). Each level of hierarchy can be characterized by a class of grammar. Aparna S Vijayan (CSA) CSG December 2, 2011 10 / 12 Chomsky Hierarchy Type Language productions Device 3 Regular A ! aB, A ! a Finite Automaton 2 CFL A ! α Pushdown Automaton 1 CSL α ! β,jβj ≥ jαj Linear Bounded Automaton 0 RE α ! β Turing Machine A,B! Nonterminals α,β! string of terminals and nonterminals a! terminal symbol Aparna S Vijayan (CSA) CSG December 2, 2011 11 / 12 References Introduction to Automata Theory Languages and Computation by "JOHN E HOPCROFT","JEFFERY D.ULLMAN". Introduction to Languages and the Theory of Computation "JOHN MARTIN" http://en.wikipedia.org/wiki/Context-sensitive grammar http://adammikeal.org/courses/compute/Chomsky Aparna S Vijayan (CSA) CSG December 2, 2011 12 / 12 Linear Bounded Automata Indu John Department of Computer Science and Automation Indian Institute of Science, Bangalore December 1, 2011 Indu John (Department of CSA) Linear Bounded Automata December 1, 2011 1 / 14 Definition Results about LBAs CSLs and LBAs Overview Indu John (Department of CSA) Linear Bounded Automata December 1, 2011 2 / 14 Results about LBAs CSLs and LBAs Overview Definition Indu John (Department of CSA) Linear Bounded Automata December 1, 2011 2 / 14 CSLs and LBAs Overview Definition Results about LBAs Indu John (Department of CSA) Linear Bounded Automata December 1, 2011 2 / 14 Overview Definition Results about LBAs CSLs and LBAs Indu John (Department of CSA) Linear Bounded Automata December 1, 2011 2 / 14 Definition A Turing machine that uses only the tape space occupied by the input is called a linear-bounded automaton (LBA). A linear bounded automaton is a nondeterministic Turing machine M = (Q; Σ; Γ; δ; s; t; r) such that: There are two special tape symbols < and >(the left end marker and right end marker).