chomsky hierarchy language operations and properties
TRANSCRIPT
Chomsky Hierarchy
2
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.
The Chomsky Hierarchy
Type Language Grammar Automaton
0 Recursively Computable
Unrestricted Turing Machine
1 Context Sensitive
Context Sensitive
Linearly Bounded Automaton
2 Context Free Context Free NPDA
3 Regular Regular DFA, NFA
0 Type 1 Type 2 Type 3 Type
You don’t have to know this
4
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
5
Unrestricted Grammars:
Productions u v
String of variables and terminals
String of variables and terminals
Note: All variables written in capital case. All terminals written in lower/small case.
6
Example of Unrestricted Grammar:
G1 = ({S, A, B}, {a, c, d}, P, S) P: S aBc aB cA Ac d
A grammar that generates {aibici | 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:
8
Another example of unrestricted grammar:
G2 = ({S, A, B, C, D, E}, {a}, P, S)
P: S ACaB
Ca aaC
CB DB | E
aD Da
AAD AC
aE Ea
AE
9
Context-Sensitive Grammars:
and: |u| |v|
Productions u v
String of variables and terminals
String of variables and terminals
10
Example of Context-Sensitive Grammar:
G1 = ({S, A, B}, {a, b}, P, S) P: S abc aAbc Ab bA Aa Bbcc bB Bb aB aa aaA
11
Context-Free Grammars:
Productions
Variable u V
String of variables and terminals v (V )*
u v
12
Example of Context-Free Gramar:
G1 = ({S, A}, {a, b}, P, S) P: S AA A AAA | bA | Ab | a
G2 = ({S, B}, {a, b}, P, S) P: S aSa | aBa B bB | b
G3 = ({S, A}, {a, b}, P, S) P: S abSA | A Aa |
13
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 Σ
14
Example of Regular Grammar:
G1 = ({S,A,B}, {a,b}, P, S)
P: S aB |
B bS | bA
A aA |
The Chomsky Hierarchy
Context Free Languages
Context Sensitive Languages
Recursively Enumerable Languages
{anbn , n ≥ 0}
Regular Languages
{anbncn , n ≥ 0}
{ambn , m, n ≥ 0}
{anbncn , n ≥ 0}
The Chomsky Hierarchy
Take note that: regular grammar, context-free grammar, context sensitive grammar; are also unrestricted grammar.
Summary
Grammar For Production uv, u can be
For Production uv, v can be
Rules
Unrestricted String of variables and terminals
String of variables and terminals
P: S aBc aB cA Ac d
Context Sensitive
String of variables and terminals
String of variables and terminals
P: S abc aAbc Ab bA Aa Bbcc bB Bb aB aa aaA
Context Free Single Variable String of variables and terminals
P: S aSa | aBa B bB | b
Regular Single Variable
String of one or more terminal or one or more terminal, followed by a variable or
P: S aB | B bS | bA A aA |
1. aibj
2. aibjcidj
3. aibjcidjeifj
4. aibjckdiejfk
• S abc Regular / C.Free / C.Sensitive / Unrestricted
• Ab bA Regular / C.Free / C.Sensitive / Unrestricted
• AA Bbcc Regular / C.Free / C.Sensitive / Unrestricted
• B Bb Regular / C.Free / C.Sensitive / Unrestricted
• aB aa Regular / C.Free / C.Sensitive / Unrestricted
• aaA aa Regular / C.Free / C.Sensitive / Unrestricted
• S aA Regular / C.Free / C.Sensitive / Unrestricted