CMPS 260 Spring 2020
HW #6: Context-free Grammars, a little Pushdown Automata
Due: 11:59pm, May 4

1. Present a context-free grammar for the language { anbm  |  n ≠ 2m }

Hint: See Linz's solution to Problem 5.1.9(e) (i.e., Problem 9(e) in Section 1 of Chapter 5).


2. Present a context-free grammar for the language { anbm  |  2n ≤ m ≤ 3n }


3. Present a context-free grammar for the language { w ∈ {a,b}*  |  na(w) = 2nb(w) + 1 }

Hint: See Linz's solution to Problem 5.1.9(e).


4. Present a context-free grammar for the language { anbmck  |  k = |n−m| }

Hint: k = |n−m| is equivalent to k+m = n ∨ k+n = m.


5. Present an unambiguous context-free grammar for the language of regular expressions over the alphabet {a,b}. An ambiguous grammar for that language is as follows:

S  ⟶  a  |  b  |  ∅  |  (S)  |  S+S  |  S·S  |  S*

Your grammar should be such that derivation trees are consistent with the conventional operator precedence rules of regular expressions, which say that star has highest precedence, then concatenation, then union. For example, a derivation tree for the regular expression ∅+b·a* should have one subtree correspoding to the subexpression ∅ and another one corresponding to the subexpression b·a*. Within the latter should be a subtree corresponding to the subexpression a*.

Hint: Compare the grammars in Examples 5.11 and 5.12 of Linz.


6. Show the context-free grammar obtained by removing useless symbols from this grammar:

S aA | Bb | Cc
A Ac | aSAC
B c | bDaS
C cBa | CS
D d | dD | cA

Include a brief narration that justifies the removal of whatever symbols/productions were omitted in arriving at your answer.


7. Present a Chomsky Normal Form grammar that is equivalent to this context-free grammar:

S Sab | bA
A aSAb | ab


8. Consider the following Chomsky Normal Form grammar G:

SAB | b
ASA | a
BBS | b

Use the CYK algorithm to determine whether or not w = bbabb is a member of L(G). Specifically, fill in the relevant cells of the matrix pictured below so that the cell in row i and column j contains Vi,j = { X ∈ {S,A,B} : X ⟹+ wi,j }, where wi,j is the substring of w beginning at its i-th symbol and ending with its j-th symbol. (Your answer is expected to include not only the answer to the question "Is bbabb ∈ L(G)?" but also the correctly filled in table.)

Recall that, for i satisfying 1≤i≤|w|, X ∈ Vi,i iff X → wi,i is a production. Meanwhile, for i and j satisfying 1≤i<j≤|w|, X ∈ Vi,j iff there exists k satisfying i≤k<j such that X → YZ is a production for some Y ∈ Vi,k and Z ∈ Vk+1,j.

     1      2      3      4      5
  +------+------+------+------+------+
  |      |      |      |      |      |
1 |      |      |      |      |      |
  |      |      |      |      |      |
  +------+------+------+------+------+
         |      |      |      |      |
       2 |      |      |      |      |
         |      |      |      |      |
         +------+------+------+------+
                |      |      |      |
              3 |      |      |      |
                |      |      |      |
                +------+------+------+
                       |      |      |
                     4 |      |      |
                       |      |      |
                       +------+------+
                              |      |
                            5 |      |
                              |      |
                              +------+


9. Present a Pushdown Automaton that accepts the language { anbmck  |  k = |n−m| } (of Problem 4).