Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Images should be more clear now. Thank you. Overview The purpose of this assignment is to broaden your understanding of deterministic finite automata and their
Images should be more clear now. Thank you.
Overview The purpose of this assignment is to broaden your understanding of deterministic finite automata and their acceptance relation. Recall that a deterministic finite automaton is defined as a 5-tuple of the form (Q, E, F, 90, 5) where: . Q is a finite set of states; . is an input alphabet; .FC is a set of final states; .90 Q is the initial (or start) state; and .8: Qx2 is a transition function and that a string wis accepted by a DFA M, if and only if there exists a path from the start state of M to some final state in M labeled by the constituent characters of w. In this assignment, you will implement a program in Java 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. 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. DFA Input File Specification Consider the DFA, Mo shown in the figure below: 0 0 0 start -> A {0,1) 1 0 0 D Mo will be represented in plain text form as follows: 1 % 0 A 2 3 4 B D E F 6 7 8 G 9 H 10 11 I ] % Sigma 12 13 14 15 1 % F A 16 17 B 18 19 D E 20 21 H 22 I 23 % QO 24 A 25 % Delta 26 AOB 27 A1 C 28 BOB 29 B1E 30 COD 31 C1 C 32 DOB 33 D1 G 34 E OF 35 E 1 36 FOB 37 F1 I 38 GOH 39 G1 C 40 HOB 41 H 1 ) 42 I OJ 43 Iic JOJ 45 Jij 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 me from the previous section: 1 2 3 100100 111 00100100 10101 01010101 4 5 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 - the program must be given two files as input 5 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 11 DFACheck: the file 'no-such-file.txt' could not be opened 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. 2Note 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. Compilation Notes Your program must compile using the following command-line invocation: 1 $ javac *.java Do not submit any IDE specific files and in the interest of simplicity do not use packages for this assignment. If your program does not compile using the command mentioned above you will receive no credit. Overview The purpose of this assignment is to broaden your understanding of deterministic finite automata and their acceptance relation. Recall that a deterministic finite automaton is defined as a 5-tuple of the form (Q, E, F, 90, 5) where: . Q is a finite set of states; . is an input alphabet; .FC is a set of final states; .90 Q is the initial (or start) state; and .8: Qx2 is a transition function and that a string wis accepted by a DFA M, if and only if there exists a path from the start state of M to some final state in M labeled by the constituent characters of w. In this assignment, you will implement a program in Java 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. 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. DFA Input File Specification Consider the DFA, Mo shown in the figure below: 0 0 0 start -> A {0,1) 1 0 0 D Mo will be represented in plain text form as follows: 1 % 0 A 2 3 4 B D E F 6 7 8 G 9 H 10 11 I ] % Sigma 12 13 14 15 1 % F A 16 17 B 18 19 D E 20 21 H 22 I 23 % QO 24 A 25 % Delta 26 AOB 27 A1 C 28 BOB 29 B1E 30 COD 31 C1 C 32 DOB 33 D1 G 34 E OF 35 E 1 36 FOB 37 F1 I 38 GOH 39 G1 C 40 HOB 41 H 1 ) 42 I OJ 43 Iic JOJ 45 Jij 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 me from the previous section: 1 2 3 100100 111 00100100 10101 01010101 4 5 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 - the program must be given two files as input 5 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 11 DFACheck: the file 'no-such-file.txt' could not be opened 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. 2Note 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. Compilation Notes Your program must compile using the following command-line invocation: 1 $ javac *.java Do not submit any IDE specific files and in the interest of simplicity do not use packages for this assignment. If your program does not compile using the command mentioned above you will receive no creditStep 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