Engr 692: Special Topics in Engineering Science
(Ruby and Software Development)
Fall 2006

Assignment #3
Due 5:00 p.m., Friday, 10 November 2006


Consider a domain-specific language (DSL) for defining deterministic finite state automata (i.e., machines). The language consists of the following kinds of statements:

In general, a state name must be declared in a state statement before it is used in any of the other statements. Otherwise, the statements can occur in any order in the machine description file.

For example, consider the following machine description file for a simple finite state machine to accept an even number of occurrences of the string "one". It has two states, one of which is both the initial and the final state. It also has an input alphabet consisting of a single symbol, the string "one". The DSL file for the machine description is as follows:

state :even, :odd
initial :even
final :even
alphabet ["one"]
transition :even, "one", :odd
transition :odd, "one", :even

The above machine would accept the input sequences "", "one one", "one one one one", and so forth. It would reject the input sequences "one", "one one one", and so forth. An input sequence such as "one three" would be an error situation because the symbol "three" is not in the input alphabet for the machine.

Write a Ruby program that takes a machine description written in the above DSL and builds a deterministic finite state acceptor for the regular language so described. As we have seen in example programs in class, the program may either implement an internal DSL using Ruby or an external DSL using simple language processing techniques.

The program should write appropriate error messages in cases such as when a nondeterministic machine is defined or more than one initial state is given.

After construction of the acceptor, the program should take a DSL file (i.e., a text file with a machine description written in the DSL) and determine whether an input file (i.e., just another text file) satisfies the language description. The program should ignore white space (blanks, tabs, newlines) between symbols in the input file.

It should be possible to run the program in irb by calling it follows with two filenames as follows:

FSM.accept machine_description_filename input_file_name

Design appropriate tests for your program and execute them.

Document your Ruby code appropriately.

Turn in a printout of the Ruby program code, your test input files, and the output from your test runs. Also turn in an electronic copy of your program with the Ruby code in a file named FSMacceptor.rb.

Challenges:

After doing the basic program above, extend it in the following ways:


UP to Engr 692 Assignments page?


Copyright © 2006, H. Conrad Cunningham
Last modified: Wednesday, 25 Oct 2006