<<

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 You don’t The Chomsky Hierarchy have to know this Type Language Grammar Automaton 0 Recursively Unrestricted Computable 1 Context Context Linearly Bounded Sensitive Sensitive Automaton 2 Context Free Context Free NPDA 3 Regular Regular DFA, NFA

Type 3  Type 2  Type 1  Type 0 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 , S  V 4 Unrestricted Grammars: Productions u  v

String of variables String of variables and terminals and terminals

Note: All variables written in capital case.

All terminals written in lower/small case. 5 Example of :

G1 = ({S, A, B}, {a, c, d}, P, S) P: S  aBc aB  cA Ac  d

6 Another example of unrestricted grammar:

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:

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   8 Context-Sensitive Grammars: Productions u  v

String of variables String of variables and terminals and terminals

and: |u|  |v|

9 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

10 Context-Free Grammars: Productions u  v

Variable String of variables u  V and terminals v  (V   )* 11 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 |  12 Regular Grammars:

A 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:

G1 = ({S,A,B}, {a,b}, P, S) P: S  aB |  B  bS | bA A  aA | 

14 The Chomsky Hierarchy

Recursively Enumerable Languages {anbncn , n ≥ 0}

Context Sensitive Languages {anbncn , n ≥ 0} Context Free Languages {anbn , n ≥ 0}

Regular Languages {ambn , 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 For Production Rules uv, u can be uv, v can be Unrestricted String of variables String of variables P: S  aBc and terminals and terminals aB  cA Ac  d Context String of variables String of variables P: S  abc  aAbc and terminals and terminals Ab  bA Sensitive Aa  Bbcc bB  Bb aB  aa  aaA Context Free Single Variable String of variables P: S  aSa | aBa and terminals B  bB | b Regular Single Variable String of one or more P: S  aB |  terminal or one or more B  bS | bA A  aA |  terminal, followed by a variable or  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