CSCE 355 Foundations of Computation

Slides:



Advertisements
Similar presentations
Grammar types There are 4 types of grammars according to the types of rules: – General grammars – Context Sensitive grammars – Context Free grammars –
Advertisements

Erik Jonsson School of Engineering and Computer Science FEARLESS Engineering CS 4384 – 001 Automata Theory Thursday: Context-Free.
Homework #5 Solutions 1. True or False a) Regular Languages are always Context-Free Languages True False b) Context Free Languages are always Regular.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin With some.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)
1 CSCI 3130: Formal Languages and Automata Theory Tutorial 4 Hung Chun Ho Office: SHB 1026 Department of Computer Science & Engineering.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
Exercise 1 Consider a language with the following tokens and token classes: ident ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP.
Lecture # 9 Chap 4: Ambiguous Grammar. 2 Chomsky Hierarchy: Language Classification A grammar G is said to be – Regular if it is right linear where each.
Introduction to CS Theory
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
Homework 4 due 11/25.
Grammars A grammar is a 4-tuple G = (V, T, P, S) where 1)V is a set of nonterminal symbols (also called variables or syntactic categories) 2)T is a finite.
Lecture 8 NFA Subset Construction & Epsilon Transitions
1 Find as many examples as you can of w, x, y, z so that w is accepted by this DFA, w = x y z, y ≠ ε, | x y | ≤ 7, and x y n z is in L for all n ≥ 0.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Lecture 15 Ambiguous Grammars Topics: Context Free Grammars Language generated by a grammar Proofs with L(G) Ambiguous grammars October 20, 2008 CSCE 355.
Lecture 6: Context-Free Languages
Lecture 11 Minimization Topics: Strings distinguishing states Equivalence relation October 6, 2008 CSCE 355 Foundations of Computation.
1 Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5.
Lecture 16 Cocke-Younger-Kasimi Parsing Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE.
Context-Free Languages & Grammars (CFLs & CFGs) (part 2)
Pushdown Automata.
Context-Free Languages & Grammars (CFLs & CFGs)
Context-Free Languages & Grammars (CFLs & CFGs)
CS510 Compiler Lecture 4.
Properties of Context-Free Languages
L1= { w  {a,b}* : w consists of all strings that begin with an even number of a's followed by an odd number of b's. } L2= { w  {a,b}* : the number of.
FORMAL LANGUAGES AND AUTOMATA THEORY
Lecture 22 Pumping Lemma for Context Free Languages
Chapter 7 PUSHDOWN AUTOMATA.
Lecture 17 Oct 25, 2011 Section 2.1 (push-down automata)
Pushdown Automata Reading: Chapter 6.
Intro to Theory of Computation
Context-Free Languages
Context-Free Grammars and Languages
CS 154, Lecture 4: Limitations on DFAs (I),
Infiniteness Test The Pumping Lemma Nonregular Languages
Regular Grammars.
4. Properties of Regular Languages
Lecture 6 Grammar Modifications
CSE 105 theory of computation
Finite Automata and Formal Languages
Finite Automata Reading: Chapter 2.
The Pumping Lemma for CFL’s
CSCE 531 Compiler Construction
The Pumping Lemma for CFL’s
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 1 Regular Language - 02
Midterm #2 — Review problems
Lecture 6 NFA Subset Construction & Epsilon Transitions
CS21 Decidability and Tractability
Lecture 12 Non-Regular Languages
Compiler Construction
Convert to a DFA: Start state: Final States: P Symbol Q E(Q) a b.
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Applications of Regular Closure
CSCI 2670 Introduction to Theory of Computing
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

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

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

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.

Pumping Lemma Examples from the Web http://www.seas.upenn.edu/~cit596/notes/dave/pumping0.html {anbn: n 0}, {anbk: n > k and n 0}, {an: n is a prime number} xxx

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

Homework 4.2.3 4.2.4 4.4.1 (just look at) 4.4.2

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]*” *

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

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

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

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

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

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”

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”

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”

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

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)

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

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?

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”.

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

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

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

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 

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

Parse Trees

Language Generated by a Grammar

Grammar for Expressions