Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }

Slides:



Advertisements
Similar presentations
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Advertisements

1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Pushdown Automata Part II: PDAs and CFG Chapter 12.
CS21 Decidability and Tractability
PDAs => CFGs Sipser 2.2 (pages ). Last time…
PDAs => CFGs Sipser 2.2 (pages ). Last time…
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
Finite State Machines Data Structures and Algorithms for Information Processing 1.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Pushdown Automata (PDA) Part 2 While I am distributing graded exams: Design a PDA to accept L = { a m b n : m  n; m, n > 0} MA/CSSE 474 Theory of Computation.
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Pushdown Automata (PDAs)
1 Let L= { w= u v : u  {a, b}*, v  {c, d}* and |u|= |v|} 1.Design a context-free grammar that generates L. 2.Use your grammar and the construction from.
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
Context-free Languages Chapter 2. Ambiguity.
1 L= { w c w R : w  {a, b}* } is accepted by the PDA below. Use a construction like the one for intersection for regular languages to design a PDA that.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Equivalence of Pushdown Automata and Context-Free Grammar Prof. Héctor Muñoz-Avila.
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.
Chapter 7 Pushdown Automata
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Grammars Hopcroft, Motawi, Ullman, Chap 5. Grammars Describes underlying rules (syntax) of programming languages Compilers (parsers) are based on such.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
PushDown Automata. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
Critique this PDA for L= { u u R v v R : u ∈ {0,1}* and v ∈ {0,1}+ } u0εu0 u1εu1 uεεvε v00vε v11vε vεεfε sεεtε t0εt0 t1εt1 t00tε t11tε tεεuε After you.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
Formal Languages, Automata and Models of Computation
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
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.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
1 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations pop, push, and nop. PDAs always.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Theory of Languages and Automata By: Mojtaba Khezrian.
1 Use the pumping theorem for context-free languages to prove that L= { a n b a n b a p : n, p ≥ 0, p ≥ n } is not context-free. Hint: For the pumping.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Context-Free and Noncontext-Free Languages Chapter 13.
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
CS21 Decidability and Tractability
Presentation transcript:

Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }

Midterm tutorial: Monday June 25 at 7:30pm, ECS 116. Tutorial this week: Bring any questions you have about assignment #3 or old midterms. Material covered if you have no other questions: Context-free grammars and Pushdown Automata. Assignment #3 is due at the beginning of class on Tuesday June 26.

3

Today: We will go back over more examples of context-free grammars, pushdown automata and parse trees. I previously went through that material fairly quickly so you would be able to do the assignment last weekend if you wanted to.

L= {w  {a,b}* : w has abb and a prefix and bba as a suffix} 1.Create a regular context-free grammar that generates L. 2. Give a context-free grammar for L that is not regular. Recall: A regular context-free grammar can have at most one non-terminal on the RHS of each rule, if there is a non- terminal, it is the last symbol on the RHS of the rule.

To accept, there must exist a computation which: 1.Starts in the start state with an empty stack. 2. Applies transitions of the PDA which are applicable at each step. 3. Consumes all the input. 4. Terminates in a final state with an empty stack. L(M)= { w  Σ* : (s, w, ε) ├ * (f, ε, ε) for some final state f in F}.

L= { w w R : w  {a, b}* } StateInputPopNext state Push saεsA sbεsB sεεtε taAtε tbBtε Start state: s, Final State: {t} PDA’s are non-deterministic: Guessing wrong time to switch from s to t gives non-accepting computations.

Some non-accepting computations on aaaa: 1. Transfer to state t too early: (s, aaaa, ε) ⊢ (s, aaa, A) ⊢ (t, aaa, A) ⊢ (t, aa, ε) Cannot finish reading input because stack is empty. 2. Transfer to state t too late: (s, aaaa, ε) ⊢ (s, aaa, A) ⊢ (s, aa, AA) ⊢ (s, a, AAA) ⊢ (t, a, AAA) ⊢ (t, ε, AA) Cannot empty stack.

Accepting computation on aaaa: (s, aaaa, ε) ⊢ (s, aaa, A) ⊢ (s, aa, AA) ⊢ (t, aa, AA) ⊢ (t, a, A) ⊢ (t, ε, ε) The computation started in the start state with the input string and an empty stack. It terminated in a final state with all the input consumed and an empty stack.

StateInputPop Next state Push saεsB saAsε sbεsA sbBsε L= {w in {a, b}* : w has the same number of a’s and b’s} Start state: s Final states: {s}

StateInputPopNext state Push sεεtX taXtBX taAtε taBtBB tbXtAX tbAtAA tbBtε tεXfε L= {w in {a, b}* : w has the same number of a’s and b’s} State state: s, Final states: {f} A more deterministic solution: Stack will never contain both A’s and B’s. X- bottom of stack marker.

Parse Trees- G = (V, Σ, R S) Nodes of parse trees are each labelled with one symbol from V ⋃ {ε}. Node at top- root, labelled with start symbol S. Leaves- nodes at the bottom. Yield- concatenate together the labels on the leaves going from left to right.

Find the leftmost derivation for this parse tree.

To pump: Look for a path from root with a repeated non-terminal.

Path: S - A - T - A Non-terminal A is repeated.

Yield from second copy downwards gives x.

Consider tree from first copy downwards. Yield before x is v. Yield after x is y.

Yield after y is z. Yield of whole tree before v is u.

Cut off part of tree from second copy downwards.

Cut off part from first copy downwards.

To pump zero times: New yield: u x z = b bc c = u v 0 x y 0 z

To pump twice:

Pumping twice: New yield is: u v v x y y z = u v 2 x y 2 z

To pump three times: New yield is: u vvv x yyy z = u v 3 x y 3 z

To pump n times: New yield is: = u v n x y n z

The Pumping Theorem for Context-Free Languages: Let G be a context-free grammar. Then there exists some constant k which depends on G such that for any string w which is generated by G with |w| ≥ k, there exists u, v, x, y, z, such that 1. w= u v x y z, 2. |v| + |y| ≥ 1, and 3. u v n x y n z is in L for all n ≥ 0.

1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse tree u, v, x, y, z as per the pumping theorem. 3. Prove that the language for this question is an infinite language.