CMPS 260 Spring 2022
Programming Assignment: DFA Simulation
Deadline: 11:59pm, Friday, April 22

Provided are the following Java classes, the first three of which you are to complete. (Each one has one or more method stubs.)


Notes

The methods in DFA_Utils are intended to solve the decision problems mentioned in Problem 6 of HW #5, for which sample solutions were provided. Don't ignore those sample solutions.

The liveStates() method in the DFA class is by far the most difficult part of this assignment. It is supposed to return the (IDs of the) set of "live" (i.e., non-dead) states in the DFA, which is to say those states from which a final state is reachable by some sequence of transitions.

Among the ways to solve the problem is to mimic the approach taken by the algorithms that identify nullable and fruitful nonterminals in a context-free grammar. A different —and superior in terms of running time— way to solve the problem is via a depth-first (or breadth-first) search.


Sample Execution of DFA_Tester:

The first line shows the program being invoked (in a command-line UNIX environment) and provided with the file name "dfa4.txt" as the command-line argument.

$ java DFA_Tester dfa4.txt
This DFA has been loaded:
-------------------------
Number of states: 5
Alphabet size: 2
  delta(0,0) = 1
  delta(0,1) = 0
  delta(1,0) = 2
  delta(1,1) = 3
  delta(2,0) = 2
  delta(2,1) = 4
  delta(3,0) = 0
  delta(3,1) = 3
  delta(4,0) = 4
  delta(4,1) = 4
Initial state: 0
Final states: {1}

0: Quit
1: Display DFA
2: Test deltaStar() in DFA_Semi
3: Test accepts() in DFA
4: Test hasMemberPrefix() in DFA_Utils
5: Test isSuffixOfMember() in DFA_Utils
6: Test isSubstringOfMember() in DFA_Utils
7: Test liveStates() in DFA
>2

Enter state ID (-1 to quit, -2 to display DFA): 1
Enter input string: 110100
delta*(1,110100) = 2

Enter state ID (-1 to quit, -2 to display DFA): -1

0: Quit
1: Display DFA
2: Test deltaStar() in DFA_Semi
3: Test accepts() in DFA
4: Test hasMemberPrefix() in DFA_Utils
5: Test isSuffixOfMember() in DFA_Utils
6: Test isSubstringOfMember() in DFA_Utils
7: Test liveStates() in DFA
>3

Enter input string (X to quit, Y to display DFA): 1101100
1101100 IS accepted.

Enter input string (X to quit, Y to display DFA): 011010010
011010010 is NOT accepted.

Enter input string (X to quit, Y to display DFA): X

0: Quit
1: Display DFA
2: Test deltaStar() in DFA_Semi
3: Test accepts() in DFA
4: Test hasMemberPrefix() in DFA_Utils
5: Test isSuffixOfMember() in DFA_Utils
6: Test isSubstringOfMember() in DFA_Utils
7: Test liveStates() in DFA
>4

Enter input string (X to quit, Y to display DFA): 101
101 has a prefix that is a member.

Enter input string (X to quit, Y to display DFA): 111
111 does not have a prefix that is a member.

Enter input string (X to quit, Y to display DFA): X

0: Quit
1: Display DFA
2: Test deltaStar() in DFA_Semi
3: Test accepts() in DFA
4: Test hasMemberPrefix() in DFA_Utils
5: Test isSuffixOfMember() in DFA_Utils
6: Test isSubstringOfMember() in DFA_Utils
7: Test liveStates() in DFA
>5

Enter input string (X to quit, Y to display DFA): 101
101 is not the suffix of any member.

Enter input string (X to quit, Y to display DFA): 11110
11110 is the suffix of some member.

Enter input string (X to quit, Y to display DFA): X

0: Quit
1: Display DFA
2: Test deltaStar() in DFA_Semi
3: Test accepts() in DFA
4: Test hasMemberPrefix() in DFA_Utils
5: Test isSuffixOfMember() in DFA_Utils
6: Test isSubstringOfMember() in DFA_Utils
7: Test liveStates() in DFA
>6

Enter input string (X to quit, Y to display DFA): 110011
110011 is the substring of some member.

Enter input string (X to quit, Y to display DFA): 000
000 is not the substring of any member.

Enter input string (X to quit, Y to display DFA): X

0: Quit
1: Display DFA
2: Test deltaStar() in DFA_Semi
3: Test accepts() in DFA
4: Test hasMemberPrefix() in DFA_Utils
5: Test isSuffixOfMember() in DFA_Utils
6: Test isSubstringOfMember() in DFA_Utils
7: Test liveStates() in DFA
>7
Live states are {0,1,3}

0: Quit
1: Display DFA
2: Test deltaStar() in DFA_Semi
3: Test accepts() in DFA
4: Test hasMemberPrefix() in DFA_Utils
5: Test isSuffixOfMember() in DFA_Utils
6: Test isSubstringOfMember() in DFA_Utils
7: Test liveStates() in DFA
>0

Goodbye.