What to submit and when:

- All submissions are electronic: by e-mail to elenam at morris.umn.edu and CC to all lab partners. Please do not delete your e-mail from "Sent mail" or your mailbox until the end of the semester.
- When working on the lab, please comment your work so that it is clear what contributions of each person are.
- At the end of the lab each group should send me the results of their in-class work. Please indicate if this is your final submission.
- If your submission at the end of the lab time was not final, please send me(CC to the lab partner(s)) a final copy before the due time. Please use the subject "3501 Lab N", where N is the lab number.

Work in pairs

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

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:

- A context free grammar for the language of strings a^n b^m, where n >= m
- A context free grammar for the language of strings a^k followed by any number of b followed by c^k
- A context-free grammar for odd-length strings of alternating zeros and ones. It can start with either zero or one.
- 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.
- A context-free grammar for a language of 0, 1, true, false,
operations
`<, >, ==`

, a ternary conditional operator`?:`

, and parentheses. The order of precedence is as follows: parentheses, the comparison operations, the conditional operator and then 0, 1, true and false (all at the same level).The conditional operator is defined as following:

evalautes e1, and if it is true then it evaluates and returns e2, otherwise it evaluates and returns e3. For example:`e1? e2 : e3`

would be interpreted as`0 < 1? 0 : 1`

which becomes`(0 < 1) ? 0 : 1`

after the condition is evaluated, which would in turn result in 0.`true ? 0 : 1`

The comparison operators

`<, >, ==`

are left-associative, i.e. i.e.

should be interpreted as`0 == 1 == false`

which evaluates to`(0 == 1) == false`

which is true.`false == false`

The conditional is right-associative:

is interpreted as`0 > 1 ? 0 : 0 == 0 ? 1 : 0`

then evaluated as`(0 > 1) ? 0 : ((0 == 0) ? 1 : 0)`

then as`false ? 0 : ((0 == 0) ? 1 : 0)`

then as`false ? 0 : (true ? 1 : 0)`

which will return 1.`false ? 0 : 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 correct precedence and associativity for all operations. Your write-up for this problem should briefly explain how this is done. - 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)
- A pushdown automaton for the language of strings a^n b^m where n <= m.
- A pushdown automaton for strings w1 w2 where w2 contains a reversed w1 as a substring and w1 has at least one symbol. The alphabet is 0,1.

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.

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

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. Clearly describe the strategy.

- The third language (a^n b^j a^n b^j, n >= 0, j >= 0) -- computer goes first.
- The eighth language (a^k b^n c^n d^j: j not equal to k) -- you go first

- Submit your JFLAP files as attachments, CC your group. Make sure to submit your automata files (as .jff) and your input data (as .txt). Make sure to follow the naming requirements! Make it clear which data refers to which automaton.

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.