gram.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. #if defined(__STDC__) || defined(__cplusplus)
  2. #define YYCONST const
  3. #define YYPARAMS(x) x
  4. #define YYDEFUN(name, arglist, args) name(args)
  5. #define YYAND ,
  6. #define YYPTR void *
  7. #else
  8. #define YYCONST
  9. #define YYPARAMS(x) ()
  10. #define YYDEFUN(name, arglist, args) name arglist args;
  11. #define YYAND ;
  12. #define YYPTR char *
  13. #endif
  14. #ifndef lint
  15. YYCONST static char yysccsid[] = "@(#)yaccpar 1.8 (Berkeley +Cygnus.28) 01/20/91";
  16. #endif
  17. #define YYBYACC 1
  18. #ifndef YYDONT_INCLUDE_STDIO
  19. #include <stdio.h>
  20. #endif
  21. #ifdef __cplusplus
  22. #include <stdlib.h> /* for malloc/realloc/free */
  23. #endif
  24. #line 2 "lburg/gram.y"
  25. #include <stdio.h>
  26. #include "lburg.h"
  27. /*lint -e616 -e527 -e652 -esym(552,yynerrs) -esym(563,yynewstate,yyerrlab) */
  28. static int yylineno = 0;
  29. #line 8 "lburg/gram.y"
  30. typedef union {
  31. int n;
  32. char *string;
  33. Tree tree;
  34. } YYSTYPE;
  35. #line 37 "y.tab.c"
  36. #define TERMINAL 257
  37. #define START 258
  38. #define PPERCENT 259
  39. #define ID 260
  40. #define TEMPLATE 261
  41. #define CODE 262
  42. #define INT 263
  43. #define YYERRCODE 256
  44. static YYCONST short yylhs[] = { -1,
  45. 0, 0, 4, 4, 6, 6, 6, 6, 7, 7,
  46. 5, 5, 5, 5, 1, 3, 3, 3, 2,
  47. };
  48. static YYCONST short yylen[] = { 2,
  49. 3, 1, 0, 2, 3, 3, 1, 2, 0, 4,
  50. 0, 7, 2, 3, 1, 1, 4, 6, 1,
  51. };
  52. static YYCONST short yydefred[] = { 3,
  53. 0, 0, 0, 9, 0, 11, 7, 4, 8, 0,
  54. 15, 0, 0, 0, 5, 6, 0, 13, 0, 0,
  55. 14, 0, 10, 0, 0, 0, 0, 0, 19, 0,
  56. 17, 0, 12, 0, 18,
  57. };
  58. static YYCONST short yydgoto[] = { 1,
  59. 12, 30, 25, 2, 13, 8, 10,
  60. };
  61. static YYCONST short yysindex[] = { 0,
  62. 0, -4, -2, 0, -250, 0, 0, 0, 0, -9,
  63. 0, 1, -10, -49, 0, 0, 3, 0, -44, -248,
  64. 0, -244, 0, -22, -242, -244, -245, -37, 0, 10,
  65. 0, -244, 0, -20, 0,
  66. };
  67. static YYCONST short yyrindex[] = { 0,
  68. 0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
  69. 0, 0, 23, 0, 0, 0, 0, 0, 0, 0,
  70. 0, 0, 0, -39, 0, 0, 0, 0, 0, 0,
  71. 0, 0, 0, 0, 0,
  72. };
  73. static YYCONST short yygindex[] = { 0,
  74. 11, 0, -23, 0, 0, 0, 0,
  75. };
  76. #define YYTABLESIZE 255
  77. static YYCONST short yytable[] = { 18,
  78. 15, 16, 28, 31, 16, 7, 32, 9, 34, 11,
  79. 16, 20, 21, 22, 23, 24, 29, 26, 27, 33,
  80. 35, 2, 1, 19, 0, 0, 0, 0, 0, 0,
  81. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  83. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  84. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  85. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  86. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  87. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  88. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  89. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  90. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  91. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  92. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  93. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  94. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  95. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  96. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  97. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  98. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  99. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  100. 0, 16, 0, 0, 0, 0, 0, 0, 0, 0,
  101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  102. 0, 0, 0, 0, 0, 17, 0, 0, 0, 11,
  103. 14, 3, 4, 5, 6,
  104. };
  105. static YYCONST short yycheck[] = { 10,
  106. 10, 41, 26, 41, 44, 10, 44, 10, 32, 260,
  107. 10, 61, 10, 58, 263, 260, 262, 40, 261, 10,
  108. 41, 0, 0, 13, -1, -1, -1, -1, -1, -1,
  109. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  110. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  111. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  112. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  113. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  114. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  115. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  116. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  117. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  118. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  119. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  120. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  121. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  122. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  123. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  124. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  125. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  126. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  127. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  128. -1, 261, -1, -1, -1, -1, -1, -1, -1, -1,
  129. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  130. -1, -1, -1, -1, -1, 256, -1, -1, -1, 260,
  131. 260, 256, 257, 258, 259,
  132. };
  133. #define YYFINAL 1
  134. #ifndef YYDEBUG
  135. #define YYDEBUG 0
  136. #endif
  137. #define YYMAXTOKEN 263
  138. #if YYDEBUG
  139. static YYCONST char *YYCONST yyname[] = {
  140. "end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  141. 0,0,0,0,0,0,0,0,0,"'('","')'",0,0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,"':'",0,0,
  142. "'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  143. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  144. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  145. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  146. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  147. "TERMINAL","START","PPERCENT","ID","TEMPLATE","CODE","INT",
  148. };
  149. static YYCONST char *YYCONST yyrule[] = {
  150. "$accept : spec",
  151. "spec : decls PPERCENT rules",
  152. "spec : decls",
  153. "decls :",
  154. "decls : decls decl",
  155. "decl : TERMINAL blist '\\n'",
  156. "decl : START nonterm '\\n'",
  157. "decl : '\\n'",
  158. "decl : error '\\n'",
  159. "blist :",
  160. "blist : blist ID '=' INT",
  161. "rules :",
  162. "rules : rules nonterm ':' tree TEMPLATE cost '\\n'",
  163. "rules : rules '\\n'",
  164. "rules : rules error '\\n'",
  165. "nonterm : ID",
  166. "tree : ID",
  167. "tree : ID '(' tree ')'",
  168. "tree : ID '(' tree ',' tree ')'",
  169. "cost : CODE",
  170. };
  171. #endif
  172. #define YYLEX yylex()
  173. #define YYEMPTY -1
  174. #define yyclearin (yychar=(YYEMPTY))
  175. #define yyerrok (yyerrflag=0)
  176. #ifndef YYINITDEPTH
  177. #define YYINITDEPTH 200
  178. #endif
  179. #ifdef YYSTACKSIZE
  180. #ifndef YYMAXDEPTH
  181. #define YYMAXDEPTH YYSTACKSIZE
  182. #endif
  183. #else
  184. #ifdef YYMAXDEPTH
  185. #define YYSTACKSIZE YYMAXDEPTH
  186. #else
  187. #define YYSTACKSIZE 500
  188. #define YYMAXDEPTH 500
  189. #endif
  190. #endif
  191. #ifndef YYMAXSTACKSIZE
  192. #define YYMAXSTACKSIZE 10000
  193. #endif
  194. int yydebug;
  195. int yynerrs;
  196. int yyerrflag;
  197. int yychar;
  198. YYSTYPE yyval;
  199. YYSTYPE yylval;
  200. static short *yyss;
  201. static YYSTYPE *yyvs;
  202. static int yystacksize;
  203. #define yyfree(x) free(x)
  204. extern int yylex();
  205. static YYPTR
  206. YYDEFUN (yymalloc, (bytes), unsigned bytes)
  207. {
  208. YYPTR ptr = (YYPTR) malloc (bytes);
  209. if (ptr != 0) return (ptr);
  210. yyerror ("yyparse: memory exhausted");
  211. return (0);
  212. }
  213. static YYPTR
  214. YYDEFUN (yyrealloc, (old, bytes), YYPTR old YYAND unsigned bytes)
  215. {
  216. YYPTR ptr = (YYPTR) realloc (old, bytes);
  217. if (ptr != 0) return (ptr);
  218. yyerror ("yyparse: memory exhausted");
  219. return (0);
  220. }
  221. static int
  222. #ifdef __GNUC__
  223. inline
  224. #endif
  225. yygrow ()
  226. {
  227. int old_stacksize = yystacksize;
  228. short *new_yyss;
  229. YYSTYPE *new_yyvs;
  230. if (yystacksize == YYMAXSTACKSIZE)
  231. return (1);
  232. yystacksize += (yystacksize + 1 ) / 2;
  233. if (yystacksize > YYMAXSTACKSIZE)
  234. yystacksize = YYMAXSTACKSIZE;
  235. #if YYDEBUG
  236. if (yydebug)
  237. printf("yydebug: growing stack size from %d to %d\n",
  238. old_stacksize, yystacksize);
  239. #endif
  240. new_yyss = (short *) yyrealloc ((char *)yyss, yystacksize * sizeof (short));
  241. if (new_yyss == 0)
  242. return (1);
  243. new_yyvs = (YYSTYPE *) yyrealloc ((char *)yyvs, yystacksize * sizeof (YYSTYPE));
  244. if (new_yyvs == 0)
  245. {
  246. yyfree (new_yyss);
  247. return (1);
  248. }
  249. yyss = new_yyss;
  250. yyvs = new_yyvs;
  251. return (0);
  252. }
  253. #line 60 "lburg/gram.y"
  254. #include <assert.h>
  255. #include <stdarg.h>
  256. #include <ctype.h>
  257. #include <string.h>
  258. #include <limits.h>
  259. int errcnt = 0;
  260. FILE *infp = NULL;
  261. FILE *outfp = NULL;
  262. static char buf[BUFSIZ], *bp = buf;
  263. static int ppercent = 0;
  264. static int code = 0;
  265. static int get(void) {
  266. if (*bp == 0) {
  267. bp = buf;
  268. *bp = 0;
  269. if (fgets(buf, sizeof buf, infp) == NULL)
  270. return EOF;
  271. yylineno++;
  272. while (buf[0] == '%' && buf[1] == '{' && buf[2] == '\n') {
  273. for (;;) {
  274. if (fgets(buf, sizeof buf, infp) == NULL) {
  275. yywarn("unterminated %{...%}\n");
  276. return EOF;
  277. }
  278. yylineno++;
  279. if (strcmp(buf, "%}\n") == 0)
  280. break;
  281. fputs(buf, outfp);
  282. }
  283. if (fgets(buf, sizeof buf, infp) == NULL)
  284. return EOF;
  285. yylineno++;
  286. }
  287. }
  288. return *bp++;
  289. }
  290. void yyerror(char *fmt, ...) {
  291. va_list ap;
  292. va_start(ap, fmt);
  293. if (yylineno > 0)
  294. fprintf(stderr, "line %d: ", yylineno);
  295. vfprintf(stderr, fmt, ap);
  296. if (fmt[strlen(fmt)-1] != '\n')
  297. fprintf(stderr, "\n");
  298. errcnt++;
  299. va_end(ap);
  300. }
  301. int yylex(void) {
  302. int c;
  303. if (code) {
  304. char *p;
  305. bp += strspn(bp, " \t\f");
  306. p = strchr(bp, '\n');
  307. if (p == NULL)
  308. p = strchr(bp, '\n');
  309. while (p > bp && isspace(p[-1]))
  310. p--;
  311. yylval.string = alloc(p - bp + 1);
  312. strncpy(yylval.string, bp, p - bp);
  313. yylval.string[p - bp] = 0;
  314. bp = p;
  315. code--;
  316. return CODE;
  317. }
  318. while ((c = get()) != EOF) {
  319. switch (c) {
  320. case ' ': case '\f': case '\t':
  321. continue;
  322. case '\n':
  323. case '(': case ')': case ',':
  324. case ':': case '=':
  325. return c;
  326. }
  327. if (c == '%' && *bp == '%') {
  328. bp++;
  329. return ppercent++ ? 0 : PPERCENT;
  330. } else if (c == '%' && strncmp(bp, "term", 4) == 0
  331. && isspace(bp[4])) {
  332. bp += 4;
  333. return TERMINAL;
  334. } else if (c == '%' && strncmp(bp, "start", 5) == 0
  335. && isspace(bp[5])) {
  336. bp += 5;
  337. return START;
  338. } else if (c == '"') {
  339. char *p = strchr(bp, '"');
  340. if (p == NULL) {
  341. yyerror("missing \" in assembler template\n");
  342. p = strchr(bp, '\n');
  343. if (p == NULL)
  344. p = strchr(bp, '\0');
  345. }
  346. assert(p);
  347. yylval.string = alloc(p - bp + 1);
  348. strncpy(yylval.string, bp, p - bp);
  349. yylval.string[p - bp] = 0;
  350. bp = *p == '"' ? p + 1 : p;
  351. code++;
  352. return TEMPLATE;
  353. } else if (isdigit(c)) {
  354. int n = 0;
  355. do {
  356. int d = c - '0';
  357. if (n > (INT_MAX - d)/10)
  358. yyerror("integer greater than %d\n", INT_MAX);
  359. else
  360. n = 10*n + d;
  361. c = get();
  362. } while (c != EOF && isdigit(c));
  363. bp--;
  364. yylval.n = n;
  365. return INT;
  366. } else if (isalpha(c)) {
  367. char *p = bp - 1;
  368. while (isalpha(*bp) || isdigit(*bp) || *bp == '_')
  369. bp++;
  370. yylval.string = alloc(bp - p + 1);
  371. strncpy(yylval.string, p, bp - p);
  372. yylval.string[bp - p] = 0;
  373. return ID;
  374. } else if (isprint(c))
  375. yyerror("invalid character `%c'\n", c);
  376. else
  377. yyerror("invalid character `\\%03o'\n", (unsigned char)c);
  378. }
  379. return 0;
  380. }
  381. void yywarn(char *fmt, ...) {
  382. va_list ap;
  383. va_start(ap, fmt);
  384. if (yylineno > 0)
  385. fprintf(stderr, "line %d: ", yylineno);
  386. fprintf(stderr, "warning: ");
  387. vfprintf(stderr, fmt, ap);
  388. }
  389. #line 403 "y.tab.c"
  390. #define YYABORT goto yyabort
  391. #define YYACCEPT goto yyaccept
  392. #define YYERROR goto yyerrlab
  393. #if YYDEBUG
  394. #ifdef __cplusplus
  395. extern "C" char *getenv();
  396. #else
  397. extern char *getenv();
  398. #endif
  399. #endif
  400. int
  401. yyparse()
  402. {
  403. register int yym, yyn, yystate;
  404. register YYSTYPE *yyvsp;
  405. register short *yyssp;
  406. short *yysse;
  407. #if YYDEBUG
  408. register YYCONST char *yys;
  409. if (yys = getenv("YYDEBUG"))
  410. {
  411. yyn = *yys;
  412. if (yyn >= '0' && yyn <= '9')
  413. yydebug = yyn - '0';
  414. }
  415. #endif
  416. yynerrs = 0;
  417. yyerrflag = 0;
  418. yychar = (-1);
  419. if (yyss == 0)
  420. {
  421. yyss = (short *) yymalloc (YYSTACKSIZE * sizeof (short));
  422. if (yyss == 0)
  423. goto yyabort;
  424. yyvs = (YYSTYPE *) yymalloc (YYSTACKSIZE * sizeof (YYSTYPE));
  425. if (yyvs == 0)
  426. {
  427. yyfree (yyss);
  428. goto yyabort;
  429. }
  430. yystacksize = YYSTACKSIZE;
  431. }
  432. yysse = yyss + yystacksize - 1;
  433. yyssp = yyss;
  434. yyvsp = yyvs;
  435. *yyssp = yystate = 0;
  436. goto yyloop;
  437. yypush_lex:
  438. yyval = yylval;
  439. yystate = yytable[yyn];
  440. yypush:
  441. if (yyssp >= yysse)
  442. {
  443. int depth = yyssp - yyss;
  444. if (yygrow() != 0)
  445. goto yyoverflow;
  446. yysse = yyss + yystacksize -1;
  447. yyssp = depth + yyss;
  448. yyvsp = depth + yyvs;
  449. }
  450. *++yyssp = yystate;
  451. *++yyvsp = yyval;
  452. yyloop:
  453. if (yyn = yydefred[yystate]) goto yyreduce;
  454. yyn = yysindex[yystate];
  455. if (yychar < 0)
  456. {
  457. if ((yychar = yylex()) < 0) yychar = 0;
  458. #if YYDEBUG
  459. if (yydebug)
  460. {
  461. yys = 0;
  462. if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  463. if (!yys) yys = "illegal-symbol";
  464. printf("yydebug: state %d, reading %d (%s)\n", yystate,
  465. yychar, yys);
  466. }
  467. #endif
  468. }
  469. if (yyn != 0
  470. && ((yyn += yychar), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
  471. && yycheck[yyn] == yychar)
  472. {
  473. #if YYDEBUG
  474. if (yydebug)
  475. printf("yydebug: state %d, shifting to state %d\n",
  476. yystate, yytable[yyn]);
  477. #endif
  478. if (yyerrflag > 0) --yyerrflag;
  479. yychar = (-1);
  480. goto yypush_lex;
  481. }
  482. yyn = yyrindex[yystate];
  483. if (yyn != 0
  484. && ((yyn += yychar), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
  485. && yycheck[yyn] == yychar)
  486. {
  487. yyn = yytable[yyn];
  488. goto yyreduce;
  489. }
  490. if (yyerrflag) goto yyinrecovery;
  491. #ifdef lint
  492. goto yynewerror;
  493. #endif
  494. yynewerror:
  495. yyerror("syntax error");
  496. #ifdef lint
  497. goto yyerrlab;
  498. #endif
  499. yyerrlab:
  500. ++yynerrs;
  501. yyinrecovery:
  502. if (yyerrflag < 3)
  503. {
  504. yyerrflag = 3;
  505. for (;;)
  506. {
  507. yyn = yysindex[*yyssp];
  508. if (yyn != 0
  509. && ((yyn += YYERRCODE), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
  510. && yycheck[yyn] == YYERRCODE)
  511. {
  512. #if YYDEBUG
  513. if (yydebug)
  514. printf("yydebug: state %d, error recovery shifting\
  515. to state %d\n", *yyssp, yytable[yyn]);
  516. #endif
  517. goto yypush_lex;
  518. }
  519. else
  520. {
  521. #if YYDEBUG
  522. if (yydebug)
  523. printf("yydebug: error recovery discarding state %d\n",
  524. *yyssp);
  525. #endif
  526. if (yyssp <= yyss) goto yyabort;
  527. --yyssp;
  528. --yyvsp;
  529. }
  530. }
  531. }
  532. else
  533. {
  534. if (yychar == 0) goto yyabort;
  535. #if YYDEBUG
  536. if (yydebug)
  537. {
  538. yys = 0;
  539. if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  540. if (!yys) yys = "illegal-symbol";
  541. printf("yydebug: state %d, error recovery discards token %d (%s)\n",
  542. yystate, yychar, yys);
  543. }
  544. #endif
  545. yychar = (-1);
  546. goto yyloop;
  547. }
  548. yyreduce:
  549. #if YYDEBUG
  550. if (yydebug)
  551. printf("yydebug: state %d, reducing by rule %d (%s)\n",
  552. yystate, yyn, yyrule[yyn]);
  553. #endif
  554. yym = yylen[yyn];
  555. yyval = yyvsp[1-yym];
  556. switch (yyn)
  557. {
  558. case 1:
  559. #line 22 "lburg/gram.y"
  560. { yylineno = 0; }
  561. break;
  562. case 2:
  563. #line 23 "lburg/gram.y"
  564. { yylineno = 0; }
  565. break;
  566. case 6:
  567. #line 31 "lburg/gram.y"
  568. {
  569. if (nonterm(yyvsp[-1].string)->number != 1)
  570. yyerror("redeclaration of the start symbol\n");
  571. }
  572. break;
  573. case 8:
  574. #line 36 "lburg/gram.y"
  575. { yyerrok; }
  576. break;
  577. case 10:
  578. #line 40 "lburg/gram.y"
  579. { term(yyvsp[-2].string, yyvsp[0].n); }
  580. break;
  581. case 12:
  582. #line 44 "lburg/gram.y"
  583. { rule(yyvsp[-5].string, yyvsp[-3].tree, yyvsp[-2].string, yyvsp[-1].string); }
  584. break;
  585. case 14:
  586. #line 46 "lburg/gram.y"
  587. { yyerrok; }
  588. break;
  589. case 15:
  590. #line 49 "lburg/gram.y"
  591. { nonterm(yyval.string = yyvsp[0].string); }
  592. break;
  593. case 16:
  594. #line 52 "lburg/gram.y"
  595. { yyval.tree = tree(yyvsp[0].string, 0, 0); }
  596. break;
  597. case 17:
  598. #line 53 "lburg/gram.y"
  599. { yyval.tree = tree(yyvsp[-3].string, yyvsp[-1].tree, 0); }
  600. break;
  601. case 18:
  602. #line 54 "lburg/gram.y"
  603. { yyval.tree = tree(yyvsp[-5].string, yyvsp[-3].tree, yyvsp[-1].tree); }
  604. break;
  605. case 19:
  606. #line 57 "lburg/gram.y"
  607. { if (*yyvsp[0].string == 0) yyval.string = "0"; }
  608. break;
  609. #line 630 "y.tab.c"
  610. }
  611. yyssp -= yym;
  612. yyvsp -= yym;
  613. yym = yylhs[yyn];
  614. yystate = *yyssp;
  615. if (yystate == 0 && yym == 0)
  616. {
  617. #if YYDEBUG
  618. if (yydebug)
  619. printf("yydebug: after reduction, shifting from state 0 to\
  620. state %d\n", YYFINAL);
  621. #endif
  622. yystate = YYFINAL;
  623. *++yyssp = YYFINAL;
  624. *++yyvsp = yyval;
  625. if (yychar < 0)
  626. {
  627. if ((yychar = yylex()) < 0) yychar = 0;
  628. #if YYDEBUG
  629. if (yydebug)
  630. {
  631. yys = 0;
  632. if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  633. if (!yys) yys = "illegal-symbol";
  634. printf("yydebug: state %d, reading %d (%s)\n",
  635. YYFINAL, yychar, yys);
  636. }
  637. #endif
  638. }
  639. if (yychar == 0) goto yyaccept;
  640. goto yyloop;
  641. }
  642. yyn = yygindex[yym];
  643. if (yyn != 0
  644. && ((yyn += yystate), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
  645. && yycheck[yyn] == yystate)
  646. yystate = yytable[yyn];
  647. else
  648. yystate = yydgoto[yym];
  649. #if YYDEBUG
  650. if (yydebug)
  651. printf("yydebug: after reduction, shifting from state %d \
  652. to state %d\n", *yyssp, yystate);
  653. #endif
  654. goto yypush;
  655. yyoverflow:
  656. yyerror("yacc stack overflow");
  657. yyabort:
  658. return (1);
  659. yyaccept:
  660. return (0);
  661. }