-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringAutomaton.h
63 lines (61 loc) · 1.17 KB
/
StringAutomaton.h
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
56
57
58
59
60
61
62
63
//
// Created by Matthew on 6/25/2022.
//
#ifndef CS236_STRINGAUTOMATON_H
#define CS236_STRINGAUTOMATON_H
#include "Automaton.h"
class StringAutomaton : public Automaton {
public:
StringAutomaton() {
type = TokenType::STRING; // set the type
}
private:
void s0() {
if (match('\'')) {
next();
s1();
}
else {
sError(); // this calls the error state
}
}
void s1() {
if (endOfFile()) {
type = TokenType::UNDEFINED;
return;
}
if (!match('\'')) {
next();
if (endOfFile()) {
type = TokenType::UNDEFINED;
return;
}
s1();
}
else {
next();
s2();
}
}
void s2() {
if (match('\'')) {
next();
s3();
}
else {
//next();//this was commented out?
return;
}
}
void s3() {
if (match('\'')) {
next();
s2();
}
else {
next();
s1();
}
}
};
#endif //CS236_STRINGAUTOMATON_H