chomsky hierarchy language operations and properties

19
Chomsky Hierarchy

Upload: others

Post on 16-Oct-2021

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chomsky Hierarchy Language Operations and Properties

Chomsky Hierarchy

Page 2: Chomsky Hierarchy Language Operations and Properties

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.

Page 3: Chomsky Hierarchy Language Operations and Properties

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

Page 4: Chomsky Hierarchy Language Operations and Properties

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

Page 5: Chomsky Hierarchy Language Operations and Properties

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.

Page 6: Chomsky Hierarchy Language Operations and Properties

6

Example of Unrestricted Grammar:

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

Page 7: Chomsky Hierarchy Language Operations and Properties

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:

Page 8: Chomsky Hierarchy Language Operations and Properties

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

Page 9: Chomsky Hierarchy Language Operations and Properties

9

Context-Sensitive Grammars:

and: |u| |v|

Productions u v

String of variables and terminals

String of variables and terminals

Page 10: Chomsky Hierarchy Language Operations and Properties

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

Page 11: Chomsky Hierarchy Language Operations and Properties

11

Context-Free Grammars:

Productions

Variable u V

String of variables and terminals v (V )*

u v

Page 12: Chomsky Hierarchy Language Operations and Properties

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 |

Page 13: Chomsky Hierarchy Language Operations and Properties

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 Σ

Page 14: Chomsky Hierarchy Language Operations and Properties

14

Example of Regular Grammar:

G1 = ({S,A,B}, {a,b}, P, S)

P: S aB |

B bS | bA

A aA |

Page 15: Chomsky Hierarchy Language Operations and Properties

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}

Page 16: Chomsky Hierarchy Language Operations and Properties

The Chomsky Hierarchy

Take note that: regular grammar, context-free grammar, context sensitive grammar; are also unrestricted grammar.

Page 17: Chomsky Hierarchy Language Operations and Properties

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 |

Page 18: Chomsky Hierarchy Language Operations and Properties

1. aibj

2. aibjcidj

3. aibjcidjeifj

4. aibjckdiejfk

Page 19: Chomsky Hierarchy Language Operations and Properties

• 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