Skip to content
Snippets Groups Projects
Commit 9bed047e authored by Michael Leuschel's avatar Michael Leuschel
Browse files

add first version of PDA to CFG notebook

parent 15c2a0e6
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# PDA nach kfG
%% Cell type:code id: tags:
``` prob
::load
MACHINE PDA_to_CFG
/* Translating a PDA to a CFG */
SETS
STATES = {z0,z1, symbol};
SYMBOLS={a,b, A, BOT, lambda, S} /* BOT = # = bottom of stack*/
DEFINITIONS
CFG_Alphabet == (STATES*(SYMBOLS-{lambda})*STATES);
Σ == {a,b};
Γ == {A,BOT};
ANIMATION_FUNCTION1 == {r,c,i| r=1 ∧ c∈dom(cur) ∧ i=prj1(STATES,SYMBOLS)(prj1(STATES*SYMBOLS,STATES)(cur(c)))};
ANIMATION_FUNCTION2 == {r,c,i| r=2 ∧ c∈dom(cur) ∧ i=prj2(STATES,SYMBOLS)(prj1(STATES*SYMBOLS,STATES)(cur(c)))};
ANIMATION_FUNCTION3 == {r,c,i| r=3 ∧ c∈dom(cur) ∧ i=prj2(STATES*SYMBOLS,STATES)(cur(c))};
ANIMATION_STR_JUSTIFY_LEFT == TRUE;
SET_PREF_PP_SEQUENCES == TRUE;
PDA_STATES == (STATES-{symbol});
SYMS(s) == IF (s=lambda) THEN [] ELSE [SYM(s)] END;
SYM(s) == (symbol,s,symbol);
TERMINALS == {x|∃t.(t∈Σ ∧ x=SYM(t))}
CONSTANTS delta, Productions
PROPERTIES
/* A PDA accepting {a^mb^m| m≥1} ; Beispiel von Info 4 (Folie 95ff) */
delta = { (z0,a,BOT) ↦ (z0,[A,BOT]),
(z0,a,A) ↦ (z0,[A,A]),
(z0,b,A) ↦ (z1,[]),
(z1,lambda,BOT) ↦ (z1,[]),
(z1,b,A) ↦ (z1,[]) } ∧
Productions = /* Punkt 1 Folie 109 */
{ lhs,rhs | ∃z.(z∈PDA_STATES ∧ lhs=SYM(S) ∧ rhs = [(z0,BOT,z)])}
/* Punkt 2 Folie 109 */
{ lhs,rhs | ∃(z,a,A,z2).((z,a,A)↦(z2,[])∈delta ∧
lhs=(z,A,z2) ∧ rhs = SYMS(a)) }
/* Punkt 3 Folie 110 */
{ lhs,rhs | ∃(z,a,A,B,z1,z2).((z,a,A)↦(z1,[B])∈delta ∧ z2∈PDA_STATES ∧
lhs=(z,A,z2) ∧ rhs = SYMS(a)^[(z1,B,z2)]) }
/* Punkt 4 Folie 110 */
{ lhs,rhs | ∃(z,a,A,B,C,z1,z2,z3).((z,a,A)↦(z1,[B,C])∈delta ∧
z2∈PDA_STATES ∧ z3∈PDA_STATES ∧
lhs=(z,A,z3) ∧ rhs = SYMS(a)^[(z1,B,z2),(z2,C,z3)]) }
VARIABLES cur
INVARIANT
cur ∈ seq(CFG_Alphabet)
INITIALISATION cur:=SYMS(S)
OPERATIONS
ApplyRule(LHS,RHS,pre,post) = PRE LHS↦RHS ∈ Productions ∧
cur = pre^[LHS]^post ∧
ran(pre) ⊆ TERMINALS /* Links Ableitung */
THEN
cur := pre^RHS^post
END
END
```
%% Output
Loaded machine: PDA_to_CFG
%% Cell type:code id: tags:
``` prob
:constants
```
%% Output
Machine constants set up using operation 0: $setup_constants()
%% Cell type:code id: tags:
``` prob
:init
```
%% Output
Machine initialised using operation 1: $initialise_machine()
%% Cell type:code id: tags:
``` prob
:show
```
%% Output
<table style="font-family:monospace"><tbody>
<tr>
<td style="padding:10px">symbol</td>
</tr>
<tr>
<td style="padding:10px">S</td>
</tr>
<tr>
<td style="padding:10px">symbol</td>
</tr>
</tbody></table>
<Animation function visualisation>
%% Cell type:code id: tags:
``` prob
:browse
```
%% Output
Machine: PDA_to_CFG
Sets: STATES, SYMBOLS
Constants: delta, Productions
Variables: cur
Operations:
ApplyRule((symbol|->S|->symbol),[(z0|->BOT|->z0)],[],[])
ApplyRule((symbol|->S|->symbol),[(z0|->BOT|->z1)],[],[])
%% Cell type:code id: tags:
``` prob
:exec ApplyRule
```
%% Output
Executed operation: ApplyRule((symbol|->S|->symbol),[(z0|->BOT|->z0)],[],[])
%% Cell type:code id: tags:
``` prob
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment