Problème 1.
Give a context free grammar for the following language:
L = { a n b m c k ∣ k = n + m }
Solution
The following CFG generates the language L :
S S 1 S 2 S 3 A B C → S 1 ∣ S 2 ∣ S 3 → a S 1 c ∣ a S 1 ∣ A → b S 2 c ∣ b S 2 ∣ B → a S 3 b ∣ c S 3 ∣ C → a A c ∣ a A ∣ a ∣ ε → b B c ∣ b B ∣ b ∣ ε → a C b ∣ c C ∣ c ∣ ε
Problème 2.
Let
L 1 = { a n b m c k ∣ n , m , k ≥ 0 }
and let
L 2 = { a n b n c n ∣ n ≥ 1 }
Complete the pushdown automata M such that L ( M ) = L 1 − L 2 , where Σ = { a , b , c } .
Solution
Given that the 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 M
Problème 3.
The first table:
1 0 x # c □ q s ( q 1 , 1 , x , R ) ( q 1 , 3 , x , R ) ( q s , x , R ) - - - q 1 , 1 ( q 1 , 1 , 1 , R ) ( q 1 , 1 , 0 , R ) - ( q 1 , 2 , # , R ) - - q 1 , 2 ( q 1 , 5 , x , R ) ==( q 1 , 2 , x , R ) == ( q 1 , 2 , x , R ) - - - q 1 , 3 ( q 1 , 3 , 1 , R ) ( q 1 , 3 , 0 , R ) - ( q 1 , 4 , # , R ) - - q 1 , 4 ==( q 1 , 3 , c , L ) == ( q 1 , 7 , x , R ) ( q 1 , 4 , x , R ) - - - q 1 , 5 ( q 1 , 5 , 1 , R ) ( q 1 , 5 , 0 , R ) - ( q 1 , 8 , # , R ) - - q 1 , 6 ( q 1 , 6 , 1 , R ) ( q 1 , 6 , 0 , R ) - ( q 1 , 9 , # , R ) - - q 1 , 7 ( q 1 , 7 , 1 , R ) ( q 1 , 7 , 0 , R ) - ( q 1 , 10 , # , R ) - - q 1 , 8 ==( q 1 , 8 , 1 , R ) == ==( q 1 , 8 , 1 , R ) == - - ==( q 1 , 8 , c , R ) == ==( q 1 , e n d 1 , □ , L ) == q 1 , 9 ==( q 1 , 9 , 1 , R ) == ==( q 1 , 9 , 0 , R ) == - - ==( q 1 , 9 , 1 , R ) == ==( q 1 , e n d 2 , □ , L ) == q 1 , 10 ==( q 1 , 10 , c , R ) == ==( q 1 , 10 , 1 , R ) == - - ==( q 1 , 10 , c , R ) == ==( q 1 , e n d 3 , □ , L ) == q 1 , e n d 1 ( q 1 , e n d 1 , 1 , L ) ( q 1 , e n d 1 , 0 , L ) - ( q 1 , e n d 2 , # , L ) ( q 1 , e n d 1 , c , L ) - q 1 , e n d 2 ( q 1 , e n d 3 , 1 , L ) ( q 1 , e n d 3 , 0 , L ) ( q 1 , e n d 2 , x , L ) ( q 1 , e n d 2 , # , L ) - - q 1 , e n d 3 ( q 1 , e n d 3 , 1 , L ) ( q 1 , e n d 3 , 0 , L ) ( q 1 , e n d 3 , x , L ) ( q 1 , e n d 3 , # , L ) - ( q 2 , s , □ , R )
The second table:
1 0 x # c □ q 2 , s - - ==( q 2 , s , □ , R ) == ==( q 2 , 1 , □ , R ) == - - q 2 , 1 - - ==( q 2 , 1 , □ , R ) == ==( q 2 , 1 , □ , R ) == - - q 2 , 2 ==( q 2 , 1 , □ , L ) == ==( q 2 , 1 , □ , L ) == - - ==( q 2 , 1 , □ , L ) == ( q 3 , s , □ , L )
The final transition table:
1 0 c □ q 3 , s ( q 3 , s , 1 , R ) ( q 3 , s , 0 , R ) ( q 3 , s , c , R ) ( q 3 , 1 , □ , R ) q 3 , 1 ( q 3 , 2 , 0 , L ) ( q 3 , 2 , 1 , L ) ( q 3 , 1 , 1 , L ) ( q 3 , 2 , □ , R ) q 3 , 2 ( q 3 , 1 , □ , L ) ( q 3 , 1 , □ , L ) ( q 3 , 1 , □ , L ) ( q 3 , e n d , □ , L )