blob: 0d5eea811d5bb21ba6b2df1e1e4bbab42807e534 (
plain)
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
190
191
192
193
|
/*
* @LANG: c
*/
#include <string.h>
#include <stdio.h>
struct strs
{
int cs;
};
%%{
machine strs;
variable cs fsm->cs;
main :=
"__gmon_start__\n" |
"cerr\n" |
"__cp_push_exception\n" |
"_DYNAMIC\n" |
"__rtti_user\n" |
"__rtti_si\n" |
"_init\n" |
"__throw\n" |
"__deregister_frame_info\n" |
"terminate__Fv\n" |
"__builtin_vec_new\n" |
"_fini\n" |
"__builtin_vec_delete\n" |
"_GLOBAL_OFFSET_TABLE_\n" |
"__nw__FUiPv\n" |
"__builtin_delete\n" |
"__builtin_new\n" |
"cout\n" |
"__register_frame_info\n" |
"__eh_alloc\n" |
"strcpy\n" |
"stdout\n" |
"memmove\n" |
"memcpy\n" |
"malloc\n" |
"isatty\n" |
"strtoul\n" |
"fprintf\n" |
"stdin\n" |
"ferror\n" |
"strncpy\n" |
"unlink\n" |
"strcasecmp\n" |
"realloc\n" |
"_IO_getc\n" |
"fread\n" |
"memset\n" |
"__assert_fail\n" |
"strcmp\n" |
"stderr\n" |
"fwrite\n" |
"exit\n" |
"fopen\n" |
"atoi\n" |
"fileno\n" |
"_IO_stdin_used\n" |
"__libc_start_main\n" |
"strlen\n" |
"free\n" |
"_edata\n" |
"__bss_start\n" |
"_end\n" |
"QVhl\n" |
"BPPh\n" |
"PHRV\n" |
"PHRj\n" |
"PHRj\n" |
"jphy\n" |
"jqhy\n" |
"PHRj\n" |
"PHRj\n" |
"LWVS\n" |
"LWVS\n" |
"bad_alloc\n" |
"main\n" |
"false\n" |
"help\n" |
"bad_alloc\n" |
"bad_alloc\n" |
"bad_alloc\n" |
"ascii\n" |
"extend\n" |
"alnum\n" |
"alpha\n" |
"cntrl\n" |
"digit\n" |
"graph\n" |
"lower\n" |
"print\n" |
"punct\n" |
"space\n" |
"upper\n" |
"xdigit\n" |
"false\n" |
"bad_alloc\n" |
"bad_alloc\n" |
"bad_alloc\n" |
"TransStruct\n" |
"StateStruct\n" |
"Struct\n" |
"Init\n" |
"bad_alloc\n" |
"TransStruct\n" |
"StateStruct\n" |
"Struct\n" |
"Init\n" |
"Accept\n" |
"Finish\n" |
"bad_alloc\n" |
"Struct\n" |
"Init\n" |
"Finish\n" |
"Accept\n" |
"bad_alloc\n" |
"Struct\n" |
"Init\n" |
"bad_alloc\n" |
"Struct\n" |
"Init\n" |
"Finish\n" |
"Accept\n" |
"bad_alloc\n" |
"Struct\n" |
"Init\n" |
"Finish\n" |
"Accept";
}%%
%% write data;
void strs_init( struct strs *fsm )
{
%% write init;
}
void strs_execute( struct strs *fsm, const char *_data, int _len )
{
const char *p = _data;
const char *pe = _data+_len;
%% write exec;
}
int strs_finish( struct strs *fsm )
{
if ( fsm->cs == strs_error )
return -1;
if ( fsm->cs >= strs_first_final )
return 1;
return 0;
}
struct strs fsm;
void test( char *buf )
{
int len = strlen( buf );
strs_init( &fsm );
strs_execute( &fsm, buf, len );
if ( strs_finish( &fsm ) > 0 )
printf("ACCEPT\n");
else
printf("FAIL\n");
}
int main()
{
test( "stdin\n" );
test( "bad_alloc\n" );
test( "_GLOBAL_OFFSET_TABLE_\n" );
test( "not in\n" );
test(
"isatty\n"
"junk on end.\n"
);
return 0;
}
#ifdef _____OUTPUT_____
ACCEPT
ACCEPT
ACCEPT
FAIL
FAIL
#endif
|