| |
Computer Science 60
Principles of Computer Science
Spring 2010
Assignment 10, extra credit in JFLAP!
Due Sunday, April 11 by 11:59 pm
For this extra credit, you'll need to download JFLAP.jar from here.
It's not the most up-to-date version, but it runs on both Max OS X and PCs.
To start JFLAP, double-click the JFLAP.jar file. Click on the "grammar" button to start defining a grammar. Note that
there is no "or" bar (the vertical bar), but separate rules allow for as many "or"s as needed. In order to test a string, you
can choose "brute force parse" from the input menu.
Once you have JFLAP working, for entirely optional extra credit of up to +15 points (5 points each), create three separate JFLAP
grammars that generate the following languages:
-
The first grammar, grammar1.jff, should generate the set of all strings of 0's and 1's in which the number of 0's is
even and the number of 1's is odd. This should be a regular grammar, i.e., every rule should have only one nonterminal
symbol on the left and zero or one nonterminal on the right - and if there is a nonterminal on the right that nonterminal must be the very
last symbol in the rule!
For example, this grammar should generate the strings 01000, 111, and 1100111; it should not generate the
strings 10, the empty string, nor 1100.
Save this grammar in a file named grammar1.jff. The .jff extension is the default for JFLAP.
-
The second grammar, grammar2.jff, should generate
the set of all strings of 0's, 1's, and 2's such that the 0's come before the 1's and the 1's come before the 2's and either
the number of 0's is equal to the number of 1's or the number of 0's is equal to the number of 2's. For example, 00112, 01112,
1111, and 000111222 should all be generated by this grammar.
This should be a context-free grammar, i.e., one in which
every rule has a single nonterminal symbol on the left, though rules may have any mix of terminal symbols (0,1,2) or
nonterminal symbols (capital letters) on the right.
Save this grammar in a file named grammar2.jff.
- a challenge!
The third grammar, grammar3.jff, the set of all strings of 0's, 1's, and 2's of the form "string1 2 string2 2 string3 2 ... 2 stringN" where each "stringK" is
made exclusively of 0's and 1's. In addition, there must be some pair of these intervening binary strings such that one is the
reverse of the other. For example, 00120002100 is generated by this grammar (note that the leading 001 is the reverse of the
trailing 100 in this case). However, the string 1200210 should not be generable by your grammar. The empty string is the
reverse of itself, so that both 2012 and 2 alone should be generated by your grammar.
As with the previous grammar, this one must be context-free.
Save this grammar in a file named grammar3.jff.
Submit one, two, or all three of these files under the names above: grammar1.jff, grammar2.jff,
and grammar3.jff under week 10. Have fun with JFLAP!
|