Assignment 1

CS 360 Programming Language Concepts
Instructor: Jeremy Johnson 
Due date: (Part I due Mon. Jan. 22 at 11:59 PM, Part II due due Mon. Jan. 29 at 11:59 PM, Part II due)

This assignment deals with finite state machines and has two parts. In the first part, you will read a description of a NDFA and translate that description to a graphical description using the DOT language. In the second part, you will write a simulator for a NDFA using the same input format as in part 1. The simulator should take as input a NDFA and an input string and return true if the string is accepted by the NDFA and false otherwise.

Background information is obtained in lecture 2. A description of the input format for NDFA's is contained in ndfa.txt. An example DOT file for the graphical representation is in fsm.dot and the corresponding output from DOT is in fsm.pdf.

Part I

Write a program that reads a textual description of an NDFA following the conventions in ndfa.txt and produces as output a DOT description of a graph (following the conventions in the example in fsm.dot). The dot program can then be used to create a picture of the graph in a variety of image formats. Note that you may read a file with a single or multiple NDFA descriptions.

After reading the NDFA description you should create an internal data structure,which you can later traverse to product the desired output. E.G. store the number of states and use an array, map, or list to store the transitions. Ideally you should create an NDFA class with a read method and an exportToGraph method. Write a main program that reads an NDFA description and produces the corresponding DOT file describing the graph corresponding to the NDFA. Make sure your program works properly on the three sample inputs in ndfa.txt. The class and read method can be reused for part II.

Part II

Write a program that reads a textual description of an NDFA following the conventions in ndfa.txt and simulates its execution on an input string. You should add a simulate method to your NDFA class, from part I, that takes a string as input and returns true of the input is accepted by the NDFA. Write a main program that reads an NDFA description and a string and prints "accepts" or "does not accept" depending on whether or not the input is accepted. Try your simulation for the input machines described in ndfa.txt using various input strings.

What and how to submit

Students should submit their solution electronically using webct. Submit a gzipped tar file of a directory containing source code, instructions how to build and run your programs, sample input and output files, and a README file. The README file should describe all files that are included, contain instructions how to build and use the code, and outline how the code works. If your program is not working, you should clearly state this in the README file. All source code should be documented (clear specifications and comments for any tricky parts of the code). Your programs must be written in either C++, java, or python. Your programs should compile (it is a good idea to use make or ant) and run on the department machines.
You should follow the same submission guidelines for both parts I and II. For part I submit a gzipped tar file (tar -zcvf A1p1.tar.gz A1p1) of a directory called A1p1, containing your files for part I, and for part II submit a gzipped tar file (tar -zcvf A1p2.tar.gz A2p1) of a directory called A1p2 containing the files for part II.