Lecture 18 Language Recognized by a PDA

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

Chapter 3 Syntax Analysis
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Lecture 10 YACC – Yet Another Compiler Compiler Introduction to YACC and Bison Topics Yacc/Bison IntroductionReadings: February 13, 2006 CSCE 531 Compiler.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
1 Pushdown Automata Definition Moves of the PDA Languages of the PDA Deterministic PDA’s.
Pushdown Automaton (PDA)
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
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:
Compilers: Yacc/7 1 Compiler Structures Objective – –describe yacc (actually bison) – –give simple examples of its use , Semester 1,
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Pushdown Automata (PDA) Intro
Pushdown Automata (PDAs)
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2010.
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s Pushdown Automata 11.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 6, 10/02/2003 Prof. Roy Levow.
Lecture 20 DPDA / Review Topics Given a PDA construct a grammar for the language it accepts Deterministic PDAs Properties of CFLsReadings: November 5,
1 Pushdown Automata Definition: relation to  -NFA Moves of the PDA Languages of the PDA Deterministic PDA’s Quiz Wednesday on CFGs lecture #3.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.
Formal Languages, Automata and Models of Computation
1 Chapter 6 Pushdown automata Sagrada Familia ( 聖家 堂 ), Barcelona, Spain.
1 Pushdown Automata Definition Moves of the PDA Languages of the PDA Deterministic PDA’s.
Lecture 14 Push Down Automata (PDA) Topics:  Definition  Moves of the PDA  Languages of the PDA  Deterministic PDA’s June 18, 2015 CSCE 355 Foundations.
LECTURE 11 Semantic Analysis and Yacc. REVIEW OF LAST LECTURE In the last lecture, we introduced the basic idea behind semantic analysis. Instead of merely.
More yacc. What is yacc – Tool to produce a parser given a grammar – YACC (Yet Another Compiler Compiler) is a program designed to compile a LALR(1) grammar.
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 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
Lecture 15 Ambiguous Grammars Topics: Context Free Grammars Language generated by a grammar Proofs with L(G) Ambiguous grammars October 20, 2008 CSCE 355.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
Lecture 14 Push Down Automata (PDA)
PDAs Accept Context-Free Languages
Table-driven parsing Parsing performed by a finite state machine.
Java CUP.
Pushdown Automata (PDA). Part 2
CIS Automata and Formal Languages – Pei Wang
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
AUTOMATA THEORY VI.
Pushdown Automata (PDA)
Simple, efficient;limitated
Pushdown Automata (PDA). Part 3
NPDAs Accept Context-Free Languages
Lecture 9 SLR Parse Table Construction
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
CSCE 531 Compiler Construction
LL and Recursive-Descent Parsing Hal Perkins Autumn 2011
Compiler Construction
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
LL and Recursive-Descent Parsing
Compiler Construction
Compiler Structures 7. Yacc Objectives , Semester 2,
… NPDAs continued.
LL and Recursive-Descent Parsing Hal Perkins Autumn 2009
Lecture 18 Bottom-Up Parsing or Shift-Reduce Parsing
Compiler Construction
LL and Recursive-Descent Parsing Hal Perkins Winter 2008
More About Nondeterminism
Normal Forms for Context-free Grammars
Push Down Automata Push Down Automata (PDAs) are L-NFAs with stack memory. Transitions are labeled by an input symbol together with a pair of the form.
Presentation transcript:

Lecture 18 Language Recognized by a PDA CSCE 531 Compiler Construction Lecture 18 Language Recognized by a PDA Topics Language Recognized by a PDA Language recognized by Empty Stack Readings: October 29, 2008

Simple4.l %{ #include "simple4.tab.h" %} digit [0-9]+ %% \n return('\n'); \+ return(PLUS); \* return(TIMES); \( return(LPAREN); \) return(RPAREN); {digit} { yylval= atoi(yytext); return(INTEGER);} yywrap(){ }

Simple4.y %{ #include <ctype.h> int yylineno = 1; %} %token INTEGER PLUS TIMES LPAREN RPAREN %% line : expr '\n' {printf("%d\n", $1);} | line expr '\n' {printf("%d\n", $2);} ; expr : expr PLUS term {$$ = $1 + $3;} | term term : term TIMES factor {$$ = $1 * $3;} | factor factor : LPAREN expr RPAREN {$$ = $2;} | INTEGER {$$ = $1;} /* the default action */

Instantaneous Descriptors The instantaneous descriptor (q, w, γ) specifies q state w ε Σ* - the remaining input γ ε Γ* - the stack contents (with top on left)

Moves relation on instantaneous descriptors For an ID (q, aw, Xγ) we say (q, aw, Xγ) moves to (r, w, Ωγ) and denote this as (q, aw, Xγ) ├ (r, w, Ωγ) If δ (q, a, X) contains (r, Ω) or graphically a, X / Ω q r

Properties of IDs (Instantaneous Desc.) Useful properties in Proofs If (q, w, γ) ├* (r, x, τ) then (q, wu, γ) ├* (r, xu, τ) (adding more input) If (q, w, γ) ├* (r, x, τ) then (q, w, γβ) ├* (r, x, τβ) (adding more stack symbols) If (q, wu, γ) ├* (r, xu, τ) then (q, w, γ) ├* (r, x, τ) (removing extra input) Intuitively …

Adding more input Theorem 6.5a If (q, w, γ) ├* (r, x, τ) then (q, wu, γ) ├* (r, xu, τ) (adding more input)

Adding more Stack symbols on bottom of stack Theorem 6.5b If (q, w, γ) ├* (r, x, τ) then (q, w, γβ) ├* (r, x, τβ) (adding more stack symbols)

Theorem 6. 6 If (q, wu, γ) ├. (r, xu, τ) then (q, w, γ) ├ Theorem 6.6 If (q, wu, γ) ├* (r, xu, τ) then (q, w, γ) ├* (r, x, τ) (removing extra input)

The Language Accepted by a PDA P = (Q, Σ, Γ, δ, q0, Z0, F) Initial State x Initial Stack - (q0, Z0 ) Language accepted by final state L(P) = { w | (q0, w, Z0) ├* (q, ε, α) for q ε F}

PDA for L = {wwR | w ε Σ* }

PDA for L = { wwR | w ε Σ* } Consider an arbitrary string x= wwR ε L 0,Z0/0Z0 1,Z0/1Z0 0,0/00 0,1/01 1,0/10 1,1/11 0,0/ ε, 1,1/ ε ε, Z0/Z0 ε, 0/0, ε, 1/1 ε, Z0/Z0 q r y

L = {wwR | w ε Σ* } is a subset of L(P)

L(P) is a subset of L = {wwR | w ε Σ* }

Language Accepted by a Empty Stack P = (Q, Σ, Γ, δ, q0, Z0, F) N(P) = { w | (q0, w, Z0) ├* (q, ε, ε) }

Theorem 6.9 Theorem 6.9 if L = N(PN) for some PN = (Q, Σ, Γ, δN, q0, Z0, F) then there is a PDA PF = (Q, Σ, Γ, δN, q0, Z0, F) such that L=L(PN).

Constructive Proof of Theorem 6.9 Theorem 6.9 if L = N(PN) for some PN = (Q, Σ, Γ, δN, q0, Z0, F) then there is a PDA PF = (Q, Σ, Γ, δN, q0, Z0, F) such that L=L(PN). ε, X0/X0Z0 p0 q0 qf PN

Homework Given the grammar simple4.y (and simple4.l) Modify the semantic actions so that it produces a trace of productions involved in the parse. If you look at the sequence do you notice anything? 6.2.1b) Strings of 0’s and 1’s such that no prefix has more 1’s than 0’s 6.2.5b,c