Assignment 1: DFSM for Numeric Constants

Use the Python implementation of the fluent API for constructing finite state machines to construct a (single!) machine accepting the following types of numeric constants:

For this assignment, the empty string is not a legal input.

A version of the finite state machine code (implementing a fluent API) is

There are three parts to this assignment: draw a finite state machine accepting the above inputs, implement that as a single instance of Fsm in the file numbers.py, and test your code using fsm.py and numbers_test.py.

In more detail:

  1. Draw a (deterministic) finite state machine for this input either by hand or using some convenient drawing tool such as OneNote. All states must have meaningful names such as "digit" (as opposed to something like "0" or "a"). Use .. or - to capture a range of (ASCII) characters on transitions: 5..8 would be all the characters between 5 and 8, inclusive. You may work on this portion of the assignment with another person, but you must document this if you do.
  2. Translate your FSM into Python code as illustrated by the turnstile example. For this problem you will not have any actions. However, you must organize your FSM so that the final state is one of 'zero', 'octal', 'hexadecimal', 'decimal', and 'float' depending on the type of number found. Note that you might (say) go through a state decimal to get to hexadecimal; this is only a constraint on the last state reached on legal inputs, and what states are traversed to arrive at that state is immaterial. Your machine states must match the state names in your FSM diagram.
  3. Make good use of addTransitionRange to minimize repetitive code.
  4. Submit your solution on esubmit. Ask if you do not remember how to use it. Note that any test run in "debug" mode (which prints the list of states reached) is likely to have output differences that can be ignored.

Do not change fsm.py or numbers_test.py; these files will be provided to you in esubmit. Place your definition of the finite state machine in numbers.py (without changing any of the other parts).

Hint: start by creating a finite state machine (using fsm.py) for a simple decimal numbers and zero. Then extend that machine to add support for octals, hexadecimals, and then floats. Note that test case 3 captures the sequence of states used in finding your solution. Since many state names are likely to be different, your solution will not match the expected output for this case.

Details

Reminder: while each student is to submit their own (independently written!) code and diagram, you are allowed to talk to other students to work out the finite state machine for this problem.

Python programming is not in the prequisites to this class. If you are not confident of your Python skills, talk to your instructor. Options include doing the assignment in another language and getting a short introduction to the bits of Python you will need for this assignment.