Question: Write a Python NDFSA+ simulator that meets the following specifications. The machine definition and tape will be stored in a text file that has the

Write a Python NDFSA+ simulator that meets the following specifications. The machine definition and tape will be stored in a text file that has the extension ".ndfsa". Note that we are not going to write a Python NDFSA simulator because it is very similar to this simulator. Also, if you have a file with no moves the NDFSA+ simulator can run it without any issues. Each line of the text file shall begin with one of the following capital letters: A, B, D, O, S, T. We will explain the meaning of these letters below. The letters appear at the very beginning of the line and there is a single blank space after the letter for readability. Each line must begin with a letter. If the file does not meet the specifications, it is rejected. If a line does not have a letter on some line, the file is rejected. The first line must be an A line which contains just a single string consisting of all the characters in the alphabet. There is only one A line per file. To simplify coding, we make the restriction that the alphabet can never contain the character @ since we want to use it to represent . Note that you can enter into a Graphviz file and Graphviz will incorporate the in arrow labels but not in state labels. Depending on what text editor you are using, entering might be tricky, which is why I am letting you use @ instead of if you wish. The A line is followed by a series of S lines. S stands for state. An S line states that the line gives information about states such as their names and whether they are final or not. An S line has the following structure S S1,Bool1,S2,Bool2,...,Sk,Boolk where Si is the name of a state and Booli is 1 if the state is final and 0 is the state is not final Next comes a B line which contains the beginning (start) state There is only one such line and it looks like B State. Next come the D lines where D stands for delta. The structure of a D line is as follows: D S1,C*1,N1,S2,C*2,N2...,Sk,C*k,Nk where Si is the current state, C*i is the character being read or @ if we are denoting an move, and Ni is the new state that the machine enters. Each line contains a whole number of triples although the number of complete triples per line is not specified. The lines could lack any entries, but they still should have the blank following the letter. Note, the .ndfsa file does not do anything special for non-determinism - it just lists all the possible moves just as for a FSA. It is up to your simulator to group the moves in a useful manner. After the last D line, come a series of alternating T and O lines. T stands for tape and contains a character string representing a initial tape. Every T line is followed by an O line. The O line is blank if the preceding T line has not been processed by the machine. The line contains the word "accepted" if the machine would accept the string on the T line and contains the word "rejected" if the machine would reject the string on the T line. After the program processes the file it should process any T lines for which there are no answers on the corresponding O lines. Once the simulator finishes, it should reconstruct the file that it read, but add any new computations to the updated file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!