Differences
This shows you the differences between two versions of the page.
lfa:cfgpda [2017/11/15 14:45] pdmatei created |
lfa:cfgpda [2018/11/07 10:55] (current) pdmatei |
||
---|---|---|---|
Line 74: | Line 74: | ||
**Induction step:** | **Induction step:** | ||
- | Suppose: | + | Suppose $math[S\Rightarrow^* \alpha\beta] in $math[n+1] steps. Then $math[S\Rightarrow^* uv \Rightarrow\alpha\beta]. Also, $math[\alpha] and $math[u] contain terminal symbols only, while $math[\beta] and $math[v] start with a non-terminal. |
- | + | ||
- | $math[S\Rightarrow^* \alpha\beta] in $math[n+1] steps. Then $math[S\Rightarrow^* uv \Rightarrow\alpha\beta]. Also, $math[\alpha] and $math[u] contain terminal symbols, while $math[\beta] and $math[v] start with a non-terminal. | + | |
Let us look at the last production $math[uv\Rightarrow\alpha\beta]. Since $math[v] must start with a non-terminal, then $math[v] is a word of the form $math[Av']. Then $math[A] is the first non-terminal, hence, a production $math[A\rightarrow\gamma] must exist in $math[G]. Moreover, we can safely assume that $math[\gamma=xBy] where $math[B] is a non-terminal. (the reasoning is similar if no non-terminal in $math[\gamma] exists. Therefore, our derivation actually has the following structure: | Let us look at the last production $math[uv\Rightarrow\alpha\beta]. Since $math[v] must start with a non-terminal, then $math[v] is a word of the form $math[Av']. Then $math[A] is the first non-terminal, hence, a production $math[A\rightarrow\gamma] must exist in $math[G]. Moreover, we can safely assume that $math[\gamma=xBy] where $math[B] is a non-terminal. (the reasoning is similar if no non-terminal in $math[\gamma] exists. Therefore, our derivation actually has the following structure: | ||
Line 93: | Line 91: | ||
$justprop | $justprop | ||
- | If $math[(q,\alpha,S)\vdash^*_M(q,\epsilon,\beta)], where $math[\alpha\in\Sigma^*] and $math[\beta\in\V^*], then $math[S\Rightarrow_G^*\alpha\beta] | + | If $math[(q,\alpha,S)\vdash^*_M(q,\epsilon,\beta)], where $math[\alpha\in\Sigma^*] and $math[\beta\in V^*], then $math[S\Rightarrow_G^*\alpha\beta] |
$end | $end | ||
Line 106: | Line 104: | ||
With this in mind, we shall construct **non-terminals** in a grammar as triples: | With this in mind, we shall construct **non-terminals** in a grammar as triples: | ||
* $math[\langle qXr \rangle] where $math[q,r] are states of the PDA and $math[X] is a symbol. | * $math[\langle qXr \rangle] where $math[q,r] are states of the PDA and $math[X] is a symbol. | ||
- | * such a non-terminal models a **sequence of transitions** where the PDA goes from state $math[q] to state $math[r], while the //pop//-event $math[X] occurs (i.e. a sequence of push-pops which do not touch $math[X] occur, and which end up with $math[X] being removed). | + | * such a non-terminal models a **sequence of transitions** where the PDA goes from state $math[q] to state $math[r], while the //pop//-event $math[X] occurs (i.e. a sequence of push-pops which do not touch $math[X] occur, and which end up with $math[X] being removed). The idea is that $math[\langle qXr \Rightarrow^* w] iff $math[(q,w,X)\vdash^*_M (r,\epsilon,\epsilon)]. That is, if $math[w] is consumed starting from state $math[q] with $math[X] on the stack and ending up in state $math[r], then $math[w] can be derived in our grammar from non-terminal $math[\langle qXr\rangle] |
==== Construction ==== | ==== Construction ==== | ||
We shall require the following conditions on the PDA at hand: | We shall require the following conditions on the PDA at hand: | ||
* it should have a **unique** final state. Moreover, in this final state, we //pop// the empty symbol; | * it should have a **unique** final state. Moreover, in this final state, we //pop// the empty symbol; | ||
- | * each transition performs exactly one //push// or one //pop//: | + | * each transition performs a stack operation of type $math[Y_1Y_2] (e.g. a push) or $math[\epsilon] (a pop): |
- | * if the PDA performs a combination of push-pops, we can add intermediate transitions with one push/pop; | + | * if the PDA performs a more complicated combination of push-pops, we can add intermediate transitions which obey the above rule; |
* if the PDA does not touch the stack, we push a dummy symbol and subsequently pop it; | * if the PDA does not touch the stack, we push a dummy symbol and subsequently pop it; | ||
Line 122: | Line 119: | ||
* $math[V=\{\langle qXr \rangle \mid q,r\in K,X\in\Gamma \}\cup\Sigma]; some non-terminals from $math[V] may end up being unused; | * $math[V=\{\langle qXr \rangle \mid q,r\in K,X\in\Gamma \}\cup\Sigma]; some non-terminals from $math[V] may end up being unused; | ||
- | * we build production $math[S\rightarrow\langle q_0,Z_0,p\rangle] where $math[p\in F]. This non-terminal models the sequence of transitions going from the initial state to the final state, while the empty symbol is popped. This sequence of transitions marks the acceptance of a word. | + | * we build production $math[S\rightarrow\langle q_0Z_0p\rangle] where $math[p\in F]. This non-terminal models the sequence of transitions going from the initial state to the final state, while the empty symbol is popped. This sequence of transitions marks the acceptance of a word. |
* If $math[\Delta] contains $math[(q,a,X,r,Y_1Y_2)], then we build $math[\mid K\mid^2] productions of the form: | * If $math[\Delta] contains $math[(q,a,X,r,Y_1Y_2)], then we build $math[\mid K\mid^2] productions of the form: | ||
* $math[qXr_2 \rightarrow a\langle rY_1r_1\rangle\langle r_1Y_2r_2\rangle] for all $math[r_1,r_2\in K] | * $math[qXr_2 \rightarrow a\langle rY_1r_1\rangle\langle r_1Y_2r_2\rangle] for all $math[r_1,r_2\in K] | ||
- | * in other words, the event of popping $math[X] from $math[q] corresponds to reading $math[a], then popping $math[Y_1] from $math[r], then reaching some state $math[r_1], then popping $math[Y_2], and reaching some $math[r_2]. $math[r_1] and $math[r_2] can be **any** state, so by these productions, we are considering **all possible** such sequences of events. | + | * in other words, in order to obtain a stack with everything unchanged 'below' $math[X], starting from $math[q] and ending up in some $math[r_2], we must eat symbol $math[a], then from $math[r] we must pop $math[Y_1], then $math[Y_2]. We do not know what state will be reached after popping $math[Y_1], so we consider all possible states. The same holds for $math[Y_2]. |
* If $math[\Delta] contains $math[(q,a,X,r,\epsilon)], then we build the production: | * If $math[\Delta] contains $math[(q,a,X,r,\epsilon)], then we build the production: | ||
* $math[ \langle qXr \rangle \rightarrow a] where $math[a] could be the empty string; | * $math[ \langle qXr \rangle \rightarrow a] where $math[a] could be the empty string; | ||
Line 131: | Line 128: | ||
=== Example === | === Example === | ||
- | Consider the following PDA, which accepts $math[L=\{a^nb^n\mid n\geq 0\}]. | + | Consider the following PDA, which accepts $math[L=\{0^n1^n\mid n\geq 0\}]. |
^ Current state ^ Input ^ Stack top ^ Next state ^ Stack op ^ | ^ Current state ^ Input ^ Stack top ^ Next state ^ Stack op ^ | ||
- | | $math[q_0] | $math[a] | $math[Z_0] | $math[q_0] | $math[XZ_0] | | + | | $math[q_0] | $math[0] | $math[Z_0] | $math[q_0] | $math[XZ_0] | |
- | | $math[q_0] | $math[a] | $math[X] | $math[q_0] | $math[XX] | | + | | $math[q_0] | $math[0] | $math[X] | $math[q_0] | $math[XX] | |
- | | $math[q_0] | $math[b] | $math[X] | $math[q_1] | $math[\epsilon] | | + | | $math[q_0] | $math[1] | $math[X] | $math[q_1] | $math[\epsilon] | |
- | | $math[q_1] | $math[b] | $math[X] | $math[q_1] | $math[\epsilon] | | + | | $math[q_1] | $math[1] | $math[X] | $math[q_1] | $math[\epsilon] | |
| $math[q_1] | $math[\epsilon] | $math[Z] | $math[q_1] | $math[\epsilon] | | | $math[q_1] | $math[\epsilon] | $math[Z] | $math[q_1] | $math[\epsilon] | | ||
Line 199: | Line 196: | ||
$math[\langle q_1 Z_0 q_1 \rangle \rightarrow \epsilon] | $math[\langle q_1 Z_0 q_1 \rangle \rightarrow \epsilon] | ||
- | Next, we observe that the rules having $math[\langle q_0 Z_0 q_0 \rangle] and $math[\langle q_0 X q_0] continue to generate non-terminals, ad-infinitum. Derivations including them will never produce actual words. For this reason, we ignore such rules: | + | Next, we observe that the rules having $math[\langle q_0 Z_0 q_0 \rangle] and $math[\langle q_0 X q_0\rangle] continue to generate non-terminals, ad-infinitum. Derivations including them will never produce actual words. For this reason, we ignore such rules: |
$math[S \rightarrow \langle q_0 Z_0 q_1 \rangle] | $math[S \rightarrow \langle q_0 Z_0 q_1 \rangle] |