Newer
Older
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
64
#include "RegExpFromStringLexer.h"
namespace regexp {
RegExpFromStringLexer::RegExpFromStringLexer(const std::string& in) : m_In(in) {
this->next();
}
RegExpFromStringLexer& RegExpFromStringLexer::next() {
char character;
L0:
character = m_In.get();
if(m_In.eof()) {
m_Current.type = TEOF;
return *this;
} else if(character == ' ' || character == '\n' || character == '\t') {
goto L0;
} else if((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z') || (character >= '0' && character <= '9')) {
m_Current.type = SYMBOL;
m_Current.value = character;
return *this;
} else if(character == '(') {
m_Current.type = LPAR;
return *this;
} else if(character == ')') {
m_Current.type = RPAR;
return *this;
} else if(character == '+') {
m_Current.type = PLUS;
return *this;
} else if(character == '*') {
m_Current.type = STAR;
return *this;
} else if(character == '\\') {
goto L1;
} else {
m_In.unget();
m_Current.type = ERROR;
return *this;
}
L1:
character = m_In.get();
if(m_In.eof()) {
m_Current.type = ERROR;
return *this;
} else if(character == 'e') {
m_Current.type = EPS;
return *this;
} else if(character == '0') {
m_Current.type = EMPTY;
return *this;
} else {
m_In.unget();
m_Current.type = ERROR;
return *this;
}
}
RegExpFromStringLexer::Token RegExpFromStringLexer::token() {
return m_Current;
}
}