PageRenderTime 268ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/re2c-0.13.5/test/condition_06.cs.c

#
C | 391 lines | 368 code | 20 blank | 3 comment | 37 complexity | ad821e14d308e237177eaf58bf3b2090 MD5 | raw file
  1. /* Generated by re2c */
  2. #line 1 "condition_06.cs.re"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #define BSIZE 8192
  7. typedef struct Scanner
  8. {
  9. FILE *fp;
  10. unsigned char *cur, *tok, *lim, *eof;
  11. unsigned char buffer[BSIZE];
  12. } Scanner;
  13. int fill(Scanner *s, int len)
  14. {
  15. if (!len)
  16. {
  17. s->cur = s->tok = s->lim = s->buffer;
  18. s->eof = 0;
  19. }
  20. if (!s->eof)
  21. {
  22. int got, cnt = s->tok - s->buffer;
  23. if (cnt > 0)
  24. {
  25. memcpy(s->buffer, s->tok, s->lim - s->tok);
  26. s->tok -= cnt;
  27. s->cur -= cnt;
  28. s->lim -= cnt;
  29. }
  30. cnt = BSIZE - cnt;
  31. if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt)
  32. {
  33. s->eof = &s->lim[got];
  34. }
  35. s->lim += got;
  36. }
  37. else if (s->cur + len > s->eof)
  38. {
  39. return 0; /* not enough input data */
  40. }
  41. return -1;
  42. }
  43. void fputl(const char *s, size_t len, FILE *stream)
  44. {
  45. while(len-- > 0)
  46. {
  47. fputc(*s++, stream);
  48. }
  49. }
  50. #line 57 "<stdout>"
  51. enum YYCONDTYPE {
  52. EStateNormal,
  53. EStateComment,
  54. EStateSkiptoeol,
  55. EStateString,
  56. };
  57. #line 54 "condition_06.cs.re"
  58. void scan(Scanner *s)
  59. {
  60. int cond = EStateNormal;
  61. fill(s, 0);
  62. for(;;)
  63. {
  64. s->tok = s->cur;
  65. #line 78 "<stdout>"
  66. {
  67. unsigned char yych;
  68. if (cond < 2) {
  69. if (cond < 1) {
  70. goto yyc_Normal;
  71. } else {
  72. goto yyc_Comment;
  73. }
  74. } else {
  75. if (cond < 3) {
  76. goto yyc_Skiptoeol;
  77. } else {
  78. goto yyc_String;
  79. }
  80. }
  81. /* *********************************** */
  82. yyc_Comment:
  83. if ((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; }
  84. yych = *s->cur;
  85. if (yych != '*') goto yy4;
  86. ++s->cur;
  87. if ((yych = *s->cur) == '/') goto yy5;
  88. yy3:
  89. #line 149 "condition_06.cs.re"
  90. {
  91. goto yyc_Comment;
  92. }
  93. #line 107 "<stdout>"
  94. yy4:
  95. yych = *++s->cur;
  96. goto yy3;
  97. yy5:
  98. ++s->cur;
  99. #line 145 "condition_06.cs.re"
  100. {
  101. continue;
  102. }
  103. #line 117 "<stdout>"
  104. /* *********************************** */
  105. yyc_Normal:
  106. if ((s->lim - s->cur) < 3) { if(fill(s, 3) >= 0) break; }
  107. yych = *s->cur;
  108. if (yych <= '.') {
  109. if (yych == '"') goto yy12;
  110. goto yy14;
  111. } else {
  112. if (yych <= '/') goto yy11;
  113. if (yych != '?') goto yy14;
  114. }
  115. yych = *(s->tok = ++s->cur);
  116. if (yych == '?') goto yy19;
  117. yy10:
  118. #line 140 "condition_06.cs.re"
  119. {
  120. fputc(*s->tok, stdout);
  121. continue;
  122. }
  123. #line 137 "<stdout>"
  124. yy11:
  125. yych = *++s->cur;
  126. if (yych == '*') goto yy17;
  127. if (yych == '/') goto yy15;
  128. goto yy10;
  129. yy12:
  130. ++s->cur;
  131. #line 134 "condition_06.cs.re"
  132. {
  133. fputc(*s->tok, stdout);
  134. state = EStateString;
  135. continue;
  136. }
  137. #line 151 "<stdout>"
  138. yy14:
  139. yych = *++s->cur;
  140. goto yy10;
  141. yy15:
  142. ++s->cur;
  143. #line 130 "condition_06.cs.re"
  144. {
  145. goto yyc_Skiptoeol;
  146. }
  147. #line 161 "<stdout>"
  148. yy17:
  149. ++s->cur;
  150. #line 126 "condition_06.cs.re"
  151. {
  152. goto yyc_Comment;
  153. }
  154. #line 168 "<stdout>"
  155. yy19:
  156. yych = *++s->cur;
  157. switch (yych) {
  158. case '!': goto yy35;
  159. case '\'': goto yy33;
  160. case '(': goto yy21;
  161. case ')': goto yy23;
  162. case '-': goto yy37;
  163. case '/': goto yy31;
  164. case '<': goto yy25;
  165. case '=': goto yy29;
  166. case '>': goto yy27;
  167. default: goto yy20;
  168. }
  169. yy20:
  170. s->cur = s->tok;
  171. goto yy10;
  172. yy21:
  173. ++s->cur;
  174. #line 81 "condition_06.cs.re"
  175. {
  176. fputc('[', stdout);
  177. continue;
  178. }
  179. #line 193 "<stdout>"
  180. yy23:
  181. ++s->cur;
  182. #line 86 "condition_06.cs.re"
  183. {
  184. fputc(']', stdout);
  185. continue;
  186. }
  187. #line 201 "<stdout>"
  188. yy25:
  189. ++s->cur;
  190. #line 91 "condition_06.cs.re"
  191. {
  192. fputc('{', stdout);
  193. continue;
  194. }
  195. #line 209 "<stdout>"
  196. yy27:
  197. ++s->cur;
  198. #line 96 "condition_06.cs.re"
  199. {
  200. fputc('}', stdout);
  201. continue;
  202. }
  203. #line 217 "<stdout>"
  204. yy29:
  205. ++s->cur;
  206. #line 101 "condition_06.cs.re"
  207. {
  208. fputc('#', stdout);
  209. continue;
  210. }
  211. #line 225 "<stdout>"
  212. yy31:
  213. ++s->cur;
  214. #line 106 "condition_06.cs.re"
  215. {
  216. fputc('\\', stdout);
  217. continue;
  218. }
  219. #line 233 "<stdout>"
  220. yy33:
  221. ++s->cur;
  222. #line 111 "condition_06.cs.re"
  223. {
  224. fputc('^', stdout);
  225. continue;
  226. }
  227. #line 241 "<stdout>"
  228. yy35:
  229. ++s->cur;
  230. #line 116 "condition_06.cs.re"
  231. {
  232. fputc('|', stdout);
  233. continue;
  234. }
  235. #line 249 "<stdout>"
  236. yy37:
  237. ++s->cur;
  238. #line 121 "condition_06.cs.re"
  239. {
  240. fputc('~', stdout);
  241. continue;
  242. }
  243. #line 257 "<stdout>"
  244. /* *********************************** */
  245. yyc_Skiptoeol:
  246. if ((s->lim - s->cur) < 5) { if(fill(s, 5) >= 0) break; }
  247. yych = *s->cur;
  248. if (yych <= '>') {
  249. if (yych == '\n') goto yy44;
  250. goto yy46;
  251. } else {
  252. if (yych <= '?') goto yy41;
  253. if (yych == '\\') goto yy43;
  254. goto yy46;
  255. }
  256. yy41:
  257. yych = *(s->tok = ++s->cur);
  258. if (yych == '?') goto yy51;
  259. yy42:
  260. #line 165 "condition_06.cs.re"
  261. {
  262. goto yyc_Skiptoeol;
  263. }
  264. #line 278 "<stdout>"
  265. yy43:
  266. yych = *(s->tok = ++s->cur);
  267. if (yych == '\n') goto yy49;
  268. if (yych == '\r') goto yy47;
  269. goto yy42;
  270. yy44:
  271. ++s->cur;
  272. #line 161 "condition_06.cs.re"
  273. {
  274. continue;
  275. }
  276. #line 290 "<stdout>"
  277. yy46:
  278. yych = *++s->cur;
  279. goto yy42;
  280. yy47:
  281. yych = *++s->cur;
  282. if (yych == '\n') goto yy49;
  283. yy48:
  284. s->cur = s->tok;
  285. goto yy42;
  286. yy49:
  287. ++s->cur;
  288. #line 157 "condition_06.cs.re"
  289. {
  290. goto yyc_Skiptoeol;
  291. }
  292. #line 306 "<stdout>"
  293. yy51:
  294. yych = *++s->cur;
  295. if (yych != '/') goto yy48;
  296. yych = *++s->cur;
  297. if (yych == '\n') goto yy54;
  298. if (yych != '\r') goto yy48;
  299. yych = *++s->cur;
  300. if (yych != '\n') goto yy48;
  301. yy54:
  302. ++s->cur;
  303. #line 153 "condition_06.cs.re"
  304. {
  305. goto yyc_Skiptoeol;
  306. }
  307. #line 321 "<stdout>"
  308. /* *********************************** */
  309. yyc_String:
  310. if ((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; }
  311. yych = *s->cur;
  312. if (yych == '"') goto yy60;
  313. if (yych != '\\') goto yy62;
  314. ++s->cur;
  315. if ((yych = *s->cur) != '\n') goto yy63;
  316. yy59:
  317. #line 179 "condition_06.cs.re"
  318. {
  319. fputc(*s->tok, stdout);
  320. continue;
  321. }
  322. #line 336 "<stdout>"
  323. yy60:
  324. ++s->cur;
  325. #line 174 "condition_06.cs.re"
  326. {
  327. fputc(*s->tok, stdout);
  328. continue;
  329. }
  330. #line 344 "<stdout>"
  331. yy62:
  332. yych = *++s->cur;
  333. goto yy59;
  334. yy63:
  335. ++s->cur;
  336. #line 169 "condition_06.cs.re"
  337. {
  338. fputl((const char*)s->tok, 2, stdout);
  339. continue;
  340. }
  341. #line 355 "<stdout>"
  342. }
  343. #line 183 "condition_06.cs.re"
  344. }
  345. }
  346. int main(int argc, char **argv)
  347. {
  348. Scanner in;
  349. char c;
  350. if (argc != 2)
  351. {
  352. fprintf(stderr, "%s <file>\n", argv[0]);
  353. return 1;;
  354. }
  355. memset((char*) &in, 0, sizeof(in));
  356. if (!strcmp(argv[1], "-"))
  357. {
  358. in.fp = stdin;
  359. }
  360. else if ((in.fp = fopen(argv[1], "r")) == NULL)
  361. {
  362. fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
  363. return 1;
  364. }
  365. scan(&in);
  366. if (in.fp != stdin)
  367. {
  368. fclose(in.fp);
  369. }
  370. return 0;
  371. }