CSCE 222 Lecture 27

From Notes
Jump to navigation Jump to search

« previous | Monday, April 11, 2011 | next »


Chomsky's Classification of Grammars

4 types of production rules:

  • Type 0. no restrictions on production rules
  • Type 1. "context-sensitive grammar" Productions are of the form lArlwr, where AN, l,rV*, and wV* (≠ λ)
  • Type 2. "context-free languages" Productions are of the form Aw when AN
  • Type 3. "regular languages" Productions are of the form AaB when A,BN and Aa when aT

Example 1

Give a grammar that generates the set , where exponents represents the number of repeated occurrences

Solution:

This is a "Type 2 (context-free) language"

Example 2

Give a grammar that generates the set .

Solution:

Type 3 Language

Example 3

Give a grammar that generates the set .

This is a context-sensitive language (cannot be generated by any context-free language

Parsing Languages

2 ways:

  • Top-down: Start with start symbol and use production rules to produce the desired output
  • Bottom-up: Start with desired output and reverse-engineer to a start symbol

Backus Naur Form

When non-terminal symbols can be replaced by many options, Backus Naur form combines them:

becomes