Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCE 355 Foundations of Computation

Similar presentations


Presentation on theme: "CSCE 355 Foundations of Computation"— Presentation transcript:

1 CSCE 355 Foundations of Computation
Lecture 14 Grammars Topics: Context Free Grammars Parses, derivations, parse trees Language generated by a grammar October 15, 2008

2 New: Homework Last Time:
Examples of Sets of indistinguishable prefixes Pumping Lemma If L is regular is the Reversal LR regular? Review: Proofs Languages are not Regular Sets of distinguishable prefixes New: Languages Regular or Not {0n1m | n > 100, m < 100}, {0m | m = k2 }, {ww | w in {a,b}* }, {w in {a,b}* | w viewed as binary is divisible by 7} Adversarial game revisited Regular or not Grammars: definitions, derivations, parse trees, languages generated by grammars, L(G) Homework Sets of indistinguishable Pumping lemma Derivations

3 Pumping Lemma as Adversarial Game
You pick the language L to be proved nonregular. Opponent picks n, but does not reveal it. You carefully pick w, which may depend on n and |w| ≥ n Opponent divides w into x, y and z, with |y| > 0, |xy| ≤ n You “win’ by picking k, which may be a function of n, x, y and z such that xykz is not in L.

4 Pumping Lemma Examples from the Web
{anbn: n 0}, {anbk: n > k and n 0}, {an: n is a prime number} xxx

5 Regular or Not? {w in {0,1}* | w has equal number of zeroes and ones}
{w in {0,1}* | w has even length}

6 Homework 4.2.3 4.2.4 4.4.1 (just look at) 4.4.2

7 Unix Shell “regular expressions” Aren’t really regular expressions
Examples ls *.rb // * is not the closure operator but wildcard ls [a-d]* grep “[a-d]*” *

8 Strings distinguishing states
A string x in Σ* distinguishes two states q1 and q2 if one of δ(q1, x) and δ(q2,x) is a final state and one if not. Examples What string distinguishes q1 and q2 in the DFA? What string distinguishes q3 and q2? Graphically

9 Indistinguishable states
Two states are indistinguishable if there is no string that distinguishes them What if we change the DFA to δ (q1,0) = q3 δ (q1,1) = q1 Then q1 and q2 are not distinguished by any string

10 Indistinguishable is an Equivalence relation
A relation is an Equivalence relation if . Prove Indistinguishable is an Equivalence relation Proof: Let

11 Figure 4.8 DFA page 156 Consider the DFA
Now ε distinguishes C from everything else Table of state inequivalences 1 A B C D E F G H . X 1 A B C D 1 1 1 1 1 E F G H 1

12 Distinguishing one step at a time
Note If δ(q, a) = s is distinguished from δ(r, a) = t by string x then q is distinguished from r by the string w = ax

13 Table of state inequivalences
1 Table of state inequivalences 1 A B C D 1 1 A B C D E F G H . X 1 1 1 E F G H 1 Consider the string “0” Find pairs of states (p,r) with δ(q, 0) is distinguished from δ(r, 0) since δ(D, 0) = C and δ(X, 0) !=C; D is disting. from X = A, B, E, G, H since δ(F, 0) = C and δ(X, 0) !=C; F is disting. from X = A, B, E, G, H Now consider the string “0”

14 Table of state inequivalences
1 Table of state inequivalences 1 A B C D 1 1 A B C D E F G H . X 1 1 1 E F G H 1 Consider the string “1” Find pairs of states (p,r) with δ(q, 1) is distinguished from δ(r, 1) not in Final, so q r Is δ(A, 1)=F is distinguished from δ(B, 1)=C, so is A distinguished from B? Is δ(A, 1)=F is distinguished from δ(E, 1)=F? Is δ(A, 1)=F is distinguished from δ(F, 1)=G? Is δ(A, 1)=F is distinguished from δ(G, 1)=E? Now consider the string “0”

15 Table of state inequivalences
1 Table of state inequivalences 1 A B C D 1 1 A B C D E F G H . X 1 1 1 E F G H 1 Do iterations considering both 0 and 1. If for an iteration there is no change then there never will be. So stop. Now consider the string “0”

16 Partitions Equivalence class of x denoted [x]
Π = {X1, X2, … Xn} is a partition of a set S if . If R is an equivalence relation on a set S then R induces a partition on S which means the equivalence classes form a partition

17 Minimization of DFA First eliminate states not reachable from the start state Partition the states into sets of indistinguishable states (equivalence classes) Figure 4.12 Minimum state DFA equivalent to DFA in figure 4.8 (slide 10)

18

19 Strings distinguishable for a Language
Two strings y and z are distinguished by a language L if there is a string x such that exactly one of yx and zx is in L Example: L

20 Consequences for DFA Suppose a DFA D=(Q, Σ, δ, q0, F) has n states and that Language L has than n distinguished prefixes Then L cannot be the language accepted by D, (L(D). Why?

21 Chapter 5 Grammars Grammar for Palindromes P  ε P  0 P  1 P  0 P 0 P  1 P 1  is interpreted as “may be rewritten as”.

22 Definitions G = (N, T, P, S) G = (N, T, P, S)
N = set of nonterminal symbols (text call these variables) T = set of terminals (or sometime tokens) S = start symbol (a nonterminal) P = a set of Productions, rewrite rules of the form X  α1 α2 …αn-1 αn Where X ε N and each αi is from N U T

23 Notational Shorthand Typically just list productions
For all productions with same LHS use ‘|’ to separate RHS’s Nonterminals? Terminals? Start Symbol? P  ε | 0 | 1 | 0 P 0 | 1 P 1

24 Further Notational Assumptions
G a, b, c,… A,B, … X, Y, Z α,β,µ,γ,δ,ζ,θ ε and sometimes λ x

25 Derives Relation Given a Grammar G. If α and β are strings of grammar symbols then we can define the “derives” relation as α  β, if α = α1Xα2 and β = α1ξα2 where X ξ is a production in G α * β derives in zero or more steps This is the transitive reflexive closure of 

26 Sentential forms E  E+E | E*E | (E) | id α is a sentential form if

27 Parse Trees

28 Language Generated by a Grammar

29 Grammar for Expressions

30

31

32

33

34


Download ppt "CSCE 355 Foundations of Computation"

Similar presentations


Ads by Google