-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path65.c
More file actions
55 lines (52 loc) · 1.2 KB
/
65.c
File metadata and controls
55 lines (52 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// I will implement a discrete finite-state automaton
// figuring out the DFA is a hassle
// but workable with pen and paper
// implementing a DFA is a rare opportunity to get away with using goto
bool isNumber(char* s) {
char c;
s0:
c = *s++;
if (c == '+' || c == '-') goto s2;
if (c == '.') goto s3;
if (isdigit(c)) goto s1;
// return false if ending here (s0 is a non-accepting state)
// return false if illegal char
return false;
s1:
c = *s++;
if (isdigit(c)) goto s1;
if (c == '.') goto s4;
if (c == 'e' || c == 'E') goto s5;
// this is an accepting state
if (c == '\0') return true;
return false;
s2:
c = *s++;
if (isdigit(c)) goto s1;
if (c == '.') goto s3;
return false;
s3:
c = *s++;
if (isdigit(c)) goto s4;
return false;
s4:
c = *s++;
if (isdigit(c)) goto s4;
if (c == 'e' || c == 'E') goto s5;
if (c == '\0') return true;
return false;
s5:
c = *s++;
if (c == '+' || c == '-') goto s6;
if (isdigit(c)) goto s7;
return false;
s6:
c = *s++;
if (isdigit(c)) goto s7;
return false;
s7:
c = *s++;
if (isdigit(c)) goto s7;
if (c == '\0') return true;
return false;
}