Download presentation
Presentation is loading. Please wait.
1
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
2
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(){ }
3
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 */
4
Instantaneous Descriptors
The instantaneous descriptor (q, w, γ) specifies q state w ε Σ* - the remaining input γ ε Γ* - the stack contents (with top on left)
5
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
6
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 …
7
Adding more input Theorem 6.5a If (q, w, γ) ├* (r, x, τ) then (q, wu, γ) ├* (r, xu, τ) (adding more input)
8
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)
9
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)
10
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}
11
PDA for L = {wwR | w ε Σ* }
12
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
13
L = {wwR | w ε Σ* } is a subset of L(P)
14
L(P) is a subset of L = {wwR | w ε Σ* }
15
Language Accepted by a Empty Stack
P = (Q, Σ, Γ, δ, q0, Z0, F) N(P) = { w | (q0, w, Z0) ├* (q, ε, ε) }
16
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).
17
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
19
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.