CSci 3501 Algorithms and Computability - Lab 11.

Due Wednesday, November 10th at 11:59pm

What to submit and when:

Lab assignment

Work in pairs

Lab overview and goals

The goal of the lab is to get practice with context-free grammars, push-down automata, and the pumping lemma for context-free languages.

Context-free grammars and pushdown automata (20 points)

Please refer to the corresponding sections of the JFLAP tutorial, namely Entering grammars (just pressing "enter" in RHS enters an empty string), Brute Force Parser for constructing parse trees, and Constructing a push-down automaton.

Your tasks are as follows:

  1. A context-free grammar for odd-length strings of alternating zeros and ones
  2. A context-free grammar of strings of a,b that has more occurrences of "a" than occurrences of "b". The order of letters is arbitrary. Test your automaton on strings baaba and aaab and export the corresponding parse trees as jpg files.
  3. A context-free grammar for a language of 0, 1, true, false, operations <, >, == , a ternary conditional operator ?:, and parentheses. The comparison operations have higher precedence than the conditional.

    The conditional operator is defined as following:

    e1? e2 : e3
    evalautes e1, and if it is true then it evaluates and returns e2, otherwise e3. For example:
     0 < 1? 0 : 1
    returns 0. <, >, == are left-associative, i.e.
    0 == 1 == true
    should be interpreted as
    (0 == 1) == true
    (and is expected to return false). The conditional is right-associative:
     0 > 1 ? 0 : 0 == 0 ? 1 : 0
    is interpreted as
     0 > 1 ? 0 : (0 == 0 ? 1 : 0)
    and is expected to return 1.

    Test your grammar on all of the test cases above and two more cases that check for precedence, associativity, and parentheses. Submit jpg files for the parse trees. Note that language designers don't always get the associativity right.

    Important: your grammar must enforce the right precedence and associativity for all operations. Your write-up for this problem should briefly explain how this is done.

  4. A pushdown automaton for the language of strings a^k followed by any number of b followed by c^k (do not convert your grammar from the previous question into an automaton or vice versa)
  5. A pushdown automaton for the language of strings a^n b^m where n <= m.
  6. A pushdown automaton for strings w1 w2 where w2 contains a reversed w1 as a substring. The alphabet is 0,1. Assume that w1 has at least one symbol.

Convert context-free grammars to pushdown automata (3 points)

Use the option Convert CFG to PDA (LL) for this problem. In a plain-text file explain what rules were added to the PDA and why.

  1. Convert the grammar for the language of palindromes to a PDA. The alphabet is 0,1. Submit the resulting PDA.

Play the context-free "pumping lemma game" (7 points) -- moved to the next lab

Use the tutorial for the pumping lemma. Play the "pumping lemma game" for the following examples. For each example state whether the language is context-free; justify it based on which side has a winning strategy in the pumping lemma game.

What to submit

CSci 3501 course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.