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:
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 ofFsm
in the
file numbers.py
, and test your code
using fsm.py
and numbers_test.py
.
In more detail:
..
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.
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.
addTransitionRange
to minimize repetitive code.
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.
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.