Machine Problem 2, due Feb 20

Part of the homework for CS:2820, Spring 2017
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Write a Java program, in file TernaryLogic.java that can be run as follows to read data from a file called f (presuming that this file exists):

[HawkID@serv15 project]$ java TernaryLogic f

When your program is run, it should read a description of a network of ternary logic gates and wires. The allowed gate types should be min, max, neg, istrue, isfalse, and isunknown. Here is an example description (an expansion of the file format discussed in Homework 4 problem 2):

gate A min 4 1.0
gate B max 2 0.5
wire A B 0.1
wire B A 0.3
gate C neg 2 0.5

wire A C 0.1
wire C B 0.1

For gates, the arguments are:

For wires, the arguments are:

The fun part of this assignment is that your program must tolerate and report errors in the input. That is, numbers must be given where expected, no gate name may be defined more than once, and all gate names referenced in wire descriptions must have been declared before use.

When the input is correct, the output to standard output (System.out) should recreate the input, although the order of gates and wires in the output may be changed and numeric fields may be output in equivalent form — so for example, 05.6 might output as 5.600.

Error messages should be output to standard error (System.error) and should reasonably document the error, for example:

cannot open file named xyzzl.bug
shoe found where gate or wire expected
gate X illegally redefined
wire X Y undefined source
wire X Z delay expected

When there are errors, the output to standard output should include all correct parts of the input and, if it includes incorrect parts, those should make sense. The format of the error messages and the output of incorrect parts of the input are deliberately underspecified. You have design decisions to make here.

Note: For now, the count of the number of inputs permitted on a gate is just a number. Later, we will add code to enforce this: A 3 input gate must have exactly 3 wires to its inputs, and we will eliminate this field on gates that only have one input (neg, for example). If you want extra work, try enforcing this.

Grading criteria: No credit will be given to programs that do not represent a substantial attempt at meeting the requirements of this assignment. Your program must:

Note that the requirements for header comments in the file header are absolute. Your name must appear in the form that it appears on your ID card. The TAs will not waste their time doing detective work to attempt to figure out who submitted what code.

Submission: Your solution should consist of a single file, with one public method, main. (Later, we will chop the file into smaller more managable pieces, as it grows.)

To submit your solution, make sure it is in a file called TernaryLogic.java (this requires that the main method be in a class called TernaryLogic. This must be in the current directory. Then, follow the same dialogue with the Linux shell you used for MP1, except that you will use mp2 wherever the instructions said to use mp1.