Assignment 6

Nils Anders Danielsson (thanks to Mohammad Ahmadpanah for feedback)

  1. Four grammar transformations, Bin, Del, Unit and Term, were discussed in a lecture. The results of the Bin and Term transformations are not always uniquely defined: there is a choice of how to name the new nonterminals that may be introduced.

    Consider the context-free grammar G = ({EON}, {+, −, 1}, P, E), where the set of productions P is defined in the following way:

      E → E O E | N
      O → + | − | ε
      N → 1 | 1 N

    1. (1p) Construct one possible (correct) result of applying the Bin transformation to G. Denote this grammar by G.
    2. (1p) Construct the result of applying the Del transformation to G. Denote this grammar by G.
    3. (1p) Construct the result of applying the Unit transformation to G. Denote this grammar by G.
    4. (1p) Construct one possible (correct) result of applying the Term transformation to G. Denote this grammar by G.
    5. (2p) Construct the CYK table for G and the string w = 1 + 1 1 − 1.

    The productions of G, G, G and G should be given in separate text files using the UTF-8 character encoding. The text in each such file has to match the following context-free grammar: ({GrammarProdsProdTNsTNNT}, DT ∪ TT ∪ NT, P, Grammar), where DT = {’\n’, ’|’, ’→’, ’ε’}, TT = {’+’, ’-’, ’1’}, and P includes exactly

      Grammar → N ’→’ Prods ’\n’ Grammar | ’\n’ | ε,
      Prods → Prod ’|’ Prods | Prod,
      Prod → TN TNs | ’ε’,
      TNs → TN TNs | ε,
      TN → T | N,

    as well as

      {T → t | t ∈ TT} and
      {N → n | n ∈ NT}.

    You get to choose the set of terminals NT, as long as it is disjoint with DT ∪ TT and each terminal is exactly one Unicode code point ( character).

    In the grammar above, note the difference between the code point ’ε’ and the notation ε for the empty string, as well as the difference between ’|’ and |, and ’→’ and .

    An explanation of each nonterminal:

    As an example, the productions of G could be given in the following way (with NT = {’E’, ’O’, ’N’}):

    E→EOE|N
    O→+|-|ε
    N→1|1N
  2. (4p) Prove that { int␣X;␣X␣=␣3;  | X ∈ {a, …, z}+}, containing strings like “int␣foo;␣foo␣=␣3;”, is not a context-free language over the alphabet {a, …, z} ∪ {0, …, 9} ∪ {=;}.

    You may use the following lemmas: