Presentation is loading. Please wait.

Presentation is loading. Please wait.

The chomsky hierarchy Module 03.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.

Similar presentations


Presentation on theme: "The chomsky hierarchy Module 03.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez."— Presentation transcript:

1 The chomsky hierarchy Module 03.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez

2 Language and Grammar classes
We’ll Cover Grammar Conventions Sample Grammars The Chomsky Hierarchy Regular Languages Context-free Languages Context-sensitive Languages Recursively Enumerable Languages

3 Grammar conventions Upper case letter – nonterminal
Lower case letter – terminal Lower case greek letter – strings in V* Left part of the first production: start symbol. If same as previous, omit left part. Example: S → aSb → ε

4 Language and Grammar classes
Definition: The language generated by a grammar G, is the set L(G) = {  Σ* | S =>*  } Definition: A sentential form generated by a grammar G is any string  such that S =>*  . Definition: A sentence generated by a grammar G is any sentential form  such that   Σ*. Lemma: L(G) = { |  is a sentence} Proof: Trivial.

5 A regular grammar Example: Grammar for identifiers. Language pattern:
Identifier → Letter → Identifier Letter → Identifier Digit Letter → ‘a’ → ‘A’ → ‘b’ → ‘B’ . . . → ‘z’ → ‘Z’ Digit → ‘0’ → ‘1’ → ‘9’ Language pattern: {an | n > 1}

6 A context-free grammar
Grammar: S → aSb S → sentential forms S => aSb => aaSbb => aaaSbbb => aaaaSbbbb =>… ε ab aabb aaabbb aaaabbbb sentences Language pattern: {anbn | n > 1} =>

7 A context-sensitive Grammar
A => aABC => aaABCBC => … aBC aaBCBC aaaBCBCBC abC aabCBC aaaBBCBCC abc aabBCC aaaBBBCCC aabbCC aaabBBCCC aabbcC aaabbbCCC aabbcc aaabbbcCC aaabbbccc => A → aABC → aBC CB → BC aB → ab bB → bb bC → bc cC → cc Language pattern: {anbncn | n > 1}

8 The chomsky hierarchy A hierarchy of grammars, the languages they generate, and the machines the accept those languages. Developed by Noam Chomsky (MIT) in 1957. Linguist, philosopher, cognitive scientist, historian, logician. Social critic, political activist. Four language levels: Regular languages: {an | n > 1} Context-free languages: {an bn / n > 0} Context-sensitive languages: {an bn cn | n > 1} Unrestricted: (no pattern)

9 The chomsky hierarchy Impractical Practical Type Language Name Grammar
Restrictions On grammar Accepting Machine Recursively Enumerable Unrestricted re-writing system None Turing Machine 1 Context-Sensitive Language Context- Sensitive Grammar For all →, ||≤|| Linear Bounded Automaton 2 Context- Free Language Context- Free Grammar Φ. Push-Down Automaton (parser) 3 Regular Φ,  U Φ U {} Finite- State Automaton

10 The chomsky hierarchy 3: Regular Languages {an | n > 0} 2: Context-free Languages 1: Context-Sensitive Languages {anbn | n>0} {anbncn | n>0} 0: Recursively Enumerable Languages English? Type 3: appropriate for lexical analysis (scanning). Type 2: appropriate for Syntax analysis (parsing)

11 summary Grammar Conventions The Chomsky Hierarchy Regular Languages
(good for scanning) Context-free Languages (good for parsing) Context-sensitive Languages Recursively Enumerable Languages


Download ppt "The chomsky hierarchy Module 03.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez."

Similar presentations


Ads by Google