Chomsky Hierarchy
What is Chomsky Hierarchy? The classification of languages into 4 classes; the description of the grammar for each class, and the machine that can recognize the grammar / language. 2
The Chomsky Hierarchy Type Language Grammar Automaton 0 Recursively Computable 1 Context Sensitive Unrestricted Context Sensitive 2 Context Free Context Free NPDA Turing Machine Linearly Bounded Automaton 3 Regular Regular DFA, NFA You don t have to know this Type3 Type2 Type1 Type0
Definition of Grammars A grammar G is defined as a quadruple : G = (V,, P, S) where: V is a finite set of variables (the alphabet) is a finite set of terminal symbols, where V = P is a finite set of rules (production rules) S is the start symbol, S V 4
Unrestricted Grammars: Productions u v String of variables String of variables Note: All variables written in capital case. All terminals written in lower/small case. 5
Example of Unrestricted Grammar: G = ({S, A, B}, {a, c, d}, P, S) 1 P: S abc ab ca Ac d 6
Another example of unrestricted grammar: A grammar that generates {a i b i c i i 0}. G = (V,, R, S) where V = {S, A, C}, = {a, b, c} R = { S aabc A aabc Cb bc Cc cc } S aabc aaabcbc aabbcc aabbcc
Another example of unrestricted grammar: G 2 = ({S, A, B, C, D, E}, {a}, P, S) P: S ACaB Ca aac CB DB E ad Da AAD AC ae Ea AE 8
Context-Sensitive Grammars: Productions u v String of variables String of variables and: u v 9
Example of Context-Sensitive Grammar: G 1 = ({S, A, B}, {a, b}, P, S) P: S abc aabc Ab ba Aa Bbcc bb Bb ab aa aaa 10
Context-Free Grammars: Productions u v Variable u V String of variables v (V )* 11
Example of Context-Free Gramar: G 1 = ({S, A}, {a, b}, P, S) P: S AA A AAA ba Ab a G 2 = ({S, B}, {a, b}, P, S) P: S asa aba B bb b G 3 = ({S, A}, {a, b}, P, S) P: S absa A Aa 12
Regular Grammars: A regular grammar is a CFG in which each rule has one of the following form: 1. A a 2. A ab 3. A λ where A, B V, and a Σ 13
Example of Regular Grammar: G 1 = ({S,A,B}, {a,b}, P, S) P: S ab B bs ba A aa 14
The Chomsky Hierarchy Recursively Enumerable Languages Context Sensitive Languages Context Free Languages Regular Languages {a n b n c n, n 0} {a n b n c n, n 0} {a n b n, n 0} {a m b n, m, n 0}
The Chomsky Hierarchy Take note that: regular grammar, context-free grammar, context sensitive grammar; are also unrestricted grammar.
Summary Grammar For Production u v, u can be Unrestricted String of variables For Production u v, v can be String of variables Rules P: S abc ab ca Ac d Context Sensitive String of variables Context Free Single Variable String of variables String of variables Regular Single Variable String of one or more terminal or one or more terminal, followed by a variable or P: S abc aabc Ab ba Aa Bbcc bb Bb ab aa aaa P: S asa aba B bb b P: S ab B bs ba A aa
1. a i b j 2. a i b j c i d j 3. a i b j c i d j e i f j 4. a i b j c k d i e j f k
S abc Ab ba AA Bbcc B Bb ab aa aaa aa S aa Regular / C.Free / C.Sensitive / Unrestricted Regular / C.Free / C.Sensitive / Unrestricted Regular / C.Free / C.Sensitive / Unrestricted Regular / C.Free / C.Sensitive / Unrestricted Regular / C.Free / C.Sensitive / Unrestricted Regular / C.Free / C.Sensitive / Unrestricted Regular / C.Free / C.Sensitive / Unrestricted