Definiton: Derivation tree Let G = ( V, T, S, P ) be a cfg. An - - PowerPoint PPT Presentation

definiton derivation tree let g v t s p be a cfg an
SMART_READER_LITE
LIVE PREVIEW

Definiton: Derivation tree Let G = ( V, T, S, P ) be a cfg. An - - PowerPoint PPT Presentation

Definiton: Derivation tree Let G = ( V, T, S, P ) be a cfg. An ordered tree is called a derivation tree for G if the root is labelled S every interior vertex has a label from V Every leaf has a label from T { } If a vertex has


slide-1
SLIDE 1

Definiton: Derivation tree Let G = (V, T, S, P) be a cfg. An ordered tree is called a derivation tree for G if

  • the root is labelled S
  • every interior vertex has a label from V
  • Every leaf has a label from T ∪ {λ}
  • If a vertex has a label A and its children are labelled

X1, X2, X3, . . . Xn from left to right, then A → X1X2 . . . Xn is a production in P.

  • A leaf labelled λ has no siblings.

1

slide-2
SLIDE 2

Chomsky Normal Form (CNF) A cfg G is in CNF if all productions are of the form A → BC

  • r A → a

where A, B, C ∈ V and a ∈ T.

2

slide-3
SLIDE 3

Given a cfg G, to put it into CNF, we perform the following steps:

  • 1. Remove all λ-productions.
  • 2. Remove all unit productions.
  • 3. Remove all useless productions.
  • 4. Remove productions not of the form A → BC or A → a.

3

slide-4
SLIDE 4

Griebach Normal Form A cfg G is in GNF if all productions are of the form A → ax where a ∈ T and x ∈ V ∗

4

slide-5
SLIDE 5

HW Q2 (revised): Let G be a context-free grammar in CNF, and let w ∈ L(G) be the yield of a parse tree for w according to the grammar G. Prove using induction that if the length of the longest path in the tree is n, then |w| ≤ 2n−1.

5

slide-6
SLIDE 6

Pumping Lemma for CFLs Let L be a CFL. Then ∃m > 0 such that ∀w ∈ L with |w| ≥ m ∃ a way to break up w such that w = uvxyz with |vxy| ≤ m and |vy| ≥ 1 ∀i ≥ 0 uvixyiz ∈ L

6

slide-7
SLIDE 7

To use the pumping lemma to show that a given L is not context- free, we play an adversary game as follows:

  • 1. Assume adversary picks m, the constant of the pumping

lemma/

  • 2. We get to pick w, a string in L that is longer than m.
  • 3. Adversary gets to break up w into uvxyz, while obeying the

rules that |vxy| ≤ m and |vy| ≥ 1.

  • 4. We get to pick i (the number of times to pump v and y. We

win if we show that uvixyiz / ∈ L.

7

slide-8
SLIDE 8

Closure properties Operation Regular CFLs DCFLs Union Yes Yes No Concatenation Yes Yes No Kleene closure Yes Yes No Intersection Yes No No

  • Int. with regular language

Yes Yes Yes Complementation Yes No Yes Reversal Yes Yes No

8

slide-9
SLIDE 9

Decision algorithms

Given a cfg G, there are algorithms to determine the following questions:

  • 1. Is L(G) empty?
  • 2. Is L(G) finite?
  • 3. Given a string x, is x ∈ L(G)?

9

slide-10
SLIDE 10

Decision algorithms

But for many questions about CFLs that no algorithm can an- swer (we will formalize what we mean by this later). Here are some examples: Let G be a cfg.

  • 1. Is L(G) = Σ∗?
  • 2. Is L(G) a regular set?
  • 3. Is L(G) a DCFL?
  • 4. Is L(G) inherently ambiguous?
  • 5. Is the complement of L(G) a cfl?

10

slide-11
SLIDE 11

Let G1, G2 be cfgs and let R be a regular set.

  • 6. Is L(G1) = L(G2)?
  • 7. Is L(G1) ∩ L(G2) = ∅?
  • 8. Is L(G1) ∩ L(G2) a cfl?
  • 9. Is L(G1) ⊆ L(G2)?
  • 10. Is L(G) = R?