calc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /* A recursive-descent parser generated by peg 0.1.1 */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #define YYRULECOUNT 16
  6. #include <stdio.h>
  7. int vars[26];
  8. #ifndef YY_VARIABLE
  9. #define YY_VARIABLE(T) static T
  10. #endif
  11. #ifndef YY_LOCAL
  12. #define YY_LOCAL(T) static T
  13. #endif
  14. #ifndef YY_ACTION
  15. #define YY_ACTION(T) static T
  16. #endif
  17. #ifndef YY_RULE
  18. #define YY_RULE(T) static T
  19. #endif
  20. #ifndef YY_PARSE
  21. #define YY_PARSE(T) T
  22. #endif
  23. #ifndef YYPARSE
  24. #define YYPARSE yyparse
  25. #endif
  26. #ifndef YYPARSEFROM
  27. #define YYPARSEFROM yyparsefrom
  28. #endif
  29. #ifndef YY_INPUT
  30. #define YY_INPUT(buf, result, max_size) \
  31. { \
  32. int yyc= getchar(); \
  33. result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
  34. yyprintf((stderr, "<%c>", yyc)); \
  35. }
  36. #endif
  37. #ifndef YY_BEGIN
  38. #define YY_BEGIN ( yybegin= yypos, 1)
  39. #endif
  40. #ifndef YY_END
  41. #define YY_END ( yyend= yypos, 1)
  42. #endif
  43. #ifdef YY_DEBUG
  44. # define yyprintf(args) fprintf args
  45. #else
  46. # define yyprintf(args)
  47. #endif
  48. #ifndef YYSTYPE
  49. #define YYSTYPE int
  50. #endif
  51. #ifndef YY_PART
  52. typedef void (*yyaction)(char *yytext, int yyleng);
  53. typedef struct _yythunk { int begin, end; yyaction action; struct _yythunk *next; } yythunk;
  54. YY_VARIABLE(char * ) yybuf= 0;
  55. YY_VARIABLE(int ) yybuflen= 0;
  56. YY_VARIABLE(int ) yypos= 0;
  57. YY_VARIABLE(int ) yylimit= 0;
  58. YY_VARIABLE(char * ) yytext= 0;
  59. YY_VARIABLE(int ) yytextlen= 0;
  60. YY_VARIABLE(int ) yybegin= 0;
  61. YY_VARIABLE(int ) yyend= 0;
  62. YY_VARIABLE(int ) yytextmax= 0;
  63. YY_VARIABLE(yythunk *) yythunks= 0;
  64. YY_VARIABLE(int ) yythunkslen= 0;
  65. YY_VARIABLE(int ) yythunkpos= 0;
  66. YY_VARIABLE(YYSTYPE ) yy;
  67. YY_VARIABLE(YYSTYPE *) yyval= 0;
  68. YY_VARIABLE(YYSTYPE *) yyvals= 0;
  69. YY_VARIABLE(int ) yyvalslen= 0;
  70. YY_LOCAL(int) yyrefill(void)
  71. {
  72. int yyn;
  73. while (yybuflen - yypos < 512)
  74. {
  75. yybuflen *= 2;
  76. yybuf= realloc(yybuf, yybuflen);
  77. }
  78. YY_INPUT((yybuf + yypos), yyn, (yybuflen - yypos));
  79. if (!yyn) return 0;
  80. yylimit += yyn;
  81. return 1;
  82. }
  83. YY_LOCAL(int) yymatchDot(void)
  84. {
  85. if (yypos >= yylimit && !yyrefill()) return 0;
  86. ++yypos;
  87. return 1;
  88. }
  89. YY_LOCAL(int) yymatchChar(int c)
  90. {
  91. if (yypos >= yylimit && !yyrefill()) return 0;
  92. if (yybuf[yypos] == c)
  93. {
  94. ++yypos;
  95. yyprintf((stderr, " ok yymatchChar(%c) @ %s\n", c, yybuf+yypos));
  96. return 1;
  97. }
  98. yyprintf((stderr, " fail yymatchChar(%c) @ %s\n", c, yybuf+yypos));
  99. return 0;
  100. }
  101. YY_LOCAL(int) yymatchString(char *s)
  102. {
  103. int yysav= yypos;
  104. while (*s)
  105. {
  106. if (yypos >= yylimit && !yyrefill()) return 0;
  107. if (yybuf[yypos] != *s)
  108. {
  109. yypos= yysav;
  110. return 0;
  111. }
  112. ++s;
  113. ++yypos;
  114. }
  115. return 1;
  116. }
  117. YY_LOCAL(int) yymatchClass(unsigned char *bits)
  118. {
  119. int c;
  120. if (yypos >= yylimit && !yyrefill()) return 0;
  121. c= yybuf[yypos];
  122. if (bits[c >> 3] & (1 << (c & 7)))
  123. {
  124. ++yypos;
  125. yyprintf((stderr, " ok yymatchClass @ %s\n", yybuf+yypos));
  126. return 1;
  127. }
  128. yyprintf((stderr, " fail yymatchClass @ %s\n", yybuf+yypos));
  129. return 0;
  130. }
  131. YY_LOCAL(void) yyDo(yyaction action, int begin, int end)
  132. {
  133. while (yythunkpos >= yythunkslen)
  134. {
  135. yythunkslen *= 2;
  136. yythunks= realloc(yythunks, sizeof(yythunk) * yythunkslen);
  137. }
  138. yythunks[yythunkpos].begin= begin;
  139. yythunks[yythunkpos].end= end;
  140. yythunks[yythunkpos].action= action;
  141. ++yythunkpos;
  142. }
  143. YY_LOCAL(int) yyText(int begin, int end)
  144. {
  145. int yyleng= end - begin;
  146. if (yyleng <= 0)
  147. yyleng= 0;
  148. else
  149. {
  150. while (yytextlen < (yyleng - 1))
  151. {
  152. yytextlen *= 2;
  153. yytext= realloc(yytext, yytextlen);
  154. }
  155. memcpy(yytext, yybuf + begin, yyleng);
  156. }
  157. yytext[yyleng]= '\0';
  158. return yyleng;
  159. }
  160. YY_LOCAL(void) yyDone(void)
  161. {
  162. int pos;
  163. for (pos= 0; pos < yythunkpos; ++pos)
  164. {
  165. yythunk *thunk= &yythunks[pos];
  166. int yyleng= thunk->end ? yyText(thunk->begin, thunk->end) : thunk->begin;
  167. yyprintf((stderr, "DO [%d] %p %s\n", pos, thunk->action, yytext));
  168. thunk->action(yytext, yyleng);
  169. }
  170. yythunkpos= 0;
  171. }
  172. YY_LOCAL(void) yyCommit()
  173. {
  174. if ((yylimit -= yypos))
  175. {
  176. memmove(yybuf, yybuf + yypos, yylimit);
  177. }
  178. yybegin -= yypos;
  179. yyend -= yypos;
  180. yypos= yythunkpos= 0;
  181. }
  182. YY_LOCAL(int) yyAccept(int tp0)
  183. {
  184. if (tp0)
  185. {
  186. fprintf(stderr, "accept denied at %d\n", tp0);
  187. return 0;
  188. }
  189. else
  190. {
  191. yyDone();
  192. yyCommit();
  193. }
  194. return 1;
  195. }
  196. YY_LOCAL(void) yyPush(char *text, int count) { if (text) { } yyval += count; }
  197. YY_LOCAL(void) yyPop(char *text, int count) { if (text) { } yyval -= count; }
  198. YY_LOCAL(void) yySet(char *text, int count) { if (text) { } yyval[count]= yy; }
  199. #endif /* YY_PART */
  200. #define YYACCEPT yyAccept(yythunkpos0)
  201. YY_RULE(int) yy_CLOSE(); /* 16 */
  202. YY_RULE(int) yy_OPEN(); /* 15 */
  203. YY_RULE(int) yy_NUMBER(); /* 14 */
  204. YY_RULE(int) yy_DIVIDE(); /* 13 */
  205. YY_RULE(int) yy_TIMES(); /* 12 */
  206. YY_RULE(int) yy_Value(); /* 11 */
  207. YY_RULE(int) yy_MINUS(); /* 10 */
  208. YY_RULE(int) yy_PLUS(); /* 9 */
  209. YY_RULE(int) yy_Product(); /* 8 */
  210. YY_RULE(int) yy_Sum(); /* 7 */
  211. YY_RULE(int) yy_ASSIGN(); /* 6 */
  212. YY_RULE(int) yy_ID(); /* 5 */
  213. YY_RULE(int) yy_EOL(); /* 4 */
  214. YY_RULE(int) yy_Expr(); /* 3 */
  215. YY_RULE(int) yy__(); /* 2 */
  216. YY_RULE(int) yy_Stmt(); /* 1 */
  217. YY_ACTION(void) yy_1_ID(char *yytext, int yyleng)
  218. { if(yytext) { } if (yyleng) { }
  219. yyprintf((stderr, "do yy_1_ID\n"));
  220. yy= yytext[0] - 'a'; ;
  221. }
  222. YY_ACTION(void) yy_1_NUMBER(char *yytext, int yyleng)
  223. { if(yytext) { } if (yyleng) { }
  224. yyprintf((stderr, "do yy_1_NUMBER\n"));
  225. yy= atoi(yytext); ;
  226. }
  227. YY_ACTION(void) yy_3_Value(char *yytext, int yyleng)
  228. { if(yytext) { } if (yyleng) { }
  229. #define i yyval[-1]
  230. yyprintf((stderr, "do yy_3_Value\n"));
  231. yy= i; ;
  232. #undef i
  233. }
  234. YY_ACTION(void) yy_2_Value(char *yytext, int yyleng)
  235. { if(yytext) { } if (yyleng) { }
  236. #define i yyval[-1]
  237. yyprintf((stderr, "do yy_2_Value\n"));
  238. yy= vars[i]; ;
  239. #undef i
  240. }
  241. YY_ACTION(void) yy_1_Value(char *yytext, int yyleng)
  242. { if(yytext) { } if (yyleng) { }
  243. #define i yyval[-1]
  244. yyprintf((stderr, "do yy_1_Value\n"));
  245. yy= atoi(yytext); ;
  246. #undef i
  247. }
  248. YY_ACTION(void) yy_3_Product(char *yytext, int yyleng)
  249. { if(yytext) { } if (yyleng) { }
  250. #define r yyval[-1]
  251. #define l yyval[-2]
  252. yyprintf((stderr, "do yy_3_Product\n"));
  253. yy= l; ;
  254. #undef r
  255. #undef l
  256. }
  257. YY_ACTION(void) yy_2_Product(char *yytext, int yyleng)
  258. { if(yytext) { } if (yyleng) { }
  259. #define r yyval[-1]
  260. #define l yyval[-2]
  261. yyprintf((stderr, "do yy_2_Product\n"));
  262. l /= r; ;
  263. #undef r
  264. #undef l
  265. }
  266. YY_ACTION(void) yy_1_Product(char *yytext, int yyleng)
  267. { if(yytext) { } if (yyleng) { }
  268. #define r yyval[-1]
  269. #define l yyval[-2]
  270. yyprintf((stderr, "do yy_1_Product\n"));
  271. l *= r; ;
  272. #undef r
  273. #undef l
  274. }
  275. YY_ACTION(void) yy_3_Sum(char *yytext, int yyleng)
  276. { if(yytext) { } if (yyleng) { }
  277. #define r yyval[-1]
  278. #define l yyval[-2]
  279. yyprintf((stderr, "do yy_3_Sum\n"));
  280. yy= l; ;
  281. #undef r
  282. #undef l
  283. }
  284. YY_ACTION(void) yy_2_Sum(char *yytext, int yyleng)
  285. { if(yytext) { } if (yyleng) { }
  286. #define r yyval[-1]
  287. #define l yyval[-2]
  288. yyprintf((stderr, "do yy_2_Sum\n"));
  289. l -= r; ;
  290. #undef r
  291. #undef l
  292. }
  293. YY_ACTION(void) yy_1_Sum(char *yytext, int yyleng)
  294. { if(yytext) { } if (yyleng) { }
  295. #define r yyval[-1]
  296. #define l yyval[-2]
  297. yyprintf((stderr, "do yy_1_Sum\n"));
  298. l += r; ;
  299. #undef r
  300. #undef l
  301. }
  302. YY_ACTION(void) yy_2_Expr(char *yytext, int yyleng)
  303. { if(yytext) { } if (yyleng) { }
  304. #define s yyval[-1]
  305. #define i yyval[-2]
  306. yyprintf((stderr, "do yy_2_Expr\n"));
  307. yy= s; ;
  308. #undef s
  309. #undef i
  310. }
  311. YY_ACTION(void) yy_1_Expr(char *yytext, int yyleng)
  312. { if(yytext) { } if (yyleng) { }
  313. #define s yyval[-1]
  314. #define i yyval[-2]
  315. yyprintf((stderr, "do yy_1_Expr\n"));
  316. yy= vars[i]= s; ;
  317. #undef s
  318. #undef i
  319. }
  320. YY_ACTION(void) yy_2_Stmt(char *yytext, int yyleng)
  321. { if(yytext) { } if (yyleng) { }
  322. #define e yyval[-1]
  323. yyprintf((stderr, "do yy_2_Stmt\n"));
  324. printf("error\n"); ;
  325. #undef e
  326. }
  327. YY_ACTION(void) yy_1_Stmt(char *yytext, int yyleng)
  328. { if(yytext) { } if (yyleng) { }
  329. #define e yyval[-1]
  330. yyprintf((stderr, "do yy_1_Stmt\n"));
  331. printf("%d\n", e); ;
  332. #undef e
  333. }
  334. YY_RULE(int) yy_CLOSE()
  335. { int yypos0= yypos, yythunkpos0= yythunkpos;
  336. yyprintf((stderr, "%s\n", "CLOSE")); if (!yymatchChar(')')) goto l1; if (!yy__()) goto l1;
  337. yyprintf((stderr, " ok %s @ %s\n", "CLOSE", yybuf+yypos));
  338. return 1;
  339. l1:; yypos= yypos0; yythunkpos= yythunkpos0;
  340. yyprintf((stderr, " fail %s @ %s\n", "CLOSE", yybuf+yypos));
  341. return 0;
  342. }
  343. YY_RULE(int) yy_OPEN()
  344. { int yypos0= yypos, yythunkpos0= yythunkpos;
  345. yyprintf((stderr, "%s\n", "OPEN")); if (!yymatchChar('(')) goto l2; if (!yy__()) goto l2;
  346. yyprintf((stderr, " ok %s @ %s\n", "OPEN", yybuf+yypos));
  347. return 1;
  348. l2:; yypos= yypos0; yythunkpos= yythunkpos0;
  349. yyprintf((stderr, " fail %s @ %s\n", "OPEN", yybuf+yypos));
  350. return 0;
  351. }
  352. YY_RULE(int) yy_NUMBER()
  353. { int yypos0= yypos, yythunkpos0= yythunkpos;
  354. yyprintf((stderr, "%s\n", "NUMBER")); yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l3; if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\377\003\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l3;
  355. l4:;
  356. { int yypos5= yypos, yythunkpos5= yythunkpos; if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\377\003\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l5; goto l4;
  357. l5:; yypos= yypos5; yythunkpos= yythunkpos5;
  358. } yyText(yybegin, yyend); if (!(YY_END)) goto l3; if (!yy__()) goto l3; yyDo(yy_1_NUMBER, yybegin, yyend);
  359. yyprintf((stderr, " ok %s @ %s\n", "NUMBER", yybuf+yypos));
  360. return 1;
  361. l3:; yypos= yypos0; yythunkpos= yythunkpos0;
  362. yyprintf((stderr, " fail %s @ %s\n", "NUMBER", yybuf+yypos));
  363. return 0;
  364. }
  365. YY_RULE(int) yy_DIVIDE()
  366. { int yypos0= yypos, yythunkpos0= yythunkpos;
  367. yyprintf((stderr, "%s\n", "DIVIDE")); if (!yymatchChar('/')) goto l6; if (!yy__()) goto l6;
  368. yyprintf((stderr, " ok %s @ %s\n", "DIVIDE", yybuf+yypos));
  369. return 1;
  370. l6:; yypos= yypos0; yythunkpos= yythunkpos0;
  371. yyprintf((stderr, " fail %s @ %s\n", "DIVIDE", yybuf+yypos));
  372. return 0;
  373. }
  374. YY_RULE(int) yy_TIMES()
  375. { int yypos0= yypos, yythunkpos0= yythunkpos;
  376. yyprintf((stderr, "%s\n", "TIMES")); if (!yymatchChar('*')) goto l7; if (!yy__()) goto l7;
  377. yyprintf((stderr, " ok %s @ %s\n", "TIMES", yybuf+yypos));
  378. return 1;
  379. l7:; yypos= yypos0; yythunkpos= yythunkpos0;
  380. yyprintf((stderr, " fail %s @ %s\n", "TIMES", yybuf+yypos));
  381. return 0;
  382. }
  383. YY_RULE(int) yy_Value()
  384. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 1, 0);
  385. yyprintf((stderr, "%s\n", "Value"));
  386. { int yypos9= yypos, yythunkpos9= yythunkpos; if (!yy_NUMBER()) goto l10; yyDo(yySet, -1, 0); yyDo(yy_1_Value, yybegin, yyend); goto l9;
  387. l10:; yypos= yypos9; yythunkpos= yythunkpos9; if (!yy_ID()) goto l11; yyDo(yySet, -1, 0);
  388. { int yypos12= yypos, yythunkpos12= yythunkpos; if (!yy_ASSIGN()) goto l12; goto l11;
  389. l12:; yypos= yypos12; yythunkpos= yythunkpos12;
  390. } yyDo(yy_2_Value, yybegin, yyend); goto l9;
  391. l11:; yypos= yypos9; yythunkpos= yythunkpos9; if (!yy_OPEN()) goto l8; if (!yy_Expr()) goto l8; yyDo(yySet, -1, 0); if (!yy_CLOSE()) goto l8; yyDo(yy_3_Value, yybegin, yyend);
  392. }
  393. l9:;
  394. yyprintf((stderr, " ok %s @ %s\n", "Value", yybuf+yypos)); yyDo(yyPop, 1, 0);
  395. return 1;
  396. l8:; yypos= yypos0; yythunkpos= yythunkpos0;
  397. yyprintf((stderr, " fail %s @ %s\n", "Value", yybuf+yypos));
  398. return 0;
  399. }
  400. YY_RULE(int) yy_MINUS()
  401. { int yypos0= yypos, yythunkpos0= yythunkpos;
  402. yyprintf((stderr, "%s\n", "MINUS")); if (!yymatchChar('-')) goto l13; if (!yy__()) goto l13;
  403. yyprintf((stderr, " ok %s @ %s\n", "MINUS", yybuf+yypos));
  404. return 1;
  405. l13:; yypos= yypos0; yythunkpos= yythunkpos0;
  406. yyprintf((stderr, " fail %s @ %s\n", "MINUS", yybuf+yypos));
  407. return 0;
  408. }
  409. YY_RULE(int) yy_PLUS()
  410. { int yypos0= yypos, yythunkpos0= yythunkpos;
  411. yyprintf((stderr, "%s\n", "PLUS")); if (!yymatchChar('+')) goto l14; if (!yy__()) goto l14;
  412. yyprintf((stderr, " ok %s @ %s\n", "PLUS", yybuf+yypos));
  413. return 1;
  414. l14:; yypos= yypos0; yythunkpos= yythunkpos0;
  415. yyprintf((stderr, " fail %s @ %s\n", "PLUS", yybuf+yypos));
  416. return 0;
  417. }
  418. YY_RULE(int) yy_Product()
  419. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
  420. yyprintf((stderr, "%s\n", "Product")); if (!yy_Value()) goto l15; yyDo(yySet, -2, 0);
  421. l16:;
  422. { int yypos17= yypos, yythunkpos17= yythunkpos;
  423. { int yypos18= yypos, yythunkpos18= yythunkpos; if (!yy_TIMES()) goto l19; if (!yy_Value()) goto l19; yyDo(yySet, -1, 0); yyDo(yy_1_Product, yybegin, yyend); goto l18;
  424. l19:; yypos= yypos18; yythunkpos= yythunkpos18; if (!yy_DIVIDE()) goto l17; if (!yy_Value()) goto l17; yyDo(yySet, -1, 0); yyDo(yy_2_Product, yybegin, yyend);
  425. }
  426. l18:; goto l16;
  427. l17:; yypos= yypos17; yythunkpos= yythunkpos17;
  428. } yyDo(yy_3_Product, yybegin, yyend);
  429. yyprintf((stderr, " ok %s @ %s\n", "Product", yybuf+yypos)); yyDo(yyPop, 2, 0);
  430. return 1;
  431. l15:; yypos= yypos0; yythunkpos= yythunkpos0;
  432. yyprintf((stderr, " fail %s @ %s\n", "Product", yybuf+yypos));
  433. return 0;
  434. }
  435. YY_RULE(int) yy_Sum()
  436. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
  437. yyprintf((stderr, "%s\n", "Sum")); if (!yy_Product()) goto l20; yyDo(yySet, -2, 0);
  438. l21:;
  439. { int yypos22= yypos, yythunkpos22= yythunkpos;
  440. { int yypos23= yypos, yythunkpos23= yythunkpos; if (!yy_PLUS()) goto l24; if (!yy_Product()) goto l24; yyDo(yySet, -1, 0); yyDo(yy_1_Sum, yybegin, yyend); goto l23;
  441. l24:; yypos= yypos23; yythunkpos= yythunkpos23; if (!yy_MINUS()) goto l22; if (!yy_Product()) goto l22; yyDo(yySet, -1, 0); yyDo(yy_2_Sum, yybegin, yyend);
  442. }
  443. l23:; goto l21;
  444. l22:; yypos= yypos22; yythunkpos= yythunkpos22;
  445. } yyDo(yy_3_Sum, yybegin, yyend);
  446. yyprintf((stderr, " ok %s @ %s\n", "Sum", yybuf+yypos)); yyDo(yyPop, 2, 0);
  447. return 1;
  448. l20:; yypos= yypos0; yythunkpos= yythunkpos0;
  449. yyprintf((stderr, " fail %s @ %s\n", "Sum", yybuf+yypos));
  450. return 0;
  451. }
  452. YY_RULE(int) yy_ASSIGN()
  453. { int yypos0= yypos, yythunkpos0= yythunkpos;
  454. yyprintf((stderr, "%s\n", "ASSIGN")); if (!yymatchChar('=')) goto l25; if (!yy__()) goto l25;
  455. yyprintf((stderr, " ok %s @ %s\n", "ASSIGN", yybuf+yypos));
  456. return 1;
  457. l25:; yypos= yypos0; yythunkpos= yythunkpos0;
  458. yyprintf((stderr, " fail %s @ %s\n", "ASSIGN", yybuf+yypos));
  459. return 0;
  460. }
  461. YY_RULE(int) yy_ID()
  462. { int yypos0= yypos, yythunkpos0= yythunkpos;
  463. yyprintf((stderr, "%s\n", "ID")); yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l26; if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\000\000\000\000\000\000\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l26; yyText(yybegin, yyend); if (!(YY_END)) goto l26; if (!yy__()) goto l26; yyDo(yy_1_ID, yybegin, yyend);
  464. yyprintf((stderr, " ok %s @ %s\n", "ID", yybuf+yypos));
  465. return 1;
  466. l26:; yypos= yypos0; yythunkpos= yythunkpos0;
  467. yyprintf((stderr, " fail %s @ %s\n", "ID", yybuf+yypos));
  468. return 0;
  469. }
  470. YY_RULE(int) yy_EOL()
  471. { int yypos0= yypos, yythunkpos0= yythunkpos;
  472. yyprintf((stderr, "%s\n", "EOL"));
  473. { int yypos28= yypos, yythunkpos28= yythunkpos; if (!yymatchChar('\n')) goto l29; goto l28;
  474. l29:; yypos= yypos28; yythunkpos= yythunkpos28; if (!yymatchString("\r\n")) goto l30; goto l28;
  475. l30:; yypos= yypos28; yythunkpos= yythunkpos28; if (!yymatchChar('\r')) goto l31; goto l28;
  476. l31:; yypos= yypos28; yythunkpos= yythunkpos28; if (!yymatchChar(';')) goto l27;
  477. }
  478. l28:;
  479. yyprintf((stderr, " ok %s @ %s\n", "EOL", yybuf+yypos));
  480. return 1;
  481. l27:; yypos= yypos0; yythunkpos= yythunkpos0;
  482. yyprintf((stderr, " fail %s @ %s\n", "EOL", yybuf+yypos));
  483. return 0;
  484. }
  485. YY_RULE(int) yy_Expr()
  486. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
  487. yyprintf((stderr, "%s\n", "Expr"));
  488. { int yypos33= yypos, yythunkpos33= yythunkpos; if (!yy_ID()) goto l34; yyDo(yySet, -2, 0); if (!yy_ASSIGN()) goto l34; if (!yy_Sum()) goto l34; yyDo(yySet, -1, 0); yyDo(yy_1_Expr, yybegin, yyend); goto l33;
  489. l34:; yypos= yypos33; yythunkpos= yythunkpos33; if (!yy_Sum()) goto l32; yyDo(yySet, -1, 0); yyDo(yy_2_Expr, yybegin, yyend);
  490. }
  491. l33:;
  492. yyprintf((stderr, " ok %s @ %s\n", "Expr", yybuf+yypos)); yyDo(yyPop, 2, 0);
  493. return 1;
  494. l32:; yypos= yypos0; yythunkpos= yythunkpos0;
  495. yyprintf((stderr, " fail %s @ %s\n", "Expr", yybuf+yypos));
  496. return 0;
  497. }
  498. YY_RULE(int) yy__()
  499. {
  500. yyprintf((stderr, "%s\n", "_"));
  501. l36:;
  502. { int yypos37= yypos, yythunkpos37= yythunkpos; if (!yymatchClass((unsigned char *)"\000\002\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l37; goto l36;
  503. l37:; yypos= yypos37; yythunkpos= yythunkpos37;
  504. }
  505. yyprintf((stderr, " ok %s @ %s\n", "_", yybuf+yypos));
  506. return 1;
  507. }
  508. YY_RULE(int) yy_Stmt()
  509. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 1, 0);
  510. yyprintf((stderr, "%s\n", "Stmt"));
  511. { int yypos39= yypos, yythunkpos39= yythunkpos; if (!yy__()) goto l40; if (!yy_Expr()) goto l40; yyDo(yySet, -1, 0); if (!yy_EOL()) goto l40; yyDo(yy_1_Stmt, yybegin, yyend); goto l39;
  512. l40:; yypos= yypos39; yythunkpos= yythunkpos39;
  513. l41:;
  514. { int yypos42= yypos, yythunkpos42= yythunkpos;
  515. { int yypos43= yypos, yythunkpos43= yythunkpos; if (!yy_EOL()) goto l43; goto l42;
  516. l43:; yypos= yypos43; yythunkpos= yythunkpos43;
  517. } if (!yymatchDot()) goto l42; goto l41;
  518. l42:; yypos= yypos42; yythunkpos= yythunkpos42;
  519. } if (!yy_EOL()) goto l38; yyDo(yy_2_Stmt, yybegin, yyend);
  520. }
  521. l39:;
  522. yyprintf((stderr, " ok %s @ %s\n", "Stmt", yybuf+yypos)); yyDo(yyPop, 1, 0);
  523. return 1;
  524. l38:; yypos= yypos0; yythunkpos= yythunkpos0;
  525. yyprintf((stderr, " fail %s @ %s\n", "Stmt", yybuf+yypos));
  526. return 0;
  527. }
  528. #ifndef YY_PART
  529. typedef int (*yyrule)();
  530. YY_PARSE(int) YYPARSEFROM(yyrule yystart)
  531. {
  532. int yyok;
  533. if (!yybuflen)
  534. {
  535. yybuflen= 1024;
  536. yybuf= malloc(yybuflen);
  537. yytextlen= 1024;
  538. yytext= malloc(yytextlen);
  539. yythunkslen= 32;
  540. yythunks= malloc(sizeof(yythunk) * yythunkslen);
  541. yyvalslen= 32;
  542. yyvals= malloc(sizeof(YYSTYPE) * yyvalslen);
  543. yybegin= yyend= yypos= yylimit= yythunkpos= 0;
  544. }
  545. yybegin= yyend= yypos;
  546. yythunkpos= 0;
  547. yyval= yyvals;
  548. yyok= yystart();
  549. if (yyok) yyDone();
  550. yyCommit();
  551. return yyok;
  552. (void)yyrefill;
  553. (void)yymatchDot;
  554. (void)yymatchChar;
  555. (void)yymatchString;
  556. (void)yymatchClass;
  557. (void)yyDo;
  558. (void)yyText;
  559. (void)yyDone;
  560. (void)yyCommit;
  561. (void)yyAccept;
  562. (void)yyPush;
  563. (void)yyPop;
  564. (void)yySet;
  565. (void)yytextmax;
  566. }
  567. YY_PARSE(int) YYPARSE(void)
  568. {
  569. return YYPARSEFROM(yy_Stmt);
  570. }
  571. #endif
  572. int main()
  573. {
  574. while (yyparse());
  575. return 0;
  576. }