I'm trying to construct the Definite Finite Automata(DFA) of a real number, that is defined as:
And its finish depends on digits if its real or not.
I constructed the regular expression: /[+ | -]?(O | ([1-9][0-9]*)).[0-9]+/
/[+ | -]?(O | ([1-9][0-9]*)).[0-9]+/
^[+-]?(?:0|[1-9]\d*)(?:\.\d+)?$
^
Assert position at the start of the line [+-]?
Optionally match either +
or -
(?:0|[1-9]\\d*)
Match either 0
or a number beginning with a digit in the range of 1-9
, followed by any number of any digit (?:\\.\\d+)?
Optionally match a decimal point number (a dot .
, followed by one or more digits) $
Assert position at the end of the line Here, start state is q0
.
Final state is q5
.
DFA enters state q1
if sign is provided.
State q2
is reached if the first digit is 0.
State q3
if the first digit is not 0 and remains in that state for further numbers till a decimal point is seen.
State q4
reached on decimal point from where there is transition to state q5
if a digit is seen.
Dead state is not shown.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.