profile pic
⌘ '
raccourcis clavier

Problème 1.

Give a context free grammar for the following language:

L={anbmckkn+m}L = \{a^nb^mc^k \mid k \neq n + m\}

Solution

The following CFG generates the language LL:

SS1S2S3S1aS1caS1AS2bS2cbS2BS3aS3bcS3CAaAcaAaεBbBcbBbεCaCbcCcε\begin{aligned} S &\rightarrow S_1 \mid S_2 \mid S_3 \\ S_1 &\rightarrow aS_1c \mid aS_1 \mid A \\ S_2 &\rightarrow bS_2c \mid bS_2 \mid B \\ S_3 &\rightarrow aS_3b \mid cS_3 \mid C \\ A &\rightarrow aAc \mid aA \mid a \mid \varepsilon \\ B &\rightarrow bBc \mid bB \mid b \mid \varepsilon \\ C &\rightarrow aCb \mid cC \mid c \mid \varepsilon \end{aligned}

Problème 2.

Let

L1={anbmckn,m,k0}L_1 =\{a^nb^mc^k \mid n,m,k \geq 0\}

and let

L2={anbncnn1}L_2 = \{a^nb^nc^n \mid n \geq 1\}

Complete the pushdown automata MM such that L(M)=L1L2L(M) = L_1 - L_2, where Σ={a,b,c}\Sigma = \{a,b,c\}.

Solution

Given that the L(M)L(M) will accept all string where the number of a’s, b’s, and c’s are not all the same or there are zero of one or more types of characters, the following is the pushdown automata MM

Problème 3.

The first table:

10x#c\square
qsq_{s}(q1,1,x,R)(q_{1,1}, x, R)(q1,3,x,R)(q_{1,3}, x, R)(qs,x,R)(q_{s}, x, R)---
q1,1q_{1,1}(q1,1,1,R)(q_{1,1},1,R)(q1,1,0,R)(q_{1,1},0,R)-(q1,2,#,R)(q_{1,2}, \#, R)--
q1,2q_{1,2}(q1,5,x,R)(q_{1,5},x,R)==(q1,2,x,R)(q_{1,2},x,R)==(q1,2,x,R)(q_{1,2}, x, R)---
q1,3q_{1,3}(q1,3,1,R)(q_{1,3},1,R)(q1,3,0,R)(q_{1,3},0,R)-(q1,4,#,R)(q_{1,4}, \#, R)--
q1,4q_{1,4}==(q1,3,c,L)(q_{1,3},c,L)==(q1,7,x,R)(q_{1,7},x,R)(q1,4,x,R)(q_{1,4}, x, R)---
q1,5q_{1,5}(q1,5,1,R)(q_{1,5},1,R)(q1,5,0,R)(q_{1,5},0,R)-(q1,8,#,R)(q_{1,8},\#,R)--
q1,6q_{1,6}(q1,6,1,R)(q_{1,6},1,R)(q1,6,0,R)(q_{1,6},0,R)-(q1,9,#,R)(q_{1,9},\#,R)--
q1,7q_{1,7}(q1,7,1,R)(q_{1,7},1,R)(q1,7,0,R)(q_{1,7},0,R)-(q1,10,#,R)(q_{1,10},\#,R)--
q1,8q_{1,8}==(q1,8,1,R)(q_{1,8},1,R)====(q1,8,1,R)(q_{1,8},1,R)==--==(q1,8,c,R)(q_{1,8}, c,R)====(q1,end1,,L)(q_{1,end1}, \square, L)==
q1,9q_{1,9}==(q1,9,1,R)(q_{1,9},1,R)====(q1,9,0,R)(q_{1,9},0,R)==--==(q1,9,1,R)(q_{1,9},1,R)====(q1,end2,,L)(q_{1,end2}, \square, L)==
q1,10q_{1,10}==(q1,10,c,R)(q_{1,10},c,R)====(q1,10,1,R)(q_{1,10},1,R)==--==(q1,10,c,R)(q_{1,10},c,R)====(q1,end3,,L)(q_{1,end3}, \square, L)==
q1,end1q_{1,end1}(q1,end1,1,L)(q_{1,end1},1,L)(q1,end1,0,L)(q_{1,end1},0,L)-(q1,end2,#,L)(q_{1,end2},\#,L)(q1,end1,c,L)(q_{1,end1},c,L)-
q1,end2q_{1,end2}(q1,end3,1,L)(q_{1,end3},1,L)(q1,end3,0,L)(q_{1,end3},0,L)(q1,end2,x,L)(q_{1,end2},x,L)(q1,end2,#,L)(q_{1,end2},\#,L)--
q1,end3q_{1,end3}(q1,end3,1,L)(q_{1,end3},1,L)(q1,end3,0,L)(q_{1,end3},0,L)(q1,end3,x,L)(q_{1,end3},x,L)(q1,end3,#,L)(q_{1,end3},\#,L)-(q2,s,,R)(q_{2},s,\square,R)

The second table:

10x#c\square
q2,sq_{2,s}--==(q2,s,,R)(q_{2,s}, \square, R)====(q2,1,,R)(q_{2,1}, \square, R)==--
q2,1q_{2,1}--==(q2,1,,R)(q_{2,1}, \square, R)====(q2,1,,R)(q_{2,1}, \square, R)==--
q2,2q_{2,2}==(q2,1,,L)(q_{2,1},\square,L)====(q2,1,,L)(q_{2,1},\square,L)==--==(q2,1,,L)(q_{2,1},\square,L)==(q3,s,,L)(q_{3,s}, \square, L)

The final transition table:

10c\square
q3,sq_{3,s}(q3,s,1,R)(q_{3,s},1,R)(q3,s,0,R)(q_{3,s},0,R)(q3,s,c,R)(q_{3,s},c,R)(q3,1,,R)(q_{3,1},\square,R)
q3,1q_{3,1}(q3,2,0,L)(q_{3,2}, 0, L)(q3,2,1,L)(q_{3,2}, 1, L)(q3,1,1,L)(q_{3,1}, 1, L)(q3,2,,R)(q_{3,2},\square,R)
q3,2q_{3,2}(q3,1,,L)(q_{3,1}, \square, L)(q3,1,,L)(q_{3,1}, \square, L)(q3,1,,L)(q_{3,1}, \square, L)(q3,end,,L)(q_{3,end}, \square, L)