CS 154 (Section 1 and 2): Formal Languages and Computability, Spring 2009

2nd Programming Assignment: Due 5/1 at 10 a.m.

You will program a Turing Machine in JFLAP. The input alphabet will be five symbols: 0, 1, +, *, and =, and you will be asked to compute function based on the input. Only 0, 1, and x will be used for the output.

Consider that NumberX is any binary string of 0's and 1's, with no leading 0s. [It can be the number 0, it cannot be the empty string. That is, NumberX would Be A String From the following regular expression: (0 + 1(0+1)*).]

Each NumberX should be interpreted as a binary representation of a number, most significant bit first. Your Turing Machine Transducer should calculate the following function:

  1. for input NumberA+NumberB, output the binary number of the two numbers added together. (Note that here, the + is a character, not the regular expression.)
  2. for input NumberA*NumberB, output the binary number of the two numbers multiplied together. (Note that here, the * is a character, not the regular expression.)
  3. for input NumberA=NumberB, the output should be "1" if NumberA is equal to NumberB, and "0" otherwise.

For any input not described by one of the above 3 cases, your program should return "x" as its answer. That is, if the number is not in a valid format, or if there is not exactly one of the three operator symbols, you should reject the input.

  1. Example: Input "11010=11010" gives output "1".
  2. Example: Input "11010=11101" gives output "0".
  3. Example: Input "1101+11" gives output "10000".
  4. Example: Input "1101*11" gives output "100111".
  5. Example: Input "01101*11" gives output "x". (No leading 0s allowed.)
  6. Example: Input "1101*" gives output "x". (No empty number allowed.)
  7. Example: Input "1101*10+11" gives output "x". (Only 1 operator allowed.)

Note on Output: There have been several questions about the output format. For JFLAP, the output is considered to be the string of symbols, starting at the tape head location, and moving to the right, until the last symbol before the first blank. So, if B is the blank symbol, and the tape ends up with ...BBabcdBef, with the tape head on the letter c, the output is cd. (You will see this if you test your machine as a transducer, it gives the output.)

Your Turing Machine should NOT use the building blocks of JFLAP. It can use the shorthand symbols of ~ and ! (matching any character, or not matching a character, see http://www.jflap.org/tutorial/ in the Turing Machine, Construct and Run.) It should use only one tape.

That is all that is required. Your entire submission should be just a single .jff (JFLAP), named LastFirst.jff, where Last and First are replaced by your actual last name and first name. This program will count three times the first program, and there will be no further programming assignments. You are required to get programs working correctly.

Important note: Originally, you were to be required to get all programs to work perfectly in order to qualify for any grade above a C- in the course. I understand that the multiplication part of this assignment may be a bit long, and thus I will not require its solution in the same way. It is still worth a large (2.5%) part of your weighted average, so you should try to get it, and the other programs, working correctly, but at least for the multiplication part, you are not required to have the program work correctly. Each of these three parts will count as 1/4 of your programming grade. (You should just submit one JFLAP program though.)

You should email this assignment to me with the subject
CS154Spring2009 Prog2 Last First
where Last and First are replaced by your name. If you use any other subject, your submission may be lost.