210k views
5 votes
Construct an NFA that accepts floating point numbers with the following format:

{optional + or -} { one or more digits} {decimal point} { one or more digits}.

It should accept strings such as: 0.0, +8.25, -51.2, 33.33, 0.01
It should reject strings such as: 17, +3, .5, 4.4.3

Upload your solution, which should be a PDF or JPEG image that clearly identifies the question number and gives the appropriate solution in the form of a hand-drawn or software-created transition graph. Do NOT use ASCII drawn transition graphs or text descriptions.

1 Answer

7 votes

Final answer:

An NFA for accepting the specified format of floating point numbers would include an initial state that transitions to a digit or sign state, a state for the decimal point, and a final state ensuring at least one digit follows the decimal.

Step-by-step explanation:

Constructing a Non-deterministic Finite Automaton (NFA) to accept floating point numbers requires understanding the components of such numbers. A floating point number consists of an optional sign (+ or -), followed by one or more digits, a decimal point, and then one or more digits. Acceptable examples are '+8.25' and '-51.2', whereas numbers like '17' or '.5' should be rejected by the NFA because they lack the required format.

To visualize this NFA, imagine a series of states where the initial state can transition to a state representing a digit or sign. A loop on the digit state allows for any number of digits. There must then be a transition to a state for the decimal point, followed by a loop on another digit state to allow for digits after the decimal point. This representation is appropriately captured in a transition graph that I am unable to upload per the instructions. Nonetheless, the description provided here summarizes the arrangement of states and transitions required to accept the specified format for floating point numbers.

User Greg Samson
by
7.7k points