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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
/* Generated by re2c */
#line 1 "strip_002.s.re"
/* re2c lesson 002_strip_comments, strip_002.s, (c) M. Boerger 2006 - 2007 */
#line 31 "strip_002.s.re"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define YYMAXFILL 2
#define BSIZE 128
#if BSIZE < YYMAXFILL
# error BSIZE must be greater YYMAXFILL
#endif
#define YYCTYPE unsigned char
#define YYCURSOR s.cur
#define YYLIMIT s.lim
#define YYMARKER s.mrk
#define YYFILL(n) { if ((res = fill(&s, n)) >= 0) break; }
typedef struct Scanner
{
FILE *fp;
unsigned char *cur, *tok, *lim, *eof, *mrk;
unsigned char buffer[BSIZE];
} Scanner;
int fill(Scanner *s, int len)
{
if (!len)
{
s->cur = s->tok = s->lim = s->mrk = s->buffer;
s->eof = 0;
}
if (!s->eof)
{
int got, cnt = s->tok - s->buffer;
if (cnt > 0)
{
memcpy(s->buffer, s->tok, s->lim - s->tok);
s->tok -= cnt;
s->cur -= cnt;
s->lim -= cnt;
s->mrk -= cnt;
}
cnt = BSIZE - cnt;
if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt)
{
s->eof = &s->lim[got];
}
s->lim += got;
}
else if (s->cur + len > s->eof)
{
return 0; /* not enough input data */
}
return -1;
}
void echo(Scanner *s)
{
fwrite(s->tok, 1, s->cur - s->tok, stdout);
}
int scan(FILE *fp)
{
int res = 0;
Scanner s;
if (!fp)
{
return 1; /* no file was opened */
}
s.fp = fp;
fill(&s, 0);
for(;;)
{
s.tok = s.cur;
#line 89 "strip_002.s.c"
{
YYCTYPE yych;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = *YYCURSOR;
if (yych == '/') goto yy4;
++YYCURSOR;
yy3:
#line 121 "strip_002.s.re"
{ fputc(*s.tok, stdout); continue; }
#line 99 "strip_002.s.c"
yy4:
yych = *++YYCURSOR;
if (yych == '*') goto yy5;
if (yych == '/') goto yy7;
goto yy3;
yy5:
++YYCURSOR;
#line 120 "strip_002.s.re"
{ goto comment; }
#line 109 "strip_002.s.c"
yy7:
++YYCURSOR;
#line 119 "strip_002.s.re"
{ goto cppcomment; }
#line 114 "strip_002.s.c"
}
#line 122 "strip_002.s.re"
comment:
s.tok = s.cur;
#line 121 "strip_002.s.c"
{
YYCTYPE yych;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = *YYCURSOR;
if (yych == '*') goto yy13;
++YYCURSOR;
yy12:
#line 127 "strip_002.s.re"
{ goto comment; }
#line 131 "strip_002.s.c"
yy13:
yych = *++YYCURSOR;
if (yych != '/') goto yy12;
++YYCURSOR;
#line 126 "strip_002.s.re"
{ goto commentws; }
#line 138 "strip_002.s.c"
}
#line 128 "strip_002.s.re"
commentws:
s.tok = s.cur;
#line 145 "strip_002.s.c"
{
YYCTYPE yych;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = *YYCURSOR;
if (yych <= '\f') {
if (yych <= 0x08) goto yy18;
if (yych <= '\t') goto yy20;
if (yych <= '\n') goto yy22;
} else {
if (yych <= '\r') goto yy24;
if (yych == ' ') goto yy20;
}
yy18:
++YYCURSOR;
#line 134 "strip_002.s.re"
{ echo(&s); continue; }
#line 162 "strip_002.s.c"
yy20:
++YYCURSOR;
yy21:
#line 133 "strip_002.s.re"
{ goto commentws; }
#line 168 "strip_002.s.c"
yy22:
++YYCURSOR;
#line 132 "strip_002.s.re"
{ echo(&s); continue; }
#line 173 "strip_002.s.c"
yy24:
yych = *++YYCURSOR;
if (yych == '\n') goto yy22;
goto yy21;
}
#line 135 "strip_002.s.re"
cppcomment:
s.tok = s.cur;
#line 184 "strip_002.s.c"
{
YYCTYPE yych;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = *YYCURSOR;
if (yych == '\n') goto yy29;
if (yych == '\r') goto yy31;
++YYCURSOR;
yy28:
#line 140 "strip_002.s.re"
{ goto cppcomment; }
#line 195 "strip_002.s.c"
yy29:
++YYCURSOR;
#line 139 "strip_002.s.re"
{ echo(&s); continue; }
#line 200 "strip_002.s.c"
yy31:
yych = *++YYCURSOR;
if (yych == '\n') goto yy29;
goto yy28;
}
#line 141 "strip_002.s.re"
}
if (fp != stdin)
{
fclose(fp); /* close only if not stdin */
}
return res; /* return result */
}
int main(int argc, char **argv)
{
if (argc > 1)
{
return scan(!strcmp(argv[1], "-") ? stdin : fopen(argv[1], "r"));
}
else
{
fprintf(stderr, "%s <expr>\n", argv[0]);
return 1;
}
}
|