-
Notifications
You must be signed in to change notification settings - Fork 0
/
flexer.flex
executable file
·189 lines (153 loc) · 3.14 KB
/
flexer.flex
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
%%
%class Flexer
%unicode
/*%debug*/
%int
/*%line*/
/*%column*/
%{
HomeworkSolver solve = new HomeworkSolver();
%}
LineTerminator = \r|\n|\r\n
WS = {LineTerminator} | [ \t\f]
special = "`"|"-"|"="|"["|"]"|";"|"'"|"\\"|"."|"/"|"~"|"!"|"@"|"#"|"$"|"%"|"^"|"&"|"*"|"_"|"+"|":"|"\""|"|"|"<"|">"|"?"
Symbol = [:uppercase:] | [:lowercase:] | [:digit:] | {special}
Name = ([:uppercase:] | [:lowercase:] | [:digit:] | "_")+
%state STARTK ELEMK STOPK SEPKS STARTS INITS ELEMS STOPS SEPSD STARTD INITD ELEMD SRCT SEPSST SYMT SEPSDT DESTT ENDT ENDD STOPD SEPDS SS SEPSF STARTF INITF ELEMF STOPF ENDDFA FINAL
%state DFA STATES STSEP ALPHABET ALSEP DELTA DSEP START STASE STOP STOSE
%%
{WS} {}
<YYINITIAL>"(" {
yybegin(STARTK);
}
<STARTK> "{" {
yybegin(ELEMK);
}
<ELEMK> {Name} {
//TODO: process state
//System.out.println("State: " + yytext());
solve.addState(yytext());
yybegin(STOPK);
}
<STOPK> {
"}" {
yybegin(SEPKS);
}
"," {
yybegin(ELEMK);
}
}
<SEPKS> "," {
yybegin(STARTS);
}
<STARTS> "{" {
//TODO: Done K, starting Sigma
//System.out.println();
yybegin(INITS);
}
<INITS> "}" {
yybegin(SEPSD);
}
<ELEMS, INITS> {Symbol} {
//TODO: Process symbol
//System.out.println(yycharat(0));
solve.addSymbol(yycharat(0));
yybegin(STOPS);
}
<STOPS> {
"," {
yybegin(ELEMS);
}
"}" {
yybegin(SEPSD);
}
}
<SEPSD> "," {
//TODO: Done Sigma, starting delta
//System.out.println();
yybegin(STARTD);
}
<STARTD> "(" {
yybegin(INITD);
}
<INITD> ")" {
yybegin(SEPDS);
}
<ELEMD,INITD> "(" {
yybegin(SRCT);
}
<SRCT> {Name} {
//TODO: Process source
//System.out.println("Transition from " + yytext());
solve.addTransitionFrom(yytext());
yybegin(SEPSST);
}
<SEPSST> "," {
yybegin(SYMT);
}
<SYMT> {Symbol} {
//TODO: process symbol
//System.out.println("Transition on " + yycharat(0));
solve.addTransitionOn(yycharat(0));
yybegin(SEPSDT);
}
<SEPSDT> "," {
yybegin(DESTT);
}
<DESTT> {Name} {
//TODO: Process destination
//System.out.println("Transition to " + yytext());
//System.out.println();
solve.addTransitionTo(yytext());
yybegin(ENDT);
}
<ENDT> ")" {
yybegin(STOPD);
}
<STOPD> {
"," {
yybegin(ELEMD);
}
")" {
yybegin(SEPDS);
}
}
<SEPDS> "," {
yybegin(SS);
}
<SS> {Name} {
//TODO: Process start state
//System.out.println("Start state " + yytext());
solve.addStartState(yytext());
yybegin(SEPSF);
}
<SEPSF> "," {
yybegin(STARTF);
}
<STARTF> "{" {
yybegin(INITF);
}
<INITF> "}" {
yybegin(ENDDFA);
}
<INITF,ELEMF> {Name} {
//TODO: Process final state
//System.out.println("Final state " + yytext());
solve.addFinalState(yytext());
yybegin(STOPF);
}
<STOPF> {
"," {
yybegin(ELEMF);
}
"}" {
yybegin(ENDDFA);
}
}
<ENDDFA> ")" {
return 0;
}
. {
System.err.println("Syntax error");
System.exit(0);
}