INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.

Slides:



Advertisements
Similar presentations
CS2303-THEORY OF COMPUTATION Push Down Automata (PDA)
Advertisements

CSCI 3130: Formal Languages and Automata Theory Tutorial 5
Computing functions with Turing machines
Lecture 11 Context-Free Grammar. Definition A context-free grammar (CFG) G is a quadruple (V, Σ, R, S) where V: a set of non-terminal symbols Σ: a set.
Grammar types There are 4 types of grammars according to the types of rules: – General grammars – Context Sensitive grammars – Context Free grammars –
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
A question from last class: construct the predictive parsing table for this grammar: S->i E t S e S | i E t S | a E -> B.
Lecture # 8 Chapter # 4: Syntax Analysis. Practice Context Free Grammars a) CFG generating alternating sequence of 0’s and 1’s b) CFG in which no consecutive.
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.
Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
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 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
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.
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
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 }
Context-free Languages
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
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.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Theory of Computation Automata Theory Dr. Ayman Srour.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Pushdown Automata.
Bottom-up parsing Goal of parser : build a derivation
CS510 Compiler Lecture 4.
Table-driven parsing Parsing performed by a finite state machine.
PDAs Accept Context-Free Languages
Context Free Languages
Intro to Theory of Computation
Context-Free Languages
Pushdown automata and CFG ↔ PDA conversions
LR(1) grammars The Chinese University of Hong Kong Fall 2010
CSCE 531 Compiler Construction
Chapter 2 Context-Free Language - 01
CS21 Decidability and Tractability
CS21 Decidability and Tractability
LR(1) grammars The Chinese University of Hong Kong Fall 2011
… NPDAs continued.
CSE 105 theory of computation
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Parsing CSCI 432 Computer Science Theory
Presentation transcript:

INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011

ε,ε → $ 0,ε → 0 1,0 → ε ε,$ → ε stringpoppush The language of P is the set of strings it accepts.

A → 0A1 A → B B → # CONTEXT-FREE GRAMMARS A  0A1  00A11  00B11  00#11 A derives 00#11 in 4 steps. The language of G is the set of strings derived by S.

VERY INTERESTING CFGs…

PARSE TREES A  0A1  00A11  00B11  00#11 A B 01# A A 01

Definition. T is a parse tree for the derivation S ⇒ * w under grammar G = (V,Σ,R,S) if 1. The root of T has label S 2. The leaves of T have labels w i ∈ Σ 4. For each node with label v ∈ V and children with labels r i ∈ (V ∪ Σ), (v→r) ∈ R. 3. The non-leaf nodes have labels v ∈ V

→ + → x → ( ) → a Build a parse tree for a + a x a ax+a a a+xa a

COMPILER MODULES LEXER PARSER SEMANTIC ANALYZER TRANSLATOR/INTERPRETER

A Language is generated by a CFG  It is recognized by a PDA  Suppose L is generated by a CFG G = (V, Σ, R, S) Construct P = (Q, Σ, Γ, , q, F) that recognizes L Idea: P will derive w ∈ L on its stack.

Suppose L is generated by a CFG G = (V, Σ, R, S) Construct P = (Q, Σ, Γ, , q, F) that recognizes L (1) Place the marker symbol $ and the start variable on the stack (2) Repeat forever: (a) If v is in the stack, and (v → s) ∈ R, push s on the stack (b) If stack is a string, goto (3) (3) Loop until stack is empty: (a) if top of stack matches input, pop. (b) on (ε,$), accept.

Suppose L is generated by a CFG G = (V, Σ, R, S) Construct P = (Q, Σ, Γ, , q, F) that recognizes L (q start ) Push S$ and go to q loop (q loop ) Repeat the following steps forever: (a) On (ε,v) where (v → s) ∈ R, push s and go to q loop (b) On ( ,  ), pop  and go to q loop (c) On (ε,$) go to q accept (else) get stuck!

ε,ε → S$ ε,$ → ε ε,A → w for rule A → w a,a → ε for terminal a

S → aTb T → Ta | ε ε,ε → $ ε,$ → ε ε,ε → S ε,S → b ε,ε → T ε,T → a ε,ε → a ε,ε → T ε,T → ε a,a → ε b,b → ε

A Language is generated by a CFG  It is recognized by a PDA 

A Language is generated by a CFG  It is recognized by a PDA  Given PDA P = (Q, Σ, Γ, , q, F) Construct a CFG G = (V, Σ, R, S) such that L(G)=L(P) First, simplify P so that: (1) It has a single accept state, q accept (2) It empties the stack before accepting (3) Each transition either pushes a symbol or pops a symbol, but not both

ε,ε → $ 0,ε → 0 1,0 → ε ε,$ → ε SIMPLIFY q0q0 q1q1 q2q2 q3q3 ε,ε → ε ε,0 → ε ε,ε → 0 q4q4 q5q5

Idea: for each pair of states p and q in P, the grammar will have a variable A pq that generates all strings that that can take P from p to q without changing the stack* V = {A pq | p,q  Q } S = A q 0 q accept *starting from any stack S in p, P has stack S at q.

ε,ε → $ 0,ε → 0 1,0 → ε ε,$ → ε q0q0 q1q1 q2q2 q3q3 ε,0 → ε ε,ε → 0 q4q4 q5q5 What strings does A q 0 q 1 generate? What strings does A q 1 q 2 generate? What strings does A q 1 q 3 generate? none {0 n 1 n | n > 0} none

A pq generates all strings that take P from p to q without changing the stack Let x be such a string P’s first move on x must be a push P’s last move on x must be a pop Consider the stack while reading x. Either: 1. The first repeat comes at the end of x 2. The stack repeats before the end of x

stack height input string pq A pq → aA rs b rs 1. The first repeat is at the end of x: ba

stack height input string prq A pq → A pr A rq 2. The stack repeats before the end of x:

V = {A pq | p,q  Q } S = A q 0 q accept Formally: For each p,q,r,s  Q, t  Γ and a,b  Σ ε If (r,t)   (p,a,ε) and (q, ε)   (s,b,t) Then add the rule A pq → aA rs b For each p,q,r  Q, add the rule A pq → A pr A rq For each p  Q, add the rule A pp → ε

ε,ε → $ 0,ε → 0 1,0 → ε ε,$ → ε q0q0 q1q1 q2q2 q3q3 ε,0 → ε ε,ε → 0 q4q4 q5q5 What strings does A q 0 q 1 generate? What strings does A q 1 q 2 generate? What strings does A q 1 q 3 generate? A q 0 q 3 → εA q 1 q 2 ε A qq → ε A pq → A pr A rq A q 1 q 2 → 0A q 1 q 2 1 A q 1 q 2 → 0A q 1 q 1 1 none {0 n 1 n | n > 0} none

A Language is generated by a CFG  It is recognized by a PDA