13
CSCI 2670 Introduction to Theory of Computing September 14, 2005

CSCI 2670 Introduction to Theory of Computing September 14, 2005

  • Upload
    roy-ray

  • View
    216

  • Download
    0

Embed Size (px)

DESCRIPTION

Announcement Quiz tomorrow –Regular expressions –Pumping lemma

Citation preview

Page 1: CSCI 2670 Introduction to Theory of Computing September 14, 2005

CSCI 2670Introduction to Theory of

Computing

September 14, 2005

Page 2: CSCI 2670 Introduction to Theory of Computing September 14, 2005

Agenda• Yesterday

– Pumping lemma • Today

– Introduce context-free grammars– Formally define CFG’s– Begin designing CFG’s

• Tomorrow– More on designing CFG’s– Chomsky normal form

Page 3: CSCI 2670 Introduction to Theory of Computing September 14, 2005

Announcement• Quiz tomorrow

– Regular expressions– Pumping lemma

Page 4: CSCI 2670 Introduction to Theory of Computing September 14, 2005

Context-free grammars• The shortcoming of finite automata

is that each state has very limited meaning– You have no memory of where you’ve

been – only knowledge of where you are

• Context-free grammars are a more powerful method of describing languages– Example: {0n1n | n 0} is a CFG

Page 5: CSCI 2670 Introduction to Theory of Computing September 14, 2005

Example CFG• Context-free grammars use

substitution to maintain knowledgeS (S)S SSS ()

• All possible legal parenthesis pairings can be expressed by consecutive applications of these rules

• Is this a regular language?

Page 6: CSCI 2670 Introduction to Theory of Computing September 14, 2005

ExampleS (S) | SS | ()

• (()())(())• S SS

(S)(S) (SS)(()) (()())(())

• This sequence of substitutions is called a derivation

Page 7: CSCI 2670 Introduction to Theory of Computing September 14, 2005

Parse treeS (S) | SS | ()

SSS

SS

()()()

S

)(

S

( )

Page 8: CSCI 2670 Introduction to Theory of Computing September 14, 2005

Example 2S Sb | BbB aBb | aCbC ε

• Derivation for aaabbbbbSSb

BbbaaBbbbbaaaεbbbbb

aBbbbaaaCbbbbb

Page 9: CSCI 2670 Introduction to Theory of Computing September 14, 2005

Example 2 parse treeS

ε

S

b

B

b

B

a b

B

a bba

C

Page 10: CSCI 2670 Introduction to Theory of Computing September 14, 2005

Example 2S Sb | BbB aBb | aCbC ε

Question 1: What language does this grammar accept?

Answer: {anbm | m > n > 0}Question 2: Can this CFG be simplified?Answer: yes.

Replace BaCb with Bab and remove Cε

Page 11: CSCI 2670 Introduction to Theory of Computing September 14, 2005

Context-free grammar definition

• A context-free grammar is a 4-tuple (V,,R,S), where

1. V is a finite set called the variables,2. is a finite set, disjoint from V,

called the terminals,3. R is a finite set of rules, with each

rule being a variable and a string of variables and terminals, and

4. S V is the start variable.

Page 12: CSCI 2670 Introduction to Theory of Computing September 14, 2005

More definitions• If u, v, and w are strings of

variables and terminals, and A w is a rule of the grammar, we say uAv yields uwv– Denoted uAv uwv

Page 13: CSCI 2670 Introduction to Theory of Computing September 14, 2005

More definitions• If a sequence of rules leads from u

to v – i.e., u u1 u2 … v, we denote this u * v

• (I can’t do the actual notation in powerpoint – the * should be over the double bars)

• The language of the grammar is {w * | s * w}