نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.

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

Chapter 5 Pushdown Automata
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory VII.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
PDAs => CFGs Sipser 2.2 (pages ). Last time…
PDAs => CFGs Sipser 2.2 (pages ). Last time…
Introduction to Computability Theory
CS5371 Theory of Computation
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
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.
Normal forms for Context-Free Grammars
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
CS 3813 Introduction to Formal Languages and Automata Chapter 6 Simplification of Context-free Grammars and Normal Forms These class notes are based on.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
1 Computer Language Theory Chapter 2: Context-Free Languages.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
Pushdown Automata.
Pushdown Automata (PDA) Intro
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Pushdown Automata (PDAs)
Chapter 5 Context-Free Grammars
Context-free Languages
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.
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Chapter 6 Simplification of Context-free Grammars and Normal Forms These class notes are based on material from our textbook, An Introduction to Formal.
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.
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
Closure Properties Lemma: Let A 1 and A 2 be two CF languages, then the union A 1  A 2 is context free as well. Proof: Assume that the two grammars are.
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.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
1 Chapter 6 Simplification of CFGs and Normal Forms.
CSCI 2670 Introduction to Theory of Computing September 23, 2004.
Lecture 14UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 14.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
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.
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.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Theory of Computation Automata Theory Dr. Ayman Srour.
Theory of Languages and Automata By: Mojtaba Khezrian.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Formal Languages, Automata and Models of Computation
Context-Free Grammars: an overview
Chapter 7 PUSHDOWN AUTOMATA.
REGULAR LANGUAGES AND REGULAR GRAMMARS
Context-free Languages
CHAPTER 2 Context-Free Languages
Context-Free Grammars
فصل دوم Context-Free Languages
Chapter 2 Context-Free Language - 01
Presentation transcript:

نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Table Of Content Context-Free Grammars Pushdown Automata Non-Context-Free Languages

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Context-Free Grammars A collection of substitution rules (production) Each rule → A line in the grammar Each line → A variable, an arrow, a string The string → variables and terminals

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Context-Free Grammars (Example) An Example: (G1) Three rules Variables: A,B Start Variable: A Terminals: 0,1,#

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Derivation Generating the strings of the language: G1:

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Parse Tree

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Context-Free Language All Strings generated in this way L(G 1 ) : G2 (describes a fragment of the English language):

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف A Derivation Example Derivation of the sentence “ a boy sees ” in G2

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Context-Free Language (Formal Definition)

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Context-Free Language (Formal Definition) u derives v The language of the grammar:

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Examples G3: R (Set of Rules): Strings such as: abab, aaabbb, aababb If: a → ( and b → ), then: L(G3) → language of all strings of properly nested parentheses

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Examples G4: V: Σ: R (Set of Rules):

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Examples (G4)

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Designing Context-Free Grammars Break the CFL into simpler pieces, if possible Construct grammar for each piece Combine the rules and the new rule S →S 1 |S 2 |…|S k, where the S i are the start variables for the individual grammars

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example Language: : Add the rule: to give the grammar:

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Designing Context-Free Grammars Any DFA can be converted to an equivalent CFG Make a variable R i for each state q i Add the rule, if Add the rule, if q i is an accept state

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Ambiguity When a grammar can generate the same string in different ways Undesirable for applications such as programming languages

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example This grammar generates the string ambiguously

Ambiguity Definition: A string w is ambiguous if it can be derived by at least two derivation (parse) trees. 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Ambiguity Leftmost (Rightmost) derivation: at every step, the leftmost (rightmost) remaining variable is replaced.

Example G: S → aAB A → bBb B → A|ε Leftmost derivation: S aAB abBbB abAbB abbBbbB abbbbB abbbb Rightmost derivation: S aAB aAA aAbBb aAbb abBbbb abbbb 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

Example (ctd) 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف S aAB B b bε A bbB ε A b S Ba A B bB ε bε b Tree 1Tree2

Example (ctd) Tree1: Rightmost derivation: S aAB aA abBb abAb abbBbb abbbb Tree2 Leftmost derivation: S aAB abBbB abbB abbA abbbBb abbbb 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

Ambiguity Definition: A string w is ambiguous in a context-free grammar if there are at least two different leftmost (rightmost) derivations or two different derivation trees for that string in that grammar. A context- free grammar is ambiguous if it can generates at least one ambiguous string. Otherwise it is unambiguous. 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

Inherently Ambiguous Languages Definition: A context-free language is (inherently) ambiguous if all context-free grammars generating it will be ambiguous. 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

Examples The following context-free languages are inherently ambiguous: L 1 = {a i b j c k | i=j or j=k where i,j,k ≥0} L 2 = {a i b j c k d m | i=j, k=m or i=m, j=k where i,j,k,m ≥1} 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Simplification of CFG Let G = (V, Σ, R, S) be a CFG. Suppose R contains a rule of the form A → x 1 Bx 2 Assume that A and B are different variables and that B → y 1 | y 2 | … | y n is the set of all rules in R which has B as the left side. Let G’ = (V, Σ, R’, S) be the grammar in which R’ is constructed by deleting A → x 1 Bx 2 from R and adding to it A → x 1 y 1 x 2 | x 1 y 2 x 2 | … | x 1 y n x 2. Then L(G’) = L(G).

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example: Consider grammar G: A → a | aaA | abBc, B → abbA | b Using the substitution property, we get G’: A → a | aaA | ababbAc | abbc, B → abbA | b The new grammar G’ is equivalent to G.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Useful Variable Let G = (V, Σ, R, S) be a CFG. A variable A  V is said to be useful if and only if there is at least one w  L(G) such that S * xAy * w with x, y  (V U Σ)*. A variable that is not useful is called useless. A rule is useless if it involves any useless variable.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example: G: S → aS | A | C A → a B → aa C → aCb S → aS | A A → a B → aa S → aS | A A → a SAB Dependency Graph

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Theorem Let G = (V, Σ, R, S) be a CFG. Then there exists an equivalent grammar G’ = (V’, Σ’, R’, S) that does not contain any useless variable or rules.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف ε rules Any rule of a context-free grammar of the form A → ε is called an ε rule. Any variable A for which the derivation A * ε is called nullable.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example: G: S → ABaC A → BC B → b | ε C → D | ε D → d A, B, C are nullable variables above. Then we have: S → ABaC | BaC | AaC | ABa | aC | Aa | Ba | a A → B | C | BC B → b C → D D → d

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Theorem: Let G be any context-free grammar with ε not in L(G). Then there exists an equivalent grammar G’ having no ε rules.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Unit rules Any rule of a context-free grammar of the form A → B where A,B  V is called a unit rule.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example: G: S → Aa | B B → A | bb A → a | bc | B S * A, S * B, B * A, A * B S → Aa B → bb A → a | bc S → a | bc | bb | Aa B → a | bb | bc A → a | bb | bc SAB Dependency graph for unit rules

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Theorem: Let G be any context-free grammar without any ε rule. Then there exists a context-free grammar G’ that does not have any unit rules and that is equivalent to G.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Theorem: Let L be a context-free language that does not contain ε. Then there exists a context-free grammar that generates L and does not have any useless rules, ε rules, or unit rules. Solution: Remove ε rules Remove unit rules Remove useless rules.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف CHOMSKY NORMAL FORM Any context-free language is generated by a context-free grammar in Chomsky normal form.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example Step 1: (make a new start variable) Step 2: Remove ε rules B → ε, shown on the left and A → ε, shown on the right

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example (cont.) Step 3a: Remove unit rules S →S, shown on the left and S 0 →S, shown on the right Step 3b: Remove unit rules A→B and A→S

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example (cont.) Step 4: convert the remaining rules into the proper form by adding variables and rules

CYK Algorithm (J. Cooke, D.H. Younger, and T. Kasami) Let G = (V, Σ, R, S) be a context-free grammar (in Chomsky normal form) and w a string of length n w = a 1 a 2 …a n. The membership problem is the problem of finding if w L(G). 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

CYK Algorithm (ctd.) Define w ij = a i … a j and subsets of V We can show 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

CYK Algorithm (ctd.) Then, the algorithm to compute the problem is as follows with the time complexity O(n 3 ): 1.Compute V 11, V 22, …, V nn 2.Compute V 12, V 23, …, V n-1,n 3.Compute V 13, V 24, …, V n-2,n and so on. 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

Example Determine whether the string w = aabbb is in the language generated by the grammar G below S → AB A → BB|a B → AB|b We have: V 11 = V 22 = {A}, V 33 = V 44 = V 55 = {B}, V 12 = Ø, V 23 = {S, B}, V 34 = V 45 = {A}, V 13 = = V 35 = {S, B}, V 24 = {A}, V 14 = {A}, V 25 = {S, B}, V 15 = {S, B}, so that w L(G). 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف PUSHDOWN AUTOMATA Like nondeterministic finite automata, with an extra component: stack The stack provides additional memory Pushdown automata are equivalent in power to context-free

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف PUSHDOWN AUTOMATA

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف PUSHDOWN AUTOMATA Push: Writing a symbol on the stack Pop: Removing a symbol Recognizes {0 n 1 n |n≥0} As each 0 is read from the input, push it onto the stack. Pop a 0 off the stack for each 1 read. Reading the input is finished exactly when the stack becomes empty →Accept

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف PUSHDOWN AUTOMATA ( formal definition)

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example 1 L={0 n 1 n |n≥0} Q={q 1,q 2,q 3,q 4 } Σ={0,1} Γ={0,$} F={q 1,q 4 } δ:

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example (cont.)

Example2 Give a pushdown automaton for the language: {a i b j c k | i,j,k ≥ 0 and i = j or i = k} 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

Example3 Give a pushdown automaton for the language: {ww R | w {0, 1}*} 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Equivalence with context-free grammars A language is context free if and only if some pushdown automaton recognizes it. Proof Idea: –Only if part : Let A be a CFL. Show how to convert the A’s CFG, G into a PDF P that accepts all strings that G generates. – If part : Let P be a PDA. Show how to convert P into a CFG G that generates all strings that P accepts.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Proof of “ only if ” part Any terminal symbols appearing before the first variable are matched with input.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Proof

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Proof (cont.) (r,u) ∈ δ(q,a,s) means that when q is the state of the automaton, a is the next input symbol, and s is on the top of the stack, push the string u onto the stack and go on to the state r.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Proof (cont.) Q={q start,q loop,q accept } E where E is the set of states needed for implementing the shorthand described before. Step 1: δ(q start,ε,ε)={(q loop,S$)} Step 2: –(a) δ(q loop,ε,A)={(q loop,w)|where A →w is a rule} –(b) δ(q loop,a,a)={(q loop,ε)} –(c) δ(q loop,ε,$)={(q accept,ε)}

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Proof (cont.)

Example Construct a PDA for the CFG grammar: S → aTb | b T → Ta | ε 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Proof of “ if ” part First, we simplify our task by modifying P slightly to give it the following three features. –It has a single accept state, q accept. –It empties its stack before accepting. –Each transition either pushes a symbol onto a stack (a push move) or pops one off the stack (a pop move), but does not do both at the same time. Next, for each pair of states p and q in P the grammar will have a variable A pq. This variable generates all strings that can take P from p with an empty stack to q with an empty stack. Observe that such strings can also take P from p to q, regardless of the stack contents at p, leaving the stack at q in the same condition as it was at p.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Proof Suppose P = (Q, Σ, Γ, δ, q 0, {q accept }). We can construct CFG G. The variables of G are {A pq | p,q Q}. The start variable is A q 0,q accept. Now we describe G’s rules: –For each p,q,r,s Q, t Γ, and a,b Σ ε, if δ(p, a, ε) contains (r,t) and δ(s, b, t) contains (q, ε), put rule A pq → aA rs b in G. –For each p,q,r Q, put rule A pq →A pr A rq in G. –Finally, for each p Q, put the rule A pp → ε in G.

PDA computation corresponding to the rule A pq →A pr A rq PDA computation corresponding to the rule A pq → aA rs b 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

Claims Claim 1: If A pq generates x, then x can bring P from p with empty stack to q with empty stack. – The proof is done by induction on the number of steps in the derivation of x from A pq. Claim 2: If x can bring P from p with empty stack to q with empty stack, A pq generates x. –The proof is done by induction on the number of steps in the computation of P that goes from p to q with empty stacks on input x. 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Relationship of the regular and context-free languages Every regular language is context-free.

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Deterministic PDAs A pushdown automaton M = (Q, Σ, Γ, δ, q 0, F) is said to be deterministic if it has the following properties:  q Q,  A Γ ε,  a Σ, δ(q, ε, A) ≠ Φ → δ(q, a, A) = Φ  q Q,  A Γ,  a Σ ε, δ(q, a, ε) ≠ Φ → δ(q, a, A) = Φ  q Q,  A Γ ε,  a Σ, δ(q, ε, ε) ≠ Φ → δ(q, a, A) = Φ  q Q,  A Γ ε,  a Σ ε, |δ(q, a, A)|  1

Deterministic Context-free Languages Definition: A context-free language is said to be deterministic if it can be accepted by some deterministic pushdown automaton. 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

Example 1 L = {a n b n : n≥0} is a deterministic language because it can be accepted by the following deterministic automaton: 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

Example 2 It can be shown that the language L 1 = {a n b n : n≥0} U {a n b 2n : n≥0} is nondeterministic. 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف NON-CONTEXT-FREE LANGUAGES Pumping Lemma for context-free languages: –If A is a context-free language, then there is a number p (the pumping length) where, if s is any string in A of length at least p, then s may be divided into five pieces s=uvxyz satisfying the conditions: For each i≥0, uv i xy i z ∈ A |vy|>0 |vxy|≤p

Proof Let G be a CFG for CFL A. Let b be the maximum number of symbols in the right-hand side of a rule (assume at least 2). Then, if the height of the parse tree is at most h, the length of the string generated is at most b h. Conversely, if a generated string is at least b h +1 long, each of its parse tree must be at least h+1 high. Let |V| be the number of variables in G. Then, we set p to be b |V|+1. Now if s is a string in A and its length is p or more, any of its parse trees must be at least |V| +1 high, because b |V|+1 ≥ b |v| +1. We choose the smallest of such parse trees. 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

Proof (cont.) Surgery on parse trees 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example 1 B={a n b n c n |n≥0} Assume that B is a CFL and p is the pumping length. s=a p b p c p : a member of B and of length at least p We show that it can not be pumped

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example 1 (cont.) s=uvxyz Condition1 –v and y contain one type pf symbol → uv 2 xy 2 z cannot contain equal number of a’s, b’s and c’s. –Either v or y contain more than one type of symbol→ uv 2 xy 2 z cannot contain a’s, b’s and c’s in the correct order.

Example 2 Let D = {ww | w {0,1}*} Assume that D is a CFL and p is the pumping length. s= 0 p 10 p 1: a member of D and of length at least p; it will not work! 88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Example 2 (cont.) Let us choose s = 0 p 1 p 0 p 1 p it will work! We show that it cannot be pumped Note that s=uvxyz = 0 p 1 p 0 p 1 p

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف Deterministic PDAs A pushdown automaton M = (Q, Σ, Γ, δ, q 0, F) is said to be deterministic if it has the following properties:  q Q,  A Γ ε,  a Σ, δ(q, ε, A) ≠ Φ → δ(q, a, A) = Φ  q Q,  A Γ,  a Σ ε, δ(q, a, ε) ≠ Φ → δ(q, a, A) = Φ  q Q,  A Γ ε,  a Σ, δ(q, ε, ε) ≠ Φ → δ(q, a, A) = Φ  q Q,  A Γ ε,  a Σ ε, |δ(q, a, A)|  1

88 بهارنظریه زبان ها و ماشین ها دانشگاه صنعتی شریف End of chapter 2 End of chapter 2