Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1960 lines
50 KiB

  1. /* Copyright (C) Boris Nikolaus, Germany, 1996-1997. All rights reserved. */
  2. #line 4 "parser.ll"
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "defs.h"
  6. #define MAXTAGS 16
  7. extern char *find_tag(char *);
  8. extern item_t *find_symbol(char *);
  9. extern item_t *get_symbol(char *);
  10. extern char *convert(char *);
  11. extern item_t *create_symbol(int isnonterm, int isexternal, char *tag, char *identifier, char *altidentifier, char **args);
  12. extern char *conststr;
  13. extern char *ll;
  14. extern char *LL;
  15. extern char *usetypes;
  16. extern char *USETYPES;
  17. void output(char *fmt, ...);
  18. void output_line();
  19. void output_rhs(char *identifier, struct rhs_s *rhs);
  20. void incput(char *fmt, ...);
  21. void create_vardefs();
  22. void set_start(char *startstr);
  23. void set_prefix(char *prefixstr);
  24. void set_module(char *modulestr);
  25. void add_rules(item_t *item, struct rhs_s *rhs);
  26. #line 30 "parser.c"
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <stdarg.h>
  30. #include <limits.h>
  31. #include "parser.h"
  32. int llcpos;
  33. int *llstk;
  34. unsigned llstksize;
  35. unsigned llcstp = 1;
  36. LLTERM *lltokens;
  37. int llntokens;
  38. char llerrormsg[256];
  39. LLPOS llerrorpos;
  40. int llepos;
  41. LLSTYPE lllval;
  42. int llterm(int token, LLSTYPE *lval, LLSTATE *llin, LLSTATE *llout);
  43. void llfailed(LLPOS *pos, char *fmt, ...);
  44. void llresizestk();
  45. #define LLCHECKSTK do{if (llcstp + 1 >= llstksize) llresizestk();}while(/*CONSTCOND*/0)
  46. #define LLFAILED(_err) do{llfailed _err; goto failed;}while(/*CONSTCOND*/0)
  47. #define LLCUTOFF do{unsigned i; for (i = llstp; i < llcstp; i++) if (llstk[i] > 0) llstk[i] = -llstk[i];}while(/*CONSTCOND*/0)
  48. #define LLCUTTHIS do{if (llstk[llstp] > 0) llstk[llstp] = -llstk[llstp];}while(/*CONSTCOND*/0)
  49. #define LLCUTALL do{unsigned i; for (i = 0; i < llcstp; i++) if (llstk[i] > 0) llstk[i] = -llstk[i];}while(/*CONSTCOND*/0)
  50. #if LLDEBUG > 0
  51. int lldebug;
  52. int last_linenr;
  53. char *last_file = "";
  54. #define LLDEBUG_ENTER(_ident) lldebug_enter(_ident)
  55. #define LLDEBUG_LEAVE(_ident,_succ) lldebug_leave(_ident,_succ)
  56. #define LLDEBUG_ALTERNATIVE(_ident,_alt) lldebug_alternative(_ident,_alt)
  57. #define LLDEBUG_ITERATION(_ident,_num) lldebug_iteration(_ident,_num)
  58. #define LLDEBUG_TOKEN(_exp,_pos) lldebug_token(_exp,_pos)
  59. #define LLDEBUG_ANYTOKEN(_pos) lldebug_anytoken(_pos)
  60. #define LLDEBUG_BACKTRACKING(_ident) lldebug_backtracking(_ident)
  61. void lldebug_init();
  62. void lldebug_enter(char *ident);
  63. void lldebug_leave(char *ident, int succ);
  64. void lldebug_alternative(char *ident, int alt);
  65. void lldebug_token(int expected, unsigned pos);
  66. void lldebug_anytoken(unsigned pos);
  67. void lldebug_backtracking(char *ident);
  68. void llprinttoken(LLTERM *token, char *identifier, FILE *f);
  69. #else
  70. #define LLDEBUG_ENTER(_ident)
  71. #define LLDEBUG_LEAVE(_ident,_succ)
  72. #define LLDEBUG_ALTERNATIVE(_ident,_alt)
  73. #define LLDEBUG_ITERATION(_ident,_num)
  74. #define LLDEBUG_TOKEN(_exp,_pos)
  75. #define LLDEBUG_ANYTOKEN(_pos)
  76. #define LLDEBUG_BACKTRACKING(_ident)
  77. #endif
  78. int ll_main(LLSTATE *llin, LLSTATE *llout)
  79. {
  80. unsigned llstp = llcstp;
  81. LLSTATE llstate_0;
  82. LLDEBUG_ENTER("main");
  83. llstate_0 = *llin;
  84. #undef failed
  85. #define failed failed1
  86. {LLSTATE llstate_1;
  87. if (!ll_declsect(&llstate_0, &llstate_1)) goto failed1;
  88. {LLSTATE llstate_2;
  89. if (!llterm(PERCENT_PERCENT, (LLSTYPE *)0, &llstate_1, &llstate_2)) goto failed1;
  90. {LLSTATE llstate_3;
  91. if (!ll_rulesect(&llstate_2, &llstate_3)) goto failed1;
  92. {LLSTATE llstate_4;
  93. if (!llterm(PERCENT_PERCENT, (LLSTYPE *)0, &llstate_3, &llstate_4)) goto failed1;
  94. {LLSTATE llstate_5;
  95. if (!ll_csect(&llstate_4, &llstate_5)) goto failed1;
  96. *llout = llstate_5;
  97. }}}}}
  98. LLDEBUG_LEAVE("main", 1);
  99. return 1;
  100. failed1: LLDEBUG_LEAVE("main", 0);
  101. return 0;
  102. }
  103. int ll_declsect(LLSTATE *llin, LLSTATE *llout)
  104. {
  105. unsigned llstp = llcstp;
  106. LLSTATE llstate_0;
  107. LLDEBUG_ENTER("declsect");
  108. llstate_0 = *llin;
  109. #undef failed
  110. #define failed failed1
  111. #undef failed
  112. #define failed failed2
  113. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  114. LLCHECKSTK;
  115. for (;;) {
  116. switch (llstk[llcstp++]) {
  117. case 1: case -1:
  118. LLDEBUG_ALTERNATIVE("declsect", 1);
  119. {LLSTATE llstate_1;
  120. if (!ll_decl(&llstate_0, &llstate_1)) goto failed2;
  121. {LLSTATE llstate_2;
  122. if (!ll_declsect(&llstate_1, &llstate_2)) goto failed2;
  123. *llout = llstate_2;
  124. break;
  125. }}
  126. case 2: case -2:
  127. LLDEBUG_ALTERNATIVE("declsect", 2);
  128. *llout = llstate_0;
  129. #line 94 "parser.ll"
  130. {create_vardefs();
  131. #line 144 "parser.c"
  132. break;
  133. }
  134. default:
  135. llstk[--llcstp] = 1;
  136. goto failed1;
  137. failed2:
  138. LLDEBUG_BACKTRACKING("declsect");
  139. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  140. llcpos = llpos1; llcstp = llstp1;
  141. continue;
  142. } break;
  143. }}
  144. LLDEBUG_LEAVE("declsect", 1);
  145. return 1;
  146. failed1: LLDEBUG_LEAVE("declsect", 0);
  147. return 0;
  148. }
  149. int ll_decl(LLSTATE *llin, LLSTATE *llout)
  150. {
  151. unsigned llstp = llcstp;
  152. LLSTATE llstate_0;
  153. LLDEBUG_ENTER("decl");
  154. llstate_0 = *llin;
  155. #undef failed
  156. #define failed failed1
  157. #undef failed
  158. #define failed failed2
  159. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  160. LLCHECKSTK;
  161. for (;;) {
  162. switch (llstk[llcstp++]) {
  163. case 1: case -1:
  164. LLDEBUG_ALTERNATIVE("decl", 1);
  165. {LLSTATE llstate_1;
  166. if (!llterm(PERCENT_TOKEN, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  167. {LLSTATE llstate_2;
  168. if (!ll_tokens(&llstate_1, &llstate_2, NULL)) goto failed2;
  169. *llout = llstate_2;
  170. break;
  171. }}
  172. case 2: case -2:
  173. LLDEBUG_ALTERNATIVE("decl", 2);
  174. {LLSTATE llstate_1;
  175. if (!llterm(PERCENT_TOKEN, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  176. {LLSTATE llstate_2;string llatt_2;
  177. if (!ll_tag(&llatt_2, &llstate_1, &llstate_2)) goto failed2;
  178. {LLSTATE llstate_3;
  179. if (!ll_tokens(&llstate_2, &llstate_3, llatt_2)) goto failed2;
  180. *llout = llstate_3;
  181. break;
  182. }}}
  183. case 3: case -3:
  184. LLDEBUG_ALTERNATIVE("decl", 3);
  185. {LLSTATE llstate_1;
  186. if (!llterm(PERCENT_TYPE, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  187. {LLSTATE llstate_2;
  188. if (!ll_nterms(&llstate_1, &llstate_2, NULL, 0)) goto failed2;
  189. *llout = llstate_2;
  190. break;
  191. }}
  192. case 4: case -4:
  193. LLDEBUG_ALTERNATIVE("decl", 4);
  194. {LLSTATE llstate_1;
  195. if (!llterm(PERCENT_TYPE, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  196. {LLSTATE llstate_2;string llatt_2;
  197. if (!ll_tag(&llatt_2, &llstate_1, &llstate_2)) goto failed2;
  198. {LLSTATE llstate_3;
  199. if (!ll_nterms(&llstate_2, &llstate_3, llatt_2, 0)) goto failed2;
  200. *llout = llstate_3;
  201. break;
  202. }}}
  203. case 5: case -5:
  204. LLDEBUG_ALTERNATIVE("decl", 5);
  205. {LLSTATE llstate_1;
  206. if (!llterm(PERCENT_EXTERNAL, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  207. {LLSTATE llstate_2;
  208. if (!ll_nterms(&llstate_1, &llstate_2, NULL, 1)) goto failed2;
  209. *llout = llstate_2;
  210. break;
  211. }}
  212. case 6: case -6:
  213. LLDEBUG_ALTERNATIVE("decl", 6);
  214. {LLSTATE llstate_1;
  215. if (!llterm(PERCENT_EXTERNAL, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  216. {LLSTATE llstate_2;string llatt_2;
  217. if (!ll_tag(&llatt_2, &llstate_1, &llstate_2)) goto failed2;
  218. {LLSTATE llstate_3;
  219. if (!ll_nterms(&llstate_2, &llstate_3, llatt_2, 1)) goto failed2;
  220. *llout = llstate_3;
  221. break;
  222. }}}
  223. case 7: case -7:
  224. LLDEBUG_ALTERNATIVE("decl", 7);
  225. {LLSTATE llstate_1;
  226. if (!llterm(PERCENT_UNION, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  227. {LLSTATE llstate_2;
  228. if (!llterm('{', (LLSTYPE *)0, &llstate_1, &llstate_2)) goto failed2;
  229. {LLSTATE llstate_3;
  230. if (!ll_union(&llstate_2, &llstate_3)) goto failed2;
  231. {LLSTATE llstate_4;
  232. if (!llterm('}', (LLSTYPE *)0, &llstate_3, &llstate_4)) goto failed2;
  233. *llout = llstate_4;
  234. #line 104 "parser.ll"
  235. {output("\n");
  236. #line 251 "parser.c"
  237. break;
  238. }}}}}
  239. case 8: case -8:
  240. LLDEBUG_ALTERNATIVE("decl", 8);
  241. {LLSTATE llstate_1;
  242. if (!llterm(PERCENT_STATE, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  243. {LLSTATE llstate_2;
  244. if (!llterm('{', (LLSTYPE *)0, &llstate_1, &llstate_2)) goto failed2;
  245. {LLSTATE llstate_3;
  246. if (!ll_state(&llstate_2, &llstate_3)) goto failed2;
  247. {LLSTATE llstate_4;
  248. if (!llterm('}', (LLSTYPE *)0, &llstate_3, &llstate_4)) goto failed2;
  249. *llout = llstate_4;
  250. #line 106 "parser.ll"
  251. {output("\n");
  252. #line 267 "parser.c"
  253. break;
  254. }}}}}
  255. case 9: case -9:
  256. LLDEBUG_ALTERNATIVE("decl", 9);
  257. {LLSTATE llstate_1;
  258. if (!llterm(PERCENT_PREFIX, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  259. {LLSTATE llstate_2;string llatt_2;
  260. if (!llterm(IDENTIFIER, &lllval, &llstate_1, &llstate_2)) goto failed2;
  261. llatt_2 = lllval._string;
  262. *llout = llstate_2;
  263. #line 108 "parser.ll"
  264. {set_prefix(llatt_2);
  265. #line 280 "parser.c"
  266. break;
  267. }}}
  268. case 10: case -10:
  269. LLDEBUG_ALTERNATIVE("decl", 10);
  270. {LLSTATE llstate_1;
  271. if (!llterm(PERCENT_MODULE, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  272. {LLSTATE llstate_2;string llatt_2;
  273. if (!llterm(IDENTIFIER, &lllval, &llstate_1, &llstate_2)) goto failed2;
  274. llatt_2 = lllval._string;
  275. *llout = llstate_2;
  276. #line 110 "parser.ll"
  277. {set_module(llatt_2);
  278. #line 293 "parser.c"
  279. break;
  280. }}}
  281. case 11: case -11:
  282. LLDEBUG_ALTERNATIVE("decl", 11);
  283. {LLSTATE llstate_1;
  284. if (!llterm(PERCENT_LBRACE, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  285. {LLSTATE llstate_2;ccode llatt_2;
  286. if (!llterm(CCODE, &lllval, &llstate_1, &llstate_2)) goto failed2;
  287. llatt_2 = lllval._ccode;
  288. {LLSTATE llstate_3;
  289. if (!llterm(PERCENT_RBRACE, (LLSTYPE *)0, &llstate_2, &llstate_3)) goto failed2;
  290. *llout = llstate_3;
  291. #line 112 "parser.ll"
  292. {if (linedirective)
  293. output("#line %d \"%s\"\n", llstate_2.pos.line, llstate_2.pos.file);
  294. output("%s", llatt_2);
  295. if (linedirective)
  296. output_line();
  297. #line 313 "parser.c"
  298. break;
  299. }}}}
  300. case 12: case -12:
  301. LLDEBUG_ALTERNATIVE("decl", 12);
  302. {LLSTATE llstate_1;
  303. if (!llterm(PERCENT_START, (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  304. {LLSTATE llstate_2;string llatt_2;
  305. if (!llterm(IDENTIFIER, &lllval, &llstate_1, &llstate_2)) goto failed2;
  306. llatt_2 = lllval._string;
  307. *llout = llstate_2;
  308. #line 119 "parser.ll"
  309. {set_start(llatt_2);
  310. #line 326 "parser.c"
  311. break;
  312. }}}
  313. default:
  314. llstk[--llcstp] = 1;
  315. goto failed1;
  316. failed2:
  317. LLDEBUG_BACKTRACKING("decl");
  318. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  319. llcpos = llpos1; llcstp = llstp1;
  320. continue;
  321. } break;
  322. }}
  323. LLDEBUG_LEAVE("decl", 1);
  324. return 1;
  325. failed1: LLDEBUG_LEAVE("decl", 0);
  326. return 0;
  327. }
  328. int ll_tokens(LLSTATE *llin, LLSTATE *llout, string llarg_tag)
  329. {
  330. unsigned llstp = llcstp;
  331. LLSTATE llstate_0;
  332. LLDEBUG_ENTER("tokens");
  333. llstate_0 = *llin;
  334. #undef failed
  335. #define failed failed1
  336. {LLSTATE llstate_1;token llatt_1;
  337. if (!ll_token(&llatt_1, &llstate_0, &llstate_1, llarg_tag)) goto failed1;
  338. {LLSTATE llstate_2;
  339. if (!ll_tokens2(&llstate_1, &llstate_2, llarg_tag)) goto failed1;
  340. *llout = llstate_2;
  341. #line 123 "parser.ll"
  342. {create_symbol(0, 0, llarg_tag, llatt_1.identifier, llatt_1.altidentifier,
  343. NULL);
  344. #line 363 "parser.c"
  345. }}}
  346. LLDEBUG_LEAVE("tokens", 1);
  347. return 1;
  348. failed1: LLDEBUG_LEAVE("tokens", 0);
  349. return 0;
  350. }
  351. int ll_tokens2(LLSTATE *llin, LLSTATE *llout, string llarg_tag)
  352. {
  353. unsigned llstp = llcstp;
  354. LLSTATE llstate_0;
  355. LLDEBUG_ENTER("tokens2");
  356. llstate_0 = *llin;
  357. #undef failed
  358. #define failed failed1
  359. #undef failed
  360. #define failed failed2
  361. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  362. LLCHECKSTK;
  363. for (;;) {
  364. switch (llstk[llcstp++]) {
  365. case 1: case -1:
  366. LLDEBUG_ALTERNATIVE("tokens2", 1);
  367. {LLSTATE llstate_1;token llatt_1;
  368. if (!ll_token(&llatt_1, &llstate_0, &llstate_1, llarg_tag)) goto failed2;
  369. {LLSTATE llstate_2;
  370. if (!ll_tokens2(&llstate_1, &llstate_2, llarg_tag)) goto failed2;
  371. *llout = llstate_2;
  372. #line 129 "parser.ll"
  373. {create_symbol(0, 0, llarg_tag, llatt_1.identifier, llatt_1.altidentifier,
  374. NULL);
  375. #line 397 "parser.c"
  376. break;
  377. }}}
  378. case 2: case -2:
  379. LLDEBUG_ALTERNATIVE("tokens2", 2);
  380. *llout = llstate_0;
  381. break;
  382. default:
  383. llstk[--llcstp] = 1;
  384. goto failed1;
  385. failed2:
  386. LLDEBUG_BACKTRACKING("tokens2");
  387. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  388. llcpos = llpos1; llcstp = llstp1;
  389. continue;
  390. } break;
  391. }}
  392. LLDEBUG_LEAVE("tokens2", 1);
  393. return 1;
  394. failed1: LLDEBUG_LEAVE("tokens2", 0);
  395. return 0;
  396. }
  397. int ll_token(token *llret, LLSTATE *llin, LLSTATE *llout, string llarg_tag)
  398. {
  399. unsigned llstp = llcstp;
  400. LLSTATE llstate_0;
  401. LLDEBUG_ENTER("token");
  402. llstate_0 = *llin;
  403. #undef failed
  404. #define failed failed1
  405. #undef failed
  406. #define failed failed2
  407. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  408. LLCHECKSTK;
  409. for (;;) {
  410. switch (llstk[llcstp++]) {
  411. case 1: case -1:
  412. LLDEBUG_ALTERNATIVE("token", 1);
  413. {LLSTATE llstate_1;string llatt_1;
  414. if (!llterm(IDENTIFIER, &lllval, &llstate_0, &llstate_1)) goto failed2;
  415. llatt_1 = lllval._string;
  416. {LLSTATE llstate_2;
  417. if (!llterm('=', (LLSTYPE *)0, &llstate_1, &llstate_2)) goto failed2;
  418. {LLSTATE llstate_3;string llatt_3;
  419. if (!llterm(IDENTIFIER, &lllval, &llstate_2, &llstate_3)) goto failed2;
  420. llatt_3 = lllval._string;
  421. *llout = llstate_3;
  422. #line 136 "parser.ll"
  423. {(*llret).identifier = llatt_1; (*llret).altidentifier = llatt_3;
  424. #line 448 "parser.c"
  425. break;
  426. }}}}
  427. case 2: case -2:
  428. LLDEBUG_ALTERNATIVE("token", 2);
  429. {LLSTATE llstate_1;string llatt_1;
  430. if (!llterm(IDENTIFIER, &lllval, &llstate_0, &llstate_1)) goto failed2;
  431. llatt_1 = lllval._string;
  432. *llout = llstate_1;
  433. #line 138 "parser.ll"
  434. {(*llret).identifier = llatt_1; (*llret).altidentifier = NULL;
  435. #line 459 "parser.c"
  436. break;
  437. }}
  438. default:
  439. llstk[--llcstp] = 1;
  440. goto failed1;
  441. failed2:
  442. LLDEBUG_BACKTRACKING("token");
  443. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  444. llcpos = llpos1; llcstp = llstp1;
  445. continue;
  446. } break;
  447. }}
  448. LLDEBUG_LEAVE("token", 1);
  449. return 1;
  450. failed1: LLDEBUG_LEAVE("token", 0);
  451. return 0;
  452. }
  453. int ll_nterms(LLSTATE *llin, LLSTATE *llout, string llarg_tag, integer llarg_ext)
  454. {
  455. unsigned llstp = llcstp;
  456. LLSTATE llstate_0;
  457. LLDEBUG_ENTER("nterms");
  458. llstate_0 = *llin;
  459. #undef failed
  460. #define failed failed1
  461. {LLSTATE llstate_1;nterm llatt_1;
  462. if (!ll_nterm(&llatt_1, &llstate_0, &llstate_1, llarg_tag)) goto failed1;
  463. {LLSTATE llstate_2;
  464. if (!ll_nterms2(&llstate_1, &llstate_2, llarg_tag, llarg_ext)) goto failed1;
  465. *llout = llstate_2;
  466. #line 142 "parser.ll"
  467. {create_symbol(1, llarg_ext, llarg_tag, llatt_1.identifier, NULL, llatt_1.tags);
  468. #line 494 "parser.c"
  469. }}}
  470. LLDEBUG_LEAVE("nterms", 1);
  471. return 1;
  472. failed1: LLDEBUG_LEAVE("nterms", 0);
  473. return 0;
  474. }
  475. int ll_nterms2(LLSTATE *llin, LLSTATE *llout, string llarg_tag, integer llarg_ext)
  476. {
  477. unsigned llstp = llcstp;
  478. LLSTATE llstate_0;
  479. LLDEBUG_ENTER("nterms2");
  480. llstate_0 = *llin;
  481. #undef failed
  482. #define failed failed1
  483. #undef failed
  484. #define failed failed2
  485. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  486. LLCHECKSTK;
  487. for (;;) {
  488. switch (llstk[llcstp++]) {
  489. case 1: case -1:
  490. LLDEBUG_ALTERNATIVE("nterms2", 1);
  491. {LLSTATE llstate_1;nterm llatt_1;
  492. if (!ll_nterm(&llatt_1, &llstate_0, &llstate_1, llarg_tag)) goto failed2;
  493. {LLSTATE llstate_2;
  494. if (!ll_nterms2(&llstate_1, &llstate_2, llarg_tag, llarg_ext)) goto failed2;
  495. *llout = llstate_2;
  496. #line 146 "parser.ll"
  497. {create_symbol(1, llarg_ext, llarg_tag, llatt_1.identifier, NULL, llatt_1.tags);
  498. #line 526 "parser.c"
  499. break;
  500. }}}
  501. case 2: case -2:
  502. LLDEBUG_ALTERNATIVE("nterms2", 2);
  503. *llout = llstate_0;
  504. break;
  505. default:
  506. llstk[--llcstp] = 1;
  507. goto failed1;
  508. failed2:
  509. LLDEBUG_BACKTRACKING("nterms2");
  510. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  511. llcpos = llpos1; llcstp = llstp1;
  512. continue;
  513. } break;
  514. }}
  515. LLDEBUG_LEAVE("nterms2", 1);
  516. return 1;
  517. failed1: LLDEBUG_LEAVE("nterms2", 0);
  518. return 0;
  519. }
  520. int ll_nterm(nterm *llret, LLSTATE *llin, LLSTATE *llout, string llarg_tag)
  521. {
  522. unsigned llstp = llcstp;
  523. LLSTATE llstate_0;
  524. LLDEBUG_ENTER("nterm");
  525. llstate_0 = *llin;
  526. #undef failed
  527. #define failed failed1
  528. {LLSTATE llstate_1;string llatt_1;
  529. if (!llterm(IDENTIFIER, &lllval, &llstate_0, &llstate_1)) goto failed1;
  530. llatt_1 = lllval._string;
  531. {LLSTATE llstate_2;strings llatt_2;
  532. if (!ll_tags(&llatt_2, &llstate_1, &llstate_2)) goto failed1;
  533. *llout = llstate_2;
  534. #line 151 "parser.ll"
  535. {(*llret).identifier = llatt_1; (*llret).tags = llatt_2;
  536. #line 566 "parser.c"
  537. }}}
  538. LLDEBUG_LEAVE("nterm", 1);
  539. return 1;
  540. failed1: LLDEBUG_LEAVE("nterm", 0);
  541. return 0;
  542. }
  543. int ll_tags(strings *llret, LLSTATE *llin, LLSTATE *llout)
  544. {
  545. unsigned llstp = llcstp;
  546. LLSTATE llstate_0;
  547. LLDEBUG_ENTER("tags");
  548. llstate_0 = *llin;
  549. #undef failed
  550. #define failed failed1
  551. #undef failed
  552. #define failed failed2
  553. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  554. LLCHECKSTK;
  555. for (;;) {
  556. switch (llstk[llcstp++]) {
  557. case 1: case -1:
  558. LLDEBUG_ALTERNATIVE("tags", 1);
  559. {LLSTATE llstate_1;string llatt_1;
  560. if (!ll_tag(&llatt_1, &llstate_0, &llstate_1)) goto failed2;
  561. {LLSTATE llstate_2;strings llatt_2;
  562. if (!ll_tags(&llatt_2, &llstate_1, &llstate_2)) goto failed2;
  563. *llout = llstate_2;
  564. #line 155 "parser.ll"
  565. {(*llret) = llatt_2;
  566. memmove((*llret) + 1, (*llret),
  567. (MAXTAGS - 1) * sizeof(char *));
  568. (*llret)[0] = llatt_1;
  569. #line 602 "parser.c"
  570. break;
  571. }}}
  572. case 2: case -2:
  573. LLDEBUG_ALTERNATIVE("tags", 2);
  574. *llout = llstate_0;
  575. #line 161 "parser.ll"
  576. {(*llret) = (char **)malloc(MAXTAGS * sizeof(char *));
  577. memset((*llret), 0, MAXTAGS * sizeof(char *));
  578. #line 612 "parser.c"
  579. break;
  580. }
  581. default:
  582. llstk[--llcstp] = 1;
  583. goto failed1;
  584. failed2:
  585. LLDEBUG_BACKTRACKING("tags");
  586. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  587. llcpos = llpos1; llcstp = llstp1;
  588. continue;
  589. } break;
  590. }}
  591. LLDEBUG_LEAVE("tags", 1);
  592. return 1;
  593. failed1: LLDEBUG_LEAVE("tags", 0);
  594. return 0;
  595. }
  596. int ll_tag(string *llret, LLSTATE *llin, LLSTATE *llout)
  597. {
  598. unsigned llstp = llcstp;
  599. LLSTATE llstate_0;
  600. LLDEBUG_ENTER("tag");
  601. llstate_0 = *llin;
  602. #undef failed
  603. #define failed failed1
  604. #undef failed
  605. #define failed failed2
  606. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  607. LLCHECKSTK;
  608. for (;;) {
  609. switch (llstk[llcstp++]) {
  610. case 1: case -1:
  611. LLDEBUG_ALTERNATIVE("tag", 1);
  612. {LLSTATE llstate_1;
  613. if (!llterm('<', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  614. {LLSTATE llstate_2;string llatt_2;
  615. if (!llterm(IDENTIFIER, &lllval, &llstate_1, &llstate_2)) goto failed2;
  616. llatt_2 = lllval._string;
  617. {LLSTATE llstate_3;
  618. if (!llterm('>', (LLSTYPE *)0, &llstate_2, &llstate_3)) goto failed2;
  619. *llout = llstate_3;
  620. #line 167 "parser.ll"
  621. {(*llret) = find_tag(llatt_2);
  622. #line 658 "parser.c"
  623. break;
  624. }}}}
  625. case 2: case -2:
  626. LLDEBUG_ALTERNATIVE("tag", 2);
  627. {LLSTATE llstate_1;
  628. if (!llterm('<', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  629. {LLSTATE llstate_2;
  630. if (!llterm('>', (LLSTYPE *)0, &llstate_1, &llstate_2)) goto failed2;
  631. *llout = llstate_2;
  632. #line 169 "parser.ll"
  633. {(*llret) = (char *)malloc(strlen(LL) + 6);
  634. sprintf((*llret), "%sSTYPE", LL);
  635. #line 672 "parser.c"
  636. break;
  637. }}}
  638. default:
  639. llstk[--llcstp] = 1;
  640. goto failed1;
  641. failed2:
  642. LLDEBUG_BACKTRACKING("tag");
  643. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  644. llcpos = llpos1; llcstp = llstp1;
  645. continue;
  646. } break;
  647. }}
  648. LLDEBUG_LEAVE("tag", 1);
  649. return 1;
  650. failed1: LLDEBUG_LEAVE("tag", 0);
  651. return 0;
  652. }
  653. int ll_union(LLSTATE *llin, LLSTATE *llout)
  654. {
  655. unsigned llstp = llcstp;
  656. LLSTATE llstate_0;
  657. LLDEBUG_ENTER("union");
  658. llstate_0 = *llin;
  659. #undef failed
  660. #define failed failed1
  661. #undef failed
  662. #define failed failed2
  663. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  664. LLCHECKSTK;
  665. for (;;) {
  666. switch (llstk[llcstp++]) {
  667. case 1: case -1:
  668. LLDEBUG_ALTERNATIVE("union", 1);
  669. {LLSTATE llstate_1;string llatt_1;
  670. if (!llterm(TAGDEF, &lllval, &llstate_0, &llstate_1)) goto failed2;
  671. llatt_1 = lllval._string;
  672. {LLSTATE llstate_2;
  673. if (!llterm(';', (LLSTYPE *)0, &llstate_1, &llstate_2)) goto failed2;
  674. #line 175 "parser.ll"
  675. {if (!usetypes) incput("typedef %s;\n", llatt_1);
  676. #line 715 "parser.c"
  677. {LLSTATE llstate_3;
  678. if (!ll_union(&llstate_2, &llstate_3)) goto failed2;
  679. *llout = llstate_3;
  680. break;
  681. }}}}
  682. case 2: case -2:
  683. LLDEBUG_ALTERNATIVE("union", 2);
  684. *llout = llstate_0;
  685. break;
  686. default:
  687. llstk[--llcstp] = 1;
  688. goto failed1;
  689. failed2:
  690. LLDEBUG_BACKTRACKING("union");
  691. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  692. llcpos = llpos1; llcstp = llstp1;
  693. continue;
  694. } break;
  695. }}
  696. LLDEBUG_LEAVE("union", 1);
  697. return 1;
  698. failed1: LLDEBUG_LEAVE("union", 0);
  699. return 0;
  700. }
  701. int ll_state(LLSTATE *llin, LLSTATE *llout)
  702. {
  703. unsigned llstp = llcstp;
  704. LLSTATE llstate_0;
  705. LLDEBUG_ENTER("state");
  706. llstate_0 = *llin;
  707. #undef failed
  708. #define failed failed1
  709. #line 181 "parser.ll"
  710. {if (usetypes) {
  711. incput("typedef %sPOS %sPOS;\n", USETYPES, LL);
  712. incput("typedef %sSTATE %sSTATE;\n", USETYPES, LL);
  713. } else {
  714. incput("typedef struct %sPOS {\n", LL);
  715. incput("\tint line;\n");
  716. incput("\tint column;\n");
  717. incput("\tchar *file;\n");
  718. incput("} %sPOS;\n", LL);
  719. incput("typedef struct %sSTATE {\n", LL);
  720. incput("\t%sPOS pos;\n", LL);
  721. }
  722. #line 764 "parser.c"
  723. {LLSTATE llstate_1;
  724. if (!ll_state1(&llstate_0, &llstate_1)) goto failed1;
  725. *llout = llstate_1;
  726. #line 195 "parser.ll"
  727. {if (!usetypes) incput("} %sSTATE;\n", LL);
  728. #line 770 "parser.c"
  729. }}}
  730. LLDEBUG_LEAVE("state", 1);
  731. return 1;
  732. failed1: LLDEBUG_LEAVE("state", 0);
  733. return 0;
  734. }
  735. int ll_state1(LLSTATE *llin, LLSTATE *llout)
  736. {
  737. unsigned llstp = llcstp;
  738. LLSTATE llstate_0;
  739. LLDEBUG_ENTER("state1");
  740. llstate_0 = *llin;
  741. #undef failed
  742. #define failed failed1
  743. #undef failed
  744. #define failed failed2
  745. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  746. LLCHECKSTK;
  747. for (;;) {
  748. switch (llstk[llcstp++]) {
  749. case 1: case -1:
  750. LLDEBUG_ALTERNATIVE("state1", 1);
  751. {LLSTATE llstate_1;string llatt_1;
  752. if (!llterm(TAGDEF, &lllval, &llstate_0, &llstate_1)) goto failed2;
  753. llatt_1 = lllval._string;
  754. {LLSTATE llstate_2;
  755. if (!llterm(';', (LLSTYPE *)0, &llstate_1, &llstate_2)) goto failed2;
  756. #line 199 "parser.ll"
  757. {if (!usetypes) incput("\t%s;\n", llatt_1);
  758. #line 802 "parser.c"
  759. {LLSTATE llstate_3;
  760. if (!ll_state1(&llstate_2, &llstate_3)) goto failed2;
  761. *llout = llstate_3;
  762. break;
  763. }}}}
  764. case 2: case -2:
  765. LLDEBUG_ALTERNATIVE("state1", 2);
  766. *llout = llstate_0;
  767. break;
  768. default:
  769. llstk[--llcstp] = 1;
  770. goto failed1;
  771. failed2:
  772. LLDEBUG_BACKTRACKING("state1");
  773. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  774. llcpos = llpos1; llcstp = llstp1;
  775. continue;
  776. } break;
  777. }}
  778. LLDEBUG_LEAVE("state1", 1);
  779. return 1;
  780. failed1: LLDEBUG_LEAVE("state1", 0);
  781. return 0;
  782. }
  783. int ll_rulesect(LLSTATE *llin, LLSTATE *llout)
  784. {
  785. unsigned llstp = llcstp;
  786. LLSTATE llstate_0;
  787. LLDEBUG_ENTER("rulesect");
  788. llstate_0 = *llin;
  789. #undef failed
  790. #define failed failed1
  791. #undef failed
  792. #define failed failed2
  793. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  794. LLCHECKSTK;
  795. for (;;) {
  796. switch (llstk[llcstp++]) {
  797. case 1: case -1:
  798. LLDEBUG_ALTERNATIVE("rulesect", 1);
  799. {LLSTATE llstate_1;
  800. if (!ll_rule(&llstate_0, &llstate_1)) goto failed2;
  801. {LLSTATE llstate_2;
  802. if (!ll_rulesect(&llstate_1, &llstate_2)) goto failed2;
  803. *llout = llstate_2;
  804. break;
  805. }}
  806. case 2: case -2:
  807. LLDEBUG_ALTERNATIVE("rulesect", 2);
  808. *llout = llstate_0;
  809. break;
  810. default:
  811. llstk[--llcstp] = 1;
  812. goto failed1;
  813. failed2:
  814. LLDEBUG_BACKTRACKING("rulesect");
  815. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  816. llcpos = llpos1; llcstp = llstp1;
  817. continue;
  818. } break;
  819. }}
  820. LLDEBUG_LEAVE("rulesect", 1);
  821. return 1;
  822. failed1: LLDEBUG_LEAVE("rulesect", 0);
  823. return 0;
  824. }
  825. int ll_rule(LLSTATE *llin, LLSTATE *llout)
  826. {
  827. unsigned llstp = llcstp;
  828. LLSTATE llstate_0;
  829. LLDEBUG_ENTER("rule");
  830. llstate_0 = *llin;
  831. #undef failed
  832. #define failed failed1
  833. {LLSTATE llstate_1;lhs llatt_1;
  834. if (!ll_lhs(&llatt_1, &llstate_0, &llstate_1)) goto failed1;
  835. {LLSTATE llstate_2;rhs llatt_2;
  836. if (!ll_rhss(&llatt_2, &llstate_1, &llstate_2)) goto failed1;
  837. {LLSTATE llstate_3;
  838. if (!llterm(';', (LLSTYPE *)0, &llstate_2, &llstate_3)) goto failed1;
  839. *llout = llstate_3;
  840. #line 211 "parser.ll"
  841. {item_t *item = find_symbol(llatt_1.identifier);
  842. /* XXX check llatt_1.args against item */
  843. if (!item)
  844. item = create_symbol(1, 0, NULL, llatt_1.identifier,
  845. NULL, NULL);
  846. if (item->tag) {
  847. if (llatt_1.args) {
  848. output("int %s_%s(%s *%sret, %s%sSTATE *%sin, %sSTATE *%sout, %s)\n",
  849. ll, llatt_1.identifier, item->tag, ll, conststr, LL,
  850. ll, LL, ll, llatt_1.args);
  851. incput("int %s_%s(%s *%sret, %s%sSTATE *%sin, %sSTATE *%sout, %s);\n",
  852. ll, llatt_1.identifier, item->tag, ll, conststr, LL,
  853. ll, LL, ll, llatt_1.args);
  854. } else {
  855. output("int %s_%s(%s *%sret, %s%sSTATE *%sin, %sSTATE *%sout)\n",
  856. ll, llatt_1.identifier, item->tag, ll, conststr, LL,
  857. ll, LL, ll);
  858. incput("int %s_%s(%s *%sret, %s%sSTATE *%sin, %sSTATE *%sout);\n",
  859. ll, llatt_1.identifier, item->tag, ll, conststr, LL,
  860. ll, LL, ll);
  861. }
  862. } else {
  863. if (llatt_1.args) {
  864. output("int %s_%s(%s%sSTATE *%sin, %sSTATE *%sout, %s)\n",
  865. ll, llatt_1.identifier, conststr, LL,
  866. ll, LL, ll, llatt_1.args);
  867. incput("int %s_%s(%s%sSTATE *%sin, %sSTATE *%sout, %s);\n",
  868. ll, llatt_1.identifier, conststr, LL,
  869. ll, LL, ll, llatt_1.args);
  870. } else {
  871. output("int %s_%s(%s%sSTATE *%sin, %sSTATE *%sout)\n",
  872. ll, llatt_1.identifier, conststr, LL,
  873. ll, LL, ll);
  874. incput("int %s_%s(%s%sSTATE *%sin, %sSTATE *%sout);\n",
  875. ll, llatt_1.identifier, conststr, LL,
  876. ll, LL, ll);
  877. }
  878. }
  879. output("{\n");
  880. output("unsigned %sstp = %scstp;\n", ll, ll);
  881. output_rhs(llatt_1.identifier, llatt_2);
  882. output("}\n");
  883. output("\n");
  884. add_rules(item, llatt_2);
  885. #line 934 "parser.c"
  886. }}}}
  887. LLDEBUG_LEAVE("rule", 1);
  888. return 1;
  889. failed1: LLDEBUG_LEAVE("rule", 0);
  890. return 0;
  891. }
  892. int ll_lhs(lhs *llret, LLSTATE *llin, LLSTATE *llout)
  893. {
  894. unsigned llstp = llcstp;
  895. LLSTATE llstate_0;
  896. LLDEBUG_ENTER("lhs");
  897. llstate_0 = *llin;
  898. #undef failed
  899. #define failed failed1
  900. {LLSTATE llstate_1;string llatt_1;
  901. if (!llterm(IDENTIFIER, &lllval, &llstate_0, &llstate_1)) goto failed1;
  902. llatt_1 = lllval._string;
  903. {LLSTATE llstate_2;string llatt_2;
  904. if (!ll_lhsargs(&llatt_2, &llstate_1, &llstate_2, llatt_1)) goto failed1;
  905. {LLSTATE llstate_3;
  906. if (!llterm(':', (LLSTYPE *)0, &llstate_2, &llstate_3)) goto failed1;
  907. *llout = llstate_3;
  908. #line 259 "parser.ll"
  909. {(*llret).identifier = llatt_1; (*llret).args = llatt_2;
  910. #line 961 "parser.c"
  911. }}}}
  912. LLDEBUG_LEAVE("lhs", 1);
  913. return 1;
  914. failed1: LLDEBUG_LEAVE("lhs", 0);
  915. return 0;
  916. }
  917. int ll_rhss(rhs *llret, LLSTATE *llin, LLSTATE *llout)
  918. {
  919. unsigned llstp = llcstp;
  920. LLSTATE llstate_0;
  921. LLDEBUG_ENTER("rhss");
  922. llstate_0 = *llin;
  923. #undef failed
  924. #define failed failed1
  925. {LLSTATE llstate_1;rhs llatt_1;
  926. if (!ll_items(&llatt_1, &llstate_0, &llstate_1)) goto failed1;
  927. {LLSTATE llstate_2;rhs llatt_2;
  928. if (!ll_rhss2(&llatt_2, &llstate_1, &llstate_2)) goto failed1;
  929. *llout = llstate_2;
  930. #line 263 "parser.ll"
  931. {(*llret) = (struct rhs_s *)malloc(sizeof(struct rhs_s));
  932. (*llret)->type = eAlternative;
  933. (*llret)->u.alternative.element = llatt_1;
  934. (*llret)->u.alternative.next = llatt_2;
  935. #line 989 "parser.c"
  936. }}}
  937. LLDEBUG_LEAVE("rhss", 1);
  938. return 1;
  939. failed1: LLDEBUG_LEAVE("rhss", 0);
  940. return 0;
  941. }
  942. int ll_rhss2(rhs *llret, LLSTATE *llin, LLSTATE *llout)
  943. {
  944. unsigned llstp = llcstp;
  945. LLSTATE llstate_0;
  946. LLDEBUG_ENTER("rhss2");
  947. llstate_0 = *llin;
  948. #undef failed
  949. #define failed failed1
  950. #undef failed
  951. #define failed failed2
  952. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  953. LLCHECKSTK;
  954. for (;;) {
  955. switch (llstk[llcstp++]) {
  956. case 1: case -1:
  957. LLDEBUG_ALTERNATIVE("rhss2", 1);
  958. {LLSTATE llstate_1;
  959. if (!llterm('|', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  960. {LLSTATE llstate_2;rhs llatt_2;
  961. if (!ll_items(&llatt_2, &llstate_1, &llstate_2)) goto failed2;
  962. {LLSTATE llstate_3;rhs llatt_3;
  963. if (!ll_rhss2(&llatt_3, &llstate_2, &llstate_3)) goto failed2;
  964. *llout = llstate_3;
  965. #line 271 "parser.ll"
  966. {(*llret) = (struct rhs_s *)malloc(sizeof(struct rhs_s));
  967. (*llret)->type = eAlternative;
  968. (*llret)->u.alternative.element = llatt_2;
  969. (*llret)->u.alternative.next = llatt_3;
  970. #line 1027 "parser.c"
  971. break;
  972. }}}}
  973. case 2: case -2:
  974. LLDEBUG_ALTERNATIVE("rhss2", 2);
  975. *llout = llstate_0;
  976. #line 277 "parser.ll"
  977. {(*llret) = NULL;
  978. #line 1035 "parser.c"
  979. break;
  980. }
  981. default:
  982. llstk[--llcstp] = 1;
  983. goto failed1;
  984. failed2:
  985. LLDEBUG_BACKTRACKING("rhss2");
  986. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  987. llcpos = llpos1; llcstp = llstp1;
  988. continue;
  989. } break;
  990. }}
  991. LLDEBUG_LEAVE("rhss2", 1);
  992. return 1;
  993. failed1: LLDEBUG_LEAVE("rhss2", 0);
  994. return 0;
  995. }
  996. int ll_items(rhs *llret, LLSTATE *llin, LLSTATE *llout)
  997. {
  998. unsigned llstp = llcstp;
  999. LLSTATE llstate_0;
  1000. LLDEBUG_ENTER("items");
  1001. llstate_0 = *llin;
  1002. #undef failed
  1003. #define failed failed1
  1004. #undef failed
  1005. #define failed failed2
  1006. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  1007. LLCHECKSTK;
  1008. for (;;) {
  1009. switch (llstk[llcstp++]) {
  1010. case 1: case -1:
  1011. LLDEBUG_ALTERNATIVE("items", 1);
  1012. {LLSTATE llstate_1;rhs llatt_1;
  1013. if (!ll_item(&llatt_1, &llstate_0, &llstate_1)) goto failed2;
  1014. {LLSTATE llstate_2;bounds llatt_2;
  1015. if (!ll_extension(&llatt_2, &llstate_1, &llstate_2)) goto failed2;
  1016. {LLSTATE llstate_3;rhs llatt_3;
  1017. if (!ll_items(&llatt_3, &llstate_2, &llstate_3)) goto failed2;
  1018. *llout = llstate_3;
  1019. #line 281 "parser.ll"
  1020. {(*llret) = (struct rhs_s *)malloc(sizeof(struct rhs_s));
  1021. (*llret)->type = eSequence;
  1022. if (llatt_2.lower != 1 || llatt_2.upper != 1) {
  1023. (*llret)->u.sequence.element =
  1024. (struct rhs_s *)malloc(sizeof(struct rhs_s));
  1025. (*llret)->u.sequence.element->type = eBounded;
  1026. (*llret)->u.sequence.element->u.bounded.items = llatt_1;
  1027. (*llret)->u.sequence.element->u.bounded.bounds = llatt_2;
  1028. } else {
  1029. (*llret)->u.sequence.element = llatt_1;
  1030. }
  1031. (*llret)->u.sequence.next = llatt_3;
  1032. #line 1092 "parser.c"
  1033. break;
  1034. }}}}
  1035. case 2: case -2:
  1036. LLDEBUG_ALTERNATIVE("items", 2);
  1037. *llout = llstate_0;
  1038. #line 295 "parser.ll"
  1039. {(*llret) = NULL;
  1040. #line 1100 "parser.c"
  1041. break;
  1042. }
  1043. default:
  1044. llstk[--llcstp] = 1;
  1045. goto failed1;
  1046. failed2:
  1047. LLDEBUG_BACKTRACKING("items");
  1048. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  1049. llcpos = llpos1; llcstp = llstp1;
  1050. continue;
  1051. } break;
  1052. }}
  1053. LLDEBUG_LEAVE("items", 1);
  1054. return 1;
  1055. failed1: LLDEBUG_LEAVE("items", 0);
  1056. return 0;
  1057. }
  1058. int ll_item(rhs *llret, LLSTATE *llin, LLSTATE *llout)
  1059. {
  1060. unsigned llstp = llcstp;
  1061. LLSTATE llstate_0;
  1062. LLDEBUG_ENTER("item");
  1063. llstate_0 = *llin;
  1064. #undef failed
  1065. #define failed failed1
  1066. #undef failed
  1067. #define failed failed2
  1068. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  1069. LLCHECKSTK;
  1070. for (;;) {
  1071. switch (llstk[llcstp++]) {
  1072. case 1: case -1:
  1073. LLDEBUG_ALTERNATIVE("item", 1);
  1074. {LLSTATE llstate_1;string llatt_1;
  1075. if (!llterm(IDENTIFIER, &lllval, &llstate_0, &llstate_1)) goto failed2;
  1076. llatt_1 = lllval._string;
  1077. {LLSTATE llstate_2;string llatt_2;
  1078. if (!ll_args(&llatt_2, &llstate_1, &llstate_2)) goto failed2;
  1079. *llout = llstate_2;
  1080. #line 299 "parser.ll"
  1081. {(*llret) = (struct rhs_s *)malloc(sizeof(struct rhs_s));
  1082. (*llret)->type = eItem;
  1083. (*llret)->u.item.identifier = llatt_1;
  1084. (*llret)->u.item.args = llatt_2;
  1085. #line 1148 "parser.c"
  1086. break;
  1087. }}}
  1088. case 2: case -2:
  1089. LLDEBUG_ALTERNATIVE("item", 2);
  1090. {LLSTATE llstate_1;
  1091. if (!llterm('[', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  1092. {LLSTATE llstate_2;rhs llatt_2;
  1093. if (!ll_rhss(&llatt_2, &llstate_1, &llstate_2)) goto failed2;
  1094. {LLSTATE llstate_3;
  1095. if (!llterm(']', (LLSTYPE *)0, &llstate_2, &llstate_3)) goto failed2;
  1096. *llout = llstate_3;
  1097. #line 305 "parser.ll"
  1098. {(*llret) = llatt_2;
  1099. #line 1163 "parser.c"
  1100. break;
  1101. }}}}
  1102. case 3: case -3:
  1103. LLDEBUG_ALTERNATIVE("item", 3);
  1104. {LLSTATE llstate_1;
  1105. if (!llterm('[', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  1106. {LLSTATE llstate_2;rhs llatt_2;
  1107. if (!ll_rhss(&llatt_2, &llstate_1, &llstate_2)) goto failed2;
  1108. {LLSTATE llstate_3;
  1109. if (!llterm(':', (LLSTYPE *)0, &llstate_2, &llstate_3)) goto failed2;
  1110. {LLSTATE llstate_4;rhs llatt_4;
  1111. if (!ll_rhss(&llatt_4, &llstate_3, &llstate_4)) goto failed2;
  1112. {LLSTATE llstate_5;
  1113. if (!llterm(']', (LLSTYPE *)0, &llstate_4, &llstate_5)) goto failed2;
  1114. *llout = llstate_5;
  1115. #line 308 "parser.ll"
  1116. {(*llret) = (struct rhs_s *)malloc(sizeof(struct rhs_s));
  1117. (*llret)->type = eNode;
  1118. (*llret)->u.node.left = llatt_2;
  1119. (*llret)->u.node.right = llatt_4;
  1120. #line 1185 "parser.c"
  1121. break;
  1122. }}}}}}
  1123. case 4: case -4:
  1124. LLDEBUG_ALTERNATIVE("item", 4);
  1125. {LLSTATE llstate_1;
  1126. if (!llterm('{', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  1127. {LLSTATE llstate_2;ccode llatt_2;
  1128. if (!llterm(CCODE, &lllval, &llstate_1, &llstate_2)) goto failed2;
  1129. llatt_2 = lllval._ccode;
  1130. {LLSTATE llstate_3;
  1131. if (!llterm('}', (LLSTYPE *)0, &llstate_2, &llstate_3)) goto failed2;
  1132. *llout = llstate_3;
  1133. #line 314 "parser.ll"
  1134. {(*llret) = (struct rhs_s *)malloc(sizeof(struct rhs_s));
  1135. (*llret)->type = eCCode;
  1136. (*llret)->u.ccode.ccode = llatt_2;
  1137. (*llret)->u.ccode.line = llstate_2.pos.line;
  1138. (*llret)->u.ccode.column = llstate_2.pos.column;
  1139. (*llret)->u.ccode.file = llstate_2.pos.file;
  1140. #line 1206 "parser.c"
  1141. break;
  1142. }}}}
  1143. default:
  1144. llstk[--llcstp] = 1;
  1145. goto failed1;
  1146. failed2:
  1147. LLDEBUG_BACKTRACKING("item");
  1148. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  1149. llcpos = llpos1; llcstp = llstp1;
  1150. continue;
  1151. } break;
  1152. }}
  1153. LLDEBUG_LEAVE("item", 1);
  1154. return 1;
  1155. failed1: LLDEBUG_LEAVE("item", 0);
  1156. return 0;
  1157. }
  1158. int ll_extension(bounds *llret, LLSTATE *llin, LLSTATE *llout)
  1159. {
  1160. unsigned llstp = llcstp;
  1161. LLSTATE llstate_0;
  1162. LLDEBUG_ENTER("extension");
  1163. llstate_0 = *llin;
  1164. #undef failed
  1165. #define failed failed1
  1166. #undef failed
  1167. #define failed failed2
  1168. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  1169. LLCHECKSTK;
  1170. for (;;) {
  1171. switch (llstk[llcstp++]) {
  1172. case 1: case -1:
  1173. LLDEBUG_ALTERNATIVE("extension", 1);
  1174. {LLSTATE llstate_1;
  1175. if (!llterm('+', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  1176. *llout = llstate_1;
  1177. #line 324 "parser.ll"
  1178. {(*llret).lower = 1;
  1179. (*llret).upper = 0;
  1180. #line 1249 "parser.c"
  1181. break;
  1182. }}
  1183. case 2: case -2:
  1184. LLDEBUG_ALTERNATIVE("extension", 2);
  1185. {LLSTATE llstate_1;
  1186. if (!llterm('*', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  1187. *llout = llstate_1;
  1188. #line 328 "parser.ll"
  1189. {(*llret).lower = 0;
  1190. (*llret).upper = 0;
  1191. #line 1261 "parser.c"
  1192. break;
  1193. }}
  1194. case 3: case -3:
  1195. LLDEBUG_ALTERNATIVE("extension", 3);
  1196. {LLSTATE llstate_1;
  1197. if (!llterm('?', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  1198. *llout = llstate_1;
  1199. #line 332 "parser.ll"
  1200. {(*llret).lower = 0;
  1201. (*llret).upper = 1;
  1202. #line 1273 "parser.c"
  1203. break;
  1204. }}
  1205. case 4: case -4:
  1206. LLDEBUG_ALTERNATIVE("extension", 4);
  1207. *llout = llstate_0;
  1208. #line 336 "parser.ll"
  1209. {(*llret).lower = 1;
  1210. (*llret).upper = 1;
  1211. #line 1283 "parser.c"
  1212. break;
  1213. }
  1214. default:
  1215. llstk[--llcstp] = 1;
  1216. goto failed1;
  1217. failed2:
  1218. LLDEBUG_BACKTRACKING("extension");
  1219. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  1220. llcpos = llpos1; llcstp = llstp1;
  1221. continue;
  1222. } break;
  1223. }}
  1224. LLDEBUG_LEAVE("extension", 1);
  1225. return 1;
  1226. failed1: LLDEBUG_LEAVE("extension", 0);
  1227. return 0;
  1228. }
  1229. int ll_lhsargs(string *llret, LLSTATE *llin, LLSTATE *llout, string llarg_ide)
  1230. {
  1231. unsigned llstp = llcstp;
  1232. LLSTATE llstate_0;
  1233. LLDEBUG_ENTER("lhsargs");
  1234. llstate_0 = *llin;
  1235. #undef failed
  1236. #define failed failed1
  1237. #undef failed
  1238. #define failed failed2
  1239. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  1240. LLCHECKSTK;
  1241. for (;;) {
  1242. switch (llstk[llcstp++]) {
  1243. case 1: case -1:
  1244. LLDEBUG_ALTERNATIVE("lhsargs", 1);
  1245. {LLSTATE llstate_1;
  1246. if (!llterm('(', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  1247. #line 342 "parser.ll"
  1248. {item_t *item;
  1249. item = find_symbol(llarg_ide);
  1250. if (!item || !item->args || !*item->args) {
  1251. fprintf(stderr,
  1252. "%s has not been declared to have arguments\n",
  1253. llarg_ide);
  1254. exit(1);
  1255. }
  1256. #line 1331 "parser.c"
  1257. {LLSTATE llstate_2;string llatt_2;
  1258. if (!ll_lhsarglist(&llatt_2, &llstate_1, &llstate_2, item->args, llarg_ide)) goto failed2;
  1259. {LLSTATE llstate_3;
  1260. if (!llterm(')', (LLSTYPE *)0, &llstate_2, &llstate_3)) goto failed2;
  1261. *llout = llstate_3;
  1262. #line 352 "parser.ll"
  1263. {(*llret) = llatt_2;
  1264. #line 1339 "parser.c"
  1265. break;
  1266. }}}}}
  1267. case 2: case -2:
  1268. LLDEBUG_ALTERNATIVE("lhsargs", 2);
  1269. *llout = llstate_0;
  1270. #line 354 "parser.ll"
  1271. {item_t *item;
  1272. item = find_symbol(llarg_ide);
  1273. if (item && item->args && *item->args) {
  1274. fprintf(stderr,
  1275. "%s has not been declared to have no arguments\n",
  1276. llarg_ide);
  1277. exit(1);
  1278. }
  1279. (*llret) = NULL;
  1280. #line 1356 "parser.c"
  1281. break;
  1282. }
  1283. default:
  1284. llstk[--llcstp] = 1;
  1285. goto failed1;
  1286. failed2:
  1287. LLDEBUG_BACKTRACKING("lhsargs");
  1288. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  1289. llcpos = llpos1; llcstp = llstp1;
  1290. continue;
  1291. } break;
  1292. }}
  1293. LLDEBUG_LEAVE("lhsargs", 1);
  1294. return 1;
  1295. failed1: LLDEBUG_LEAVE("lhsargs", 0);
  1296. return 0;
  1297. }
  1298. int ll_lhsarglist(string *llret, LLSTATE *llin, LLSTATE *llout, strings llarg_tags, string llarg_ide)
  1299. {
  1300. unsigned llstp = llcstp;
  1301. LLSTATE llstate_0;
  1302. LLDEBUG_ENTER("lhsarglist");
  1303. llstate_0 = *llin;
  1304. #undef failed
  1305. #define failed failed1
  1306. #undef failed
  1307. #define failed failed2
  1308. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  1309. LLCHECKSTK;
  1310. for (;;) {
  1311. switch (llstk[llcstp++]) {
  1312. case 1: case -1:
  1313. LLDEBUG_ALTERNATIVE("lhsarglist", 1);
  1314. {LLSTATE llstate_1;string llatt_1;
  1315. if (!llterm(ARG, &lllval, &llstate_0, &llstate_1)) goto failed2;
  1316. llatt_1 = lllval._string;
  1317. {LLSTATE llstate_2;
  1318. if (!llterm(',', (LLSTYPE *)0, &llstate_1, &llstate_2)) goto failed2;
  1319. {LLSTATE llstate_3;string llatt_3;
  1320. if (!ll_lhsarglist(&llatt_3, &llstate_2, &llstate_3, llarg_tags+1, llarg_ide)) goto failed2;
  1321. *llout = llstate_3;
  1322. #line 367 "parser.ll"
  1323. {if (!*llarg_tags) {
  1324. fprintf(stderr,
  1325. "%s has not been declared to have so much arguments\n",
  1326. llarg_ide);
  1327. exit(1);
  1328. }
  1329. (*llret) = (char *)malloc(strlen(llatt_1) + strlen(llatt_3) +
  1330. strlen(*llarg_tags) + strlen(conststr) + 10);
  1331. sprintf((*llret), "%s%s %sarg_%s, %s",
  1332. conststr, *llarg_tags, ll, llatt_1, llatt_3);
  1333. #line 1412 "parser.c"
  1334. break;
  1335. }}}}
  1336. case 2: case -2:
  1337. LLDEBUG_ALTERNATIVE("lhsarglist", 2);
  1338. {LLSTATE llstate_1;string llatt_1;
  1339. if (!llterm(ARG, &lllval, &llstate_0, &llstate_1)) goto failed2;
  1340. llatt_1 = lllval._string;
  1341. *llout = llstate_1;
  1342. #line 379 "parser.ll"
  1343. {if (!*llarg_tags) {
  1344. fprintf(stderr,
  1345. "%s has not been declared to have so much arguments\n",
  1346. llarg_ide);
  1347. exit(1);
  1348. }
  1349. if (llarg_tags[1]) {
  1350. fprintf(stderr,
  1351. "%s has not been declared to have so less arguments\n",
  1352. llarg_ide);
  1353. exit(1);
  1354. }
  1355. (*llret) = (char *)malloc(strlen(llatt_1) + strlen(*llarg_tags) +
  1356. strlen(conststr) + 8);
  1357. sprintf((*llret), "%s%s %sarg_%s", conststr, *llarg_tags, ll, llatt_1);
  1358. #line 1438 "parser.c"
  1359. break;
  1360. }}
  1361. default:
  1362. llstk[--llcstp] = 1;
  1363. goto failed1;
  1364. failed2:
  1365. LLDEBUG_BACKTRACKING("lhsarglist");
  1366. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  1367. llcpos = llpos1; llcstp = llstp1;
  1368. continue;
  1369. } break;
  1370. }}
  1371. LLDEBUG_LEAVE("lhsarglist", 1);
  1372. return 1;
  1373. failed1: LLDEBUG_LEAVE("lhsarglist", 0);
  1374. return 0;
  1375. }
  1376. int ll_args(string *llret, LLSTATE *llin, LLSTATE *llout)
  1377. {
  1378. unsigned llstp = llcstp;
  1379. LLSTATE llstate_0;
  1380. LLDEBUG_ENTER("args");
  1381. llstate_0 = *llin;
  1382. #undef failed
  1383. #define failed failed1
  1384. #undef failed
  1385. #define failed failed2
  1386. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  1387. LLCHECKSTK;
  1388. for (;;) {
  1389. switch (llstk[llcstp++]) {
  1390. case 1: case -1:
  1391. LLDEBUG_ALTERNATIVE("args", 1);
  1392. {LLSTATE llstate_1;
  1393. if (!llterm('(', (LLSTYPE *)0, &llstate_0, &llstate_1)) goto failed2;
  1394. {LLSTATE llstate_2;string llatt_2;
  1395. if (!ll_arglist(&llatt_2, &llstate_1, &llstate_2)) goto failed2;
  1396. {LLSTATE llstate_3;
  1397. if (!llterm(')', (LLSTYPE *)0, &llstate_2, &llstate_3)) goto failed2;
  1398. *llout = llstate_3;
  1399. #line 398 "parser.ll"
  1400. {(*llret) = llatt_2;
  1401. #line 1483 "parser.c"
  1402. break;
  1403. }}}}
  1404. case 2: case -2:
  1405. LLDEBUG_ALTERNATIVE("args", 2);
  1406. *llout = llstate_0;
  1407. #line 400 "parser.ll"
  1408. {(*llret) = "";
  1409. #line 1491 "parser.c"
  1410. break;
  1411. }
  1412. default:
  1413. llstk[--llcstp] = 1;
  1414. goto failed1;
  1415. failed2:
  1416. LLDEBUG_BACKTRACKING("args");
  1417. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  1418. llcpos = llpos1; llcstp = llstp1;
  1419. continue;
  1420. } break;
  1421. }}
  1422. LLDEBUG_LEAVE("args", 1);
  1423. return 1;
  1424. failed1: LLDEBUG_LEAVE("args", 0);
  1425. return 0;
  1426. }
  1427. int ll_arglist(string *llret, LLSTATE *llin, LLSTATE *llout)
  1428. {
  1429. unsigned llstp = llcstp;
  1430. LLSTATE llstate_0;
  1431. LLDEBUG_ENTER("arglist");
  1432. llstate_0 = *llin;
  1433. #undef failed
  1434. #define failed failed1
  1435. #undef failed
  1436. #define failed failed2
  1437. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  1438. LLCHECKSTK;
  1439. for (;;) {
  1440. switch (llstk[llcstp++]) {
  1441. case 1: case -1:
  1442. LLDEBUG_ALTERNATIVE("arglist", 1);
  1443. {LLSTATE llstate_1;string llatt_1;
  1444. if (!llterm(ARG, &lllval, &llstate_0, &llstate_1)) goto failed2;
  1445. llatt_1 = lllval._string;
  1446. {LLSTATE llstate_2;
  1447. if (!llterm(',', (LLSTYPE *)0, &llstate_1, &llstate_2)) goto failed2;
  1448. {LLSTATE llstate_3;string llatt_3;
  1449. if (!ll_arglist(&llatt_3, &llstate_2, &llstate_3)) goto failed2;
  1450. *llout = llstate_3;
  1451. #line 404 "parser.ll"
  1452. {char *p = convert(llatt_1);
  1453. (*llret) = (char *)malloc(strlen(p) + strlen(llatt_3) + 3);
  1454. strcpy((*llret), p);
  1455. strcat((*llret), ", ");
  1456. strcat((*llret), llatt_3);
  1457. #line 1542 "parser.c"
  1458. break;
  1459. }}}}
  1460. case 2: case -2:
  1461. LLDEBUG_ALTERNATIVE("arglist", 2);
  1462. {LLSTATE llstate_1;string llatt_1;
  1463. if (!llterm(ARG, &lllval, &llstate_0, &llstate_1)) goto failed2;
  1464. llatt_1 = lllval._string;
  1465. *llout = llstate_1;
  1466. #line 411 "parser.ll"
  1467. {(*llret) = convert(llatt_1);
  1468. #line 1553 "parser.c"
  1469. break;
  1470. }}
  1471. default:
  1472. llstk[--llcstp] = 1;
  1473. goto failed1;
  1474. failed2:
  1475. LLDEBUG_BACKTRACKING("arglist");
  1476. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  1477. llcpos = llpos1; llcstp = llstp1;
  1478. continue;
  1479. } break;
  1480. }}
  1481. LLDEBUG_LEAVE("arglist", 1);
  1482. return 1;
  1483. failed1: LLDEBUG_LEAVE("arglist", 0);
  1484. return 0;
  1485. }
  1486. int ll_csect(LLSTATE *llin, LLSTATE *llout)
  1487. {
  1488. unsigned llstp = llcstp;
  1489. LLSTATE llstate_0;
  1490. LLDEBUG_ENTER("csect");
  1491. llstate_0 = *llin;
  1492. #undef failed
  1493. #define failed failed1
  1494. #undef failed
  1495. #define failed failed2
  1496. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  1497. LLCHECKSTK;
  1498. for (;;) {
  1499. switch (llstk[llcstp++]) {
  1500. case 1: case -1:
  1501. LLDEBUG_ALTERNATIVE("csect", 1);
  1502. {LLSTATE llstate_1;ccode llatt_1;
  1503. if (!llterm(CCODE, &lllval, &llstate_0, &llstate_1)) goto failed2;
  1504. llatt_1 = lllval._ccode;
  1505. *llout = llstate_1;
  1506. #line 417 "parser.ll"
  1507. {if (linedirective)
  1508. output("#line %d \"%s\"\n", llstate_1.pos.line, llstate_1.pos.file);
  1509. output("%s\n", llatt_1);
  1510. if (linedirective)
  1511. output_line();
  1512. #line 1600 "parser.c"
  1513. break;
  1514. }}
  1515. case 2: case -2:
  1516. LLDEBUG_ALTERNATIVE("csect", 2);
  1517. *llout = llstate_0;
  1518. break;
  1519. default:
  1520. llstk[--llcstp] = 1;
  1521. goto failed1;
  1522. failed2:
  1523. LLDEBUG_BACKTRACKING("csect");
  1524. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  1525. llcpos = llpos1; llcstp = llstp1;
  1526. continue;
  1527. } break;
  1528. }}
  1529. LLDEBUG_LEAVE("csect", 1);
  1530. return 1;
  1531. failed1: LLDEBUG_LEAVE("csect", 0);
  1532. return 0;
  1533. }
  1534. #line 426 "parser.ll"
  1535. #line 1625 "parser.c"
  1536. int
  1537. llparser(LLTERM *tokens, unsigned ntokens, LLSTATE *llin, LLSTATE *llout)
  1538. {
  1539. unsigned i;
  1540. LLDEBUG_ENTER("llparser");
  1541. lltokens = tokens; llntokens = ntokens;
  1542. for (i = 0; i < llstksize; i++) llstk[i] = 1;
  1543. llcstp = 1; llcpos = 0; llepos = 0; *llerrormsg = 0;
  1544. #if LLDEBUG > 0
  1545. last_linenr = 0; last_file = "";
  1546. #endif
  1547. {unsigned llpos1 = llcpos, llstp1 = llcstp;
  1548. LLCHECKSTK;
  1549. for (;;) {
  1550. switch (llstk[llcstp++]) {
  1551. case 1: case -1:
  1552. if (!ll_main(llin, llout)) goto failed2;
  1553. if (llcpos != llntokens) goto failed2;
  1554. break;
  1555. default:
  1556. llstk[--llcstp] = 1;
  1557. goto failed1;
  1558. failed2:
  1559. LLDEBUG_BACKTRACKING("llparser");
  1560. if (llstk[--llcstp] < 0) llstk[llcstp] = 0; else llstk[llcstp]++;
  1561. llcpos = llpos1; llcstp = llstp1;
  1562. continue;
  1563. } break;
  1564. }}
  1565. LLDEBUG_LEAVE("llparser", 1);
  1566. return 1;
  1567. failed1:
  1568. LLDEBUG_LEAVE("llparser", 0);
  1569. return 0;
  1570. }
  1571. int
  1572. llterm(int token, LLSTYPE *lval, LLSTATE *llin, LLSTATE *llout)
  1573. {
  1574. #if LLDEBUG > 0
  1575. if (lldebug > 0 && (lltokens[llcpos].pos.line > last_linenr || strcmp(lltokens[llcpos].pos.file, last_file))) {
  1576. fprintf(stderr, "File \"%s\", Line %5d \r",
  1577. lltokens[llcpos].pos.file, lltokens[llcpos].pos.line);
  1578. last_linenr = lltokens[llcpos].pos.line / 10 * 10 + 9;
  1579. last_file = lltokens[llcpos].pos.file;
  1580. }
  1581. #endif
  1582. if (llstk[llcstp] != 1 && llstk[llcstp] != -1) {
  1583. LLDEBUG_BACKTRACKING("llterm");
  1584. llstk[llcstp] = 1;
  1585. return 0;
  1586. }
  1587. LLDEBUG_TOKEN(token, llcpos);
  1588. if (llcpos < llntokens && lltokens[llcpos].token == token) {
  1589. if (lval)
  1590. *lval = lltokens[llcpos].lval;
  1591. *llout = *llin;
  1592. llout->pos = lltokens[llcpos].pos;
  1593. llcpos++;
  1594. LLCHECKSTK;
  1595. llcstp++;
  1596. return 1;
  1597. }
  1598. llfailed(&lltokens[llcpos].pos, NULL);
  1599. llstk[llcstp] = 1;
  1600. return 0;
  1601. }
  1602. int
  1603. llanyterm(LLSTYPE *lval, LLSTATE *llin, LLSTATE *llout)
  1604. {
  1605. #if LLDEBUG > 0
  1606. if (lldebug > 0 && (lltokens[llcpos].pos.line > last_linenr || strcmp(lltokens[llcpos].pos.file, last_file))) {
  1607. fprintf(stderr, "File \"%s\", Line %5d \r",
  1608. lltokens[llcpos].pos.file, lltokens[llcpos].pos.line);
  1609. last_linenr = lltokens[llcpos].pos.line / 10 * 10 + 9;
  1610. last_file = lltokens[llcpos].pos.file;
  1611. }
  1612. #endif
  1613. if (llstk[llcstp] != 1 && llstk[llcstp] != -1) {
  1614. LLDEBUG_BACKTRACKING("llanyterm");
  1615. llstk[llcstp] = 1;
  1616. return 0;
  1617. }
  1618. LLDEBUG_ANYTOKEN(llcpos);
  1619. if (llcpos < llntokens) {
  1620. if (lval)
  1621. *lval = lltokens[llcpos].lval;
  1622. *llout = *llin;
  1623. llout->pos = lltokens[llcpos].pos;
  1624. llcpos++;
  1625. LLCHECKSTK;
  1626. llcstp++;
  1627. return 1;
  1628. }
  1629. llfailed(&lltokens[llcpos].pos, NULL);
  1630. llstk[llcstp] = 1;
  1631. return 0;
  1632. }
  1633. void
  1634. llscanner(LLTERM **tokens, unsigned *ntokens)
  1635. {
  1636. unsigned i = 0;
  1637. #if LLDEBUG > 0
  1638. int line = -1;
  1639. #endif
  1640. *ntokens = 1024;
  1641. *tokens = (LLTERM *)malloc(*ntokens * sizeof(LLTERM));
  1642. while (llgettoken(&(*tokens)[i].token, &(*tokens)[i].lval, &(*tokens)[i].pos)) {
  1643. #if LLDEBUG > 0
  1644. if (lldebug > 0 && (*tokens)[i].pos.line > line) {
  1645. line = (*tokens)[i].pos.line / 10 * 10 + 9;
  1646. fprintf(stderr, "File \"%s\", Line %5d \r",
  1647. (*tokens)[i].pos.file, (*tokens)[i].pos.line);
  1648. }
  1649. #endif
  1650. if (++i >= *ntokens) {
  1651. *ntokens *= 2;
  1652. *tokens = (LLTERM *)realloc(*tokens, *ntokens * sizeof(LLTERM));
  1653. }
  1654. }
  1655. (*tokens)[i].token = 0;
  1656. *ntokens = i;
  1657. #if LLDEBUG > 0
  1658. lldebug_init();
  1659. #endif
  1660. llresizestk();
  1661. }
  1662. void
  1663. llfailed(LLPOS *pos, char *fmt, ...)
  1664. {
  1665. va_list args;
  1666. va_start(args, fmt);
  1667. if (llcpos > llepos || llcpos == llepos && !*llerrormsg) {
  1668. llepos = llcpos;
  1669. if (fmt)
  1670. vsprintf(llerrormsg, fmt, args);
  1671. else
  1672. *llerrormsg = 0;
  1673. llerrorpos = *pos;
  1674. }
  1675. va_end(args);
  1676. }
  1677. void
  1678. llprinterror(FILE *f)
  1679. {
  1680. #if LLDEBUG > 0
  1681. fputs(" \r", stderr);
  1682. #endif
  1683. if (*llerrormsg)
  1684. llerror(f, &llerrorpos, llerrormsg);
  1685. else
  1686. llerror(f, &llerrorpos, "Syntax error");
  1687. }
  1688. void
  1689. llerror(FILE *f, LLPOS *pos, char *fmt, ...)
  1690. {
  1691. va_list args;
  1692. va_start(args, fmt);
  1693. llverror(f, pos, fmt, args);
  1694. va_end(args);
  1695. }
  1696. void
  1697. llresizestk()
  1698. {
  1699. unsigned i;
  1700. if (llcstp + 1 >= llstksize) {
  1701. i = llstksize;
  1702. if (!llstksize)
  1703. llstk = (int *)malloc((llstksize = 4096) * sizeof(int));
  1704. else
  1705. llstk = (int *)realloc(llstk, (llstksize *= 2) * sizeof(int));
  1706. for (; i < llstksize; i++)
  1707. llstk[i] = 1;
  1708. }
  1709. }
  1710. #if LLDEBUG > 0
  1711. int lldepth;
  1712. char *lltokentab[] = {
  1713. "EOF","#1","#2","#3","#4","#5","#6","#7"
  1714. ,"#8","#9","#10","#11","#12","#13","#14","#15"
  1715. ,"#16","#17","#18","#19","#20","#21","#22","#23"
  1716. ,"#24","#25","#26","#27","#28","#29","#30","#31"
  1717. ,"' '","'!'","'\"'","'#'","'$'","'%'","'&'","'''"
  1718. ,"'('","')'","'*'","'+'","','","'-'","'.'","'/'"
  1719. ,"'0'","'1'","'2'","'3'","'4'","'5'","'6'","'7'"
  1720. ,"'8'","'9'","':'","';'","'<'","'='","'>'","'?'"
  1721. ,"'@'","'A'","'B'","'C'","'D'","'E'","'F'","'G'"
  1722. ,"'H'","'I'","'J'","'K'","'L'","'M'","'N'","'O'"
  1723. ,"'P'","'Q'","'R'","'S'","'T'","'U'","'V'","'W'"
  1724. ,"'X'","'Y'","'Z'","'['","'\\'","']'","'^'","'_'"
  1725. ,"'`'","'a'","'b'","'c'","'d'","'e'","'f'","'g'"
  1726. ,"'h'","'i'","'j'","'k'","'l'","'m'","'n'","'o'"
  1727. ,"'p'","'q'","'r'","'s'","'t'","'u'","'v'","'w'"
  1728. ,"'x'","'y'","'z'","'{'","'|'","'}'","'~'","#127"
  1729. ,"#128","#129","#130","#131","#132","#133","#134","#135"
  1730. ,"#136","#137","#138","#139","#140","#141","#142","#143"
  1731. ,"#144","#145","#146","#147","#148","#149","#150","#151"
  1732. ,"#152","#153","#154","#155","#156","#157","#158","#159"
  1733. ,"#160","#161","#162","#163","#164","#165","#166","#167"
  1734. ,"#168","#169","#170","#171","#172","#173","#174","#175"
  1735. ,"#176","#177","#178","#179","#180","#181","#182","#183"
  1736. ,"#184","#185","#186","#187","#188","#189","#190","#191"
  1737. ,"#192","#193","#194","#195","#196","#197","#198","#199"
  1738. ,"#200","#201","#202","#203","#204","#205","#206","#207"
  1739. ,"#208","#209","#210","#211","#212","#213","#214","#215"
  1740. ,"#216","#217","#218","#219","#220","#221","#222","#223"
  1741. ,"#224","#225","#226","#227","#228","#229","#230","#231"
  1742. ,"#232","#233","#234","#235","#236","#237","#238","#239"
  1743. ,"#240","#241","#242","#243","#244","#245","#246","#247"
  1744. ,"#248","#249","#250","#251","#252","#253","#254","#255"
  1745. ,"#256","IDENTIFIER","ARG","CCODE","TAGDEF","PERCENT_PERCENT","PERCENT_TOKEN","PERCENT_TYPE"
  1746. ,"PERCENT_EXTERNAL","PERCENT_UNION","PERCENT_STATE","PERCENT_START","PERCENT_PREFIX","PERCENT_MODULE","PERCENT_LBRACE","PERCENT_RBRACE"
  1747. };
  1748. void
  1749. lldebug_init()
  1750. {
  1751. char *p;
  1752. p = getenv("LLDEBUG");
  1753. if (p)
  1754. lldebug = atoi(p);
  1755. }
  1756. void
  1757. lldebug_enter(char *ident)
  1758. {
  1759. int i;
  1760. if (lldebug < 2)
  1761. return;
  1762. for (i = 0; i < lldepth; i++)
  1763. fputs("| ", stdout);
  1764. printf("/--- trying rule %s\n", ident);
  1765. lldepth++;
  1766. }
  1767. void
  1768. lldebug_leave(char *ident, int succ)
  1769. {
  1770. int i;
  1771. if (lldebug < 2)
  1772. return;
  1773. lldepth--;
  1774. for (i = 0; i < lldepth; i++)
  1775. fputs("| ", stdout);
  1776. if (succ)
  1777. printf("\\--- succeeded to apply rule %s\n", ident);
  1778. else
  1779. printf("\\--- failed to apply rule %s\n", ident);
  1780. }
  1781. void
  1782. lldebug_alternative(char *ident, int alt)
  1783. {
  1784. int i;
  1785. if (lldebug < 2)
  1786. return;
  1787. for (i = 0; i < lldepth - 1; i++)
  1788. fputs("| ", stdout);
  1789. printf(">--- trying alternative %d for rule %s\n", alt, ident);
  1790. }
  1791. lldebug_iteration(char *ident, int num)
  1792. {
  1793. int i;
  1794. if (lldebug < 2)
  1795. return;
  1796. for (i = 0; i < lldepth - 1; i++)
  1797. fputs("| ", stdout);
  1798. printf(">--- trying iteration %d for rule %s\n", num, ident);
  1799. }
  1800. void
  1801. lldebug_token(int expected, unsigned pos)
  1802. {
  1803. int i;
  1804. if (lldebug < 2)
  1805. return;
  1806. for (i = 0; i < lldepth; i++)
  1807. fputs("| ", stdout);
  1808. if (pos < llntokens && expected == lltokens[pos].token)
  1809. printf(" found token ");
  1810. else
  1811. printf(" expected token %s, found token ", lltokentab[expected]);
  1812. if (pos >= llntokens)
  1813. printf("<EOF>");
  1814. else
  1815. llprinttoken(lltokens + pos, lltokentab[lltokens[pos].token], stdout);
  1816. putchar('\n');
  1817. }
  1818. void
  1819. lldebug_anytoken(unsigned pos)
  1820. {
  1821. int i;
  1822. if (lldebug < 2)
  1823. return;
  1824. for (i = 0; i < lldepth; i++)
  1825. fputs("| ", stdout);
  1826. printf(" found token ");
  1827. if (pos >= llntokens)
  1828. printf("<EOF>");
  1829. else
  1830. llprinttoken(lltokens + pos, lltokentab[lltokens[pos].token], stdout);
  1831. putchar('\n');
  1832. }
  1833. void
  1834. lldebug_backtracking(char *ident)
  1835. {
  1836. int i;
  1837. if (lldebug < 2)
  1838. return;
  1839. for (i = 0; i < lldepth; i++)
  1840. fputs("| ", stdout);
  1841. printf(" backtracking rule %s\n", ident);
  1842. }
  1843. #endif