Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Define a DFA and test it from two files. The first containing the DFA specifications (DFA.txt) and the second containing test numbers (input.txt). The DFA
Define a DFA and test it from two files. The first containing the DFA specifications (DFA.txt) and the second containing test numbers (input.txt). The DFA MUST be created using the information from the first file, the data must be imported and stored to be used as the DFA to test the information in the second file.
The DFA.txt file looks as follows:
Specification Define a program called DFACheck which will accept as its input a pair of file names, the first of which contains a textual representation of a DFA, and the second of which contains a collection of strings, and determines whether or not the given strings are accepted by the specified automaton. 1 % Q 2 B 3 4 D 5 6 E 7 F G 8 9 . I 10 11 12 % Sigma 13 14 15 1 % F B 16 17 18 19 20 C D E 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 . I % QO A % Delta AOB A1c BOB B1E COD Cic DOB D1G E OF E1C FOB F11 GOH G1C HOB H 1 ) I OJ I 10 JOJ J 10 36 37 38 39 40 41 42 43 44 45 Note that in this representation, those lines preceded by a % sign (i.e., lines 1, 12, 15, 25, and 27) are to be treated as single line comments in Java - any content on the line after the % sign is to be ignored and is entirely optional. Also note, that for this assignment you are guaranteed the following about the DFA input file: the DFA within it is correctly specified (i.e., is both a a DFA, and in the correct textual form), and that the order of the DFA's constituent parts are as in the example above (which by design corresponds with how the definition of a DFA is formulated). String Input File Specification For this assignment you may assume that the string input file is formatted with exactly one string per line and that the strings are guaranteed to be formed from characters of the input alphabet (which in the context of this example is {0, 1}). The following is one possible input file' to be used with the deterministic finite automaton Mo from the previous section: 1 100100 2 111 3 00100100 4 10101 5 010101 Usage The program DFACheck is intended to be run via the following command-line invocation: 1 $ java DFACheck dfa.txt input.txt If no input file is specified or if the input file is not found, an appropriate error message must be displayed. For example: 1 $ java DFACheck DFACheck: no input files specified 2 3 4 $ java DFACheck foo.txt DFACheck: invalid usage 5 the program must be given two files as input 6 7 $ java DFACheck no-such-file.txt input.txt DFACheck: the file 'no-such-file.txt' could not be opened 8 9 10 $ java DFACheck dfa.txt no-such-file.txt DFACheck: the file 'no-such-file.txt' could not be opened 11 If valid files are specified as input, then for every string of the second file you should output both the string and the word accepted if the given DFA accepts it and rejected otherwise, with only one string's results given per line. Using the files dfa.txt and input.txt given as examples above, your program should behave as follows: 1 2 3 $ java DFACheck dfa.txt input.txt 100100 accepted 111 accepted 00100100 accepted 10101 rejected 01010101 rejected 4 5 6 "Line numbers are included for reference only. 2 Note that in the example output there is exactly one space between the string and its results. As before, line numbers are included for reference only. Specification Define a program called DFACheck which will accept as its input a pair of file names, the first of which contains a textual representation of a DFA, and the second of which contains a collection of strings, and determines whether or not the given strings are accepted by the specified automaton. 1 % Q 2 B 3 4 D 5 6 E 7 F G 8 9 . I 10 11 12 % Sigma 13 14 15 1 % F B 16 17 18 19 20 C D E 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 . I % QO A % Delta AOB A1c BOB B1E COD Cic DOB D1G E OF E1C FOB F11 GOH G1C HOB H 1 ) I OJ I 10 JOJ J 10 36 37 38 39 40 41 42 43 44 45 Note that in this representation, those lines preceded by a % sign (i.e., lines 1, 12, 15, 25, and 27) are to be treated as single line comments in Java - any content on the line after the % sign is to be ignored and is entirely optional. Also note, that for this assignment you are guaranteed the following about the DFA input file: the DFA within it is correctly specified (i.e., is both a a DFA, and in the correct textual form), and that the order of the DFA's constituent parts are as in the example above (which by design corresponds with how the definition of a DFA is formulated). String Input File Specification For this assignment you may assume that the string input file is formatted with exactly one string per line and that the strings are guaranteed to be formed from characters of the input alphabet (which in the context of this example is {0, 1}). The following is one possible input file' to be used with the deterministic finite automaton Mo from the previous section: 1 100100 2 111 3 00100100 4 10101 5 010101 Usage The program DFACheck is intended to be run via the following command-line invocation: 1 $ java DFACheck dfa.txt input.txt If no input file is specified or if the input file is not found, an appropriate error message must be displayed. For example: 1 $ java DFACheck DFACheck: no input files specified 2 3 4 $ java DFACheck foo.txt DFACheck: invalid usage 5 the program must be given two files as input 6 7 $ java DFACheck no-such-file.txt input.txt DFACheck: the file 'no-such-file.txt' could not be opened 8 9 10 $ java DFACheck dfa.txt no-such-file.txt DFACheck: the file 'no-such-file.txt' could not be opened 11 If valid files are specified as input, then for every string of the second file you should output both the string and the word accepted if the given DFA accepts it and rejected otherwise, with only one string's results given per line. Using the files dfa.txt and input.txt given as examples above, your program should behave as follows: 1 2 3 $ java DFACheck dfa.txt input.txt 100100 accepted 111 accepted 00100100 accepted 10101 rejected 01010101 rejected 4 5 6 "Line numbers are included for reference only. 2 Note that in the example output there is exactly one space between the string and its results. As before, line numbers are included for reference onlyStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started