BISON.SIM 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
  2. #line 3 "bison.simple"
  3. /* Skeleton output parser for bison,
  4. Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 1, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  16. #ifndef alloca
  17. #ifdef __GNUC__
  18. #define alloca __builtin_alloca
  19. #else /* not GNU C. */
  20. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc)
  21. #include <alloca.h>
  22. #else /* not sparc */
  23. #if defined (MSDOS) && !defined (__TURBOC__)
  24. #include <malloc.h>
  25. #else /* not MSDOS, or __TURBOC__ */
  26. #if defined(_AIX)
  27. #include <malloc.h>
  28. #pragma alloca
  29. #endif /* not _AIX */
  30. #endif /* not MSDOS, or __TURBOC__ */
  31. #endif /* not sparc. */
  32. #endif /* not GNU C. */
  33. #endif /* alloca not defined. */
  34. #ifdef atarist
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <unistd.h>
  38. #include <memory.h>
  39. #endif /* atarist */
  40. /* This is the parser code that is written into each bison parser
  41. when the %semantic_parser declaration is not specified in the grammar.
  42. It was written by Richard Stallman by simplifying the hairy parser
  43. used when %semantic_parser is specified. */
  44. /* Note: there must be only one dollar sign in this file.
  45. It is replaced by the list of actions, each action
  46. as one case of the switch. */
  47. #define yyerrok (yyerrstatus = 0)
  48. #define yyclearin (yychar = YYEMPTY)
  49. #define YYEMPTY -2
  50. #define YYEOF 0
  51. #define YYACCEPT return(0)
  52. #define YYABORT return(1)
  53. #define YYERROR goto yyerrlab1
  54. /* Like YYERROR except do call yyerror.
  55. This remains here temporarily to ease the
  56. transition to the new meaning of YYERROR, for GCC.
  57. Once GCC version 2 has supplanted version 1, this can go. */
  58. #define YYFAIL goto yyerrlab
  59. #define YYRECOVERING() (!!yyerrstatus)
  60. #define YYBACKUP(token, value) \
  61. do \
  62. if (yychar == YYEMPTY && yylen == 1) \
  63. { yychar = (token), yylval = (value); \
  64. yychar1 = YYTRANSLATE (yychar); \
  65. YYPOPSTACK; \
  66. goto yybackup; \
  67. } \
  68. else \
  69. { yyerror ("syntax error: cannot back up"); YYERROR; } \
  70. while (0)
  71. #define YYTERROR 1
  72. #define YYERRCODE 256
  73. #ifndef YYPURE
  74. #define YYLEX yylex()
  75. #endif
  76. #ifdef YYPURE
  77. #ifdef YYLSP_NEEDED
  78. #define YYLEX yylex(&yylval, &yylloc)
  79. #else
  80. #define YYLEX yylex(&yylval)
  81. #endif
  82. #endif
  83. /* If nonreentrant, generate the variables here */
  84. #ifndef YYPURE
  85. int yychar; /* the lookahead symbol */
  86. YYSTYPE yylval; /* the semantic value of the */
  87. /* lookahead symbol */
  88. #ifdef YYLSP_NEEDED
  89. YYLTYPE yylloc; /* location data for the lookahead */
  90. /* symbol */
  91. #endif
  92. int yynerrs; /* number of parse errors so far */
  93. #endif /* not YYPURE */
  94. #if YYDEBUG != 0
  95. int yydebug; /* nonzero means print parse trace */
  96. /* Since this is uninitialized, it does not stop multiple parsers
  97. from coexisting. */
  98. #endif
  99. /* YYINITDEPTH indicates the initial size of the parser's stacks */
  100. #ifndef YYINITDEPTH
  101. #define YYINITDEPTH 200
  102. #endif
  103. /* YYMAXDEPTH is the maximum size the stacks can grow to
  104. (effective only if the built-in stack extension method is used). */
  105. #if YYMAXDEPTH == 0
  106. #undef YYMAXDEPTH
  107. #endif
  108. #ifndef YYMAXDEPTH
  109. #define YYMAXDEPTH 10000
  110. #endif
  111. #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
  112. #define __yy_bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
  113. #else /* not GNU C or C++ */
  114. #ifndef __cplusplus
  115. /* This is the most reliable way to avoid incompatibilities
  116. in available built-in functions on various systems. */
  117. static void
  118. __yy_bcopy (from, to, count)
  119. char *from;
  120. char *to;
  121. int count;
  122. {
  123. register char *f = from;
  124. register char *t = to;
  125. register int i = count;
  126. while (i-- > 0)
  127. *t++ = *f++;
  128. }
  129. #else /* __cplusplus */
  130. /* This is the most reliable way to avoid incompatibilities
  131. in available built-in functions on various systems. */
  132. static void
  133. __yy_bcopy (char *from, char *to, int count)
  134. {
  135. register char *f = from;
  136. register char *t = to;
  137. register int i = count;
  138. while (i-- > 0)
  139. *t++ = *f++;
  140. }
  141. #endif
  142. #endif
  143. #line 169 "bison.simple"
  144. int
  145. yyparse()
  146. {
  147. register int yystate;
  148. register int yyn;
  149. register short *yyssp;
  150. register YYSTYPE *yyvsp;
  151. int yyerrstatus; /* number of tokens to shift before error messages enabled */
  152. int yychar1; /* lookahead token as an internal (translated) token number */
  153. short yyssa[YYINITDEPTH]; /* the state stack */
  154. YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
  155. short *yyss = yyssa; /* refer to the stacks thru separate pointers */
  156. YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
  157. #ifdef YYLSP_NEEDED
  158. YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
  159. YYLTYPE *yyls = yylsa;
  160. YYLTYPE *yylsp;
  161. #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
  162. #else
  163. #define YYPOPSTACK (yyvsp--, yyssp--)
  164. #endif
  165. int yystacksize = YYINITDEPTH;
  166. #ifdef YYPURE
  167. int yychar;
  168. YYSTYPE yylval;
  169. int yynerrs;
  170. #ifdef YYLSP_NEEDED
  171. YYLTYPE yylloc;
  172. #endif
  173. #endif
  174. YYSTYPE yyval; /* the variable used to return */
  175. /* semantic values from the action */
  176. /* routines */
  177. int yylen;
  178. #if YYDEBUG != 0
  179. if (yydebug)
  180. fprintf(stderr, "Starting parse\n");
  181. #endif
  182. yystate = 0;
  183. yyerrstatus = 0;
  184. yynerrs = 0;
  185. yychar = YYEMPTY; /* Cause a token to be read. */
  186. /* Initialize stack pointers.
  187. Waste one element of value and location stack
  188. so that they stay on the same level as the state stack.
  189. The wasted elements are never initialized. */
  190. yyssp = yyss - 1;
  191. yyvsp = yyvs;
  192. #ifdef YYLSP_NEEDED
  193. yylsp = yyls;
  194. #endif
  195. /* Push a new state, which is found in yystate . */
  196. /* In all cases, when you get here, the value and location stacks
  197. have just been pushed. so pushing a state here evens the stacks. */
  198. yynewstate:
  199. *++yyssp = yystate;
  200. if (yyssp >= yyss + yystacksize - 1)
  201. {
  202. /* Give user a chance to reallocate the stack */
  203. /* Use copies of these so that the &'s don't force the real ones into memory. */
  204. YYSTYPE *yyvs1 = yyvs;
  205. short *yyss1 = yyss;
  206. #ifdef YYLSP_NEEDED
  207. YYLTYPE *yyls1 = yyls;
  208. #endif
  209. /* Get the current used size of the three stacks, in elements. */
  210. int size = yyssp - yyss + 1;
  211. #ifdef yyoverflow
  212. /* Each stack pointer address is followed by the size of
  213. the data in use in that stack, in bytes. */
  214. yyoverflow("parser stack overflow",
  215. &yyss1, size * sizeof (*yyssp),
  216. &yyvs1, size * sizeof (*yyvsp),
  217. #ifdef YYLSP_NEEDED
  218. &yyls1, size * sizeof (*yylsp),
  219. #endif
  220. &yystacksize);
  221. yyss = yyss1; yyvs = yyvs1;
  222. #ifdef YYLSP_NEEDED
  223. yyls = yyls1;
  224. #endif
  225. #else /* no yyoverflow */
  226. /* Extend the stack our own way. */
  227. if (yystacksize >= YYMAXDEPTH)
  228. {
  229. yyerror("parser stack overflow");
  230. return 2;
  231. }
  232. yystacksize *= 2;
  233. if (yystacksize > YYMAXDEPTH)
  234. yystacksize = YYMAXDEPTH;
  235. yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  236. __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  237. yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  238. __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  239. #ifdef YYLSP_NEEDED
  240. yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  241. __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  242. #endif
  243. #endif /* no yyoverflow */
  244. yyssp = yyss + size - 1;
  245. yyvsp = yyvs + size - 1;
  246. #ifdef YYLSP_NEEDED
  247. yylsp = yyls + size - 1;
  248. #endif
  249. #if YYDEBUG != 0
  250. if (yydebug)
  251. fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  252. #endif
  253. if (yyssp >= yyss + yystacksize - 1)
  254. YYABORT;
  255. }
  256. #if YYDEBUG != 0
  257. if (yydebug)
  258. fprintf(stderr, "Entering state %d\n", yystate);
  259. #endif
  260. goto yybackup;
  261. yybackup:
  262. /* Do appropriate processing given the current state. */
  263. /* Read a lookahead token if we need one and don't already have one. */
  264. /* yyresume: */
  265. /* First try to decide what to do without reference to lookahead token. */
  266. yyn = yypact[yystate];
  267. if (yyn == YYFLAG)
  268. goto yydefault;
  269. /* Not known => get a lookahead token if don't already have one. */
  270. /* yychar is either YYEMPTY or YYEOF
  271. or a valid token in external form. */
  272. if (yychar == YYEMPTY)
  273. {
  274. #if YYDEBUG != 0
  275. if (yydebug)
  276. fprintf(stderr, "Reading a token: ");
  277. #endif
  278. yychar = YYLEX;
  279. }
  280. /* Convert token to internal form (in yychar1) for indexing tables with */
  281. if (yychar <= 0) /* This means end of input. */
  282. {
  283. yychar1 = 0;
  284. yychar = YYEOF; /* Don't call YYLEX any more */
  285. #if YYDEBUG != 0
  286. if (yydebug)
  287. fprintf(stderr, "Now at end of input.\n");
  288. #endif
  289. }
  290. else
  291. {
  292. yychar1 = YYTRANSLATE(yychar);
  293. #if YYDEBUG != 0
  294. if (yydebug)
  295. {
  296. fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  297. /* Give the individual parser a way to print the precise meaning
  298. of a token, for further debugging info. */
  299. #ifdef YYPRINT
  300. YYPRINT (stderr, yychar, yylval);
  301. #endif
  302. fprintf (stderr, ")\n");
  303. }
  304. #endif
  305. }
  306. yyn += yychar1;
  307. if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  308. goto yydefault;
  309. yyn = yytable[yyn];
  310. /* yyn is what to do for this token type in this state.
  311. Negative => reduce, -yyn is rule number.
  312. Positive => shift, yyn is new state.
  313. New state is final state => don't bother to shift,
  314. just return success.
  315. 0, or most negative number => error. */
  316. if (yyn < 0)
  317. {
  318. if (yyn == YYFLAG)
  319. goto yyerrlab;
  320. yyn = -yyn;
  321. goto yyreduce;
  322. }
  323. else if (yyn == 0)
  324. goto yyerrlab;
  325. if (yyn == YYFINAL)
  326. YYACCEPT;
  327. /* Shift the lookahead token. */
  328. #if YYDEBUG != 0
  329. if (yydebug)
  330. fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  331. #endif
  332. /* Discard the token being shifted unless it is eof. */
  333. if (yychar != YYEOF)
  334. yychar = YYEMPTY;
  335. *++yyvsp = yylval;
  336. #ifdef YYLSP_NEEDED
  337. *++yylsp = yylloc;
  338. #endif
  339. /* count tokens shifted since error; after three, turn off error status. */
  340. if (yyerrstatus) yyerrstatus--;
  341. yystate = yyn;
  342. goto yynewstate;
  343. /* Do the default action for the current state. */
  344. yydefault:
  345. yyn = yydefact[yystate];
  346. if (yyn == 0)
  347. goto yyerrlab;
  348. /* Do a reduction. yyn is the number of a rule to reduce with. */
  349. yyreduce:
  350. yylen = yyr2[yyn];
  351. yyval = yyvsp[1-yylen]; /* implement default value of the action */
  352. #if YYDEBUG != 0
  353. if (yydebug)
  354. {
  355. int i;
  356. fprintf (stderr, "Reducing via rule %d (line %d), ",
  357. yyn, yyrline[yyn]);
  358. /* Print the symbols being reduced, and their result. */
  359. for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  360. fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  361. fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  362. }
  363. #endif
  364. $ /* the action file gets copied in in place of this dollarsign */
  365. #line 442 "bison.simple"
  366. yyvsp -= yylen;
  367. yyssp -= yylen;
  368. #ifdef YYLSP_NEEDED
  369. yylsp -= yylen;
  370. #endif
  371. #if YYDEBUG != 0
  372. if (yydebug)
  373. {
  374. short *ssp1 = yyss - 1;
  375. fprintf (stderr, "state stack now");
  376. while (ssp1 != yyssp)
  377. fprintf (stderr, " %d", *++ssp1);
  378. fprintf (stderr, "\n");
  379. }
  380. #endif
  381. *++yyvsp = yyval;
  382. #ifdef YYLSP_NEEDED
  383. yylsp++;
  384. if (yylen == 0)
  385. {
  386. yylsp->first_line = yylloc.first_line;
  387. yylsp->first_column = yylloc.first_column;
  388. yylsp->last_line = (yylsp-1)->last_line;
  389. yylsp->last_column = (yylsp-1)->last_column;
  390. yylsp->text = 0;
  391. }
  392. else
  393. {
  394. yylsp->last_line = (yylsp+yylen-1)->last_line;
  395. yylsp->last_column = (yylsp+yylen-1)->last_column;
  396. }
  397. #endif
  398. /* Now "shift" the result of the reduction.
  399. Determine what state that goes to,
  400. based on the state we popped back to
  401. and the rule number reduced by. */
  402. yyn = yyr1[yyn];
  403. yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  404. if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  405. yystate = yytable[yystate];
  406. else
  407. yystate = yydefgoto[yyn - YYNTBASE];
  408. goto yynewstate;
  409. yyerrlab: /* here on detecting error */
  410. if (! yyerrstatus)
  411. /* If not already recovering from an error, report this error. */
  412. {
  413. ++yynerrs;
  414. #ifdef YYERROR_VERBOSE
  415. yyn = yypact[yystate];
  416. if (yyn > YYFLAG && yyn < YYLAST)
  417. {
  418. int size = 0;
  419. char *msg;
  420. int x, count;
  421. count = 0;
  422. for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  423. if (yycheck[x + yyn] == x)
  424. size += strlen(yytname[x]) + 15, count++;
  425. msg = (char *) malloc(size + 15);
  426. if (msg != 0)
  427. {
  428. strcpy(msg, "parse error");
  429. if (count < 5)
  430. {
  431. count = 0;
  432. for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  433. if (yycheck[x + yyn] == x)
  434. {
  435. strcat(msg, count == 0 ? ", expecting `" : " or `");
  436. strcat(msg, yytname[x]);
  437. strcat(msg, "'");
  438. count++;
  439. }
  440. }
  441. yyerror(msg);
  442. free(msg);
  443. }
  444. else
  445. yyerror ("parse error; also virtual memory exceeded");
  446. }
  447. else
  448. #endif /* YYERROR_VERBOSE */
  449. yyerror("parse error");
  450. }
  451. goto yyerrlab1;
  452. yyerrlab1: /* here on error raised explicitly by an action */
  453. if (yyerrstatus == 3)
  454. {
  455. /* if just tried and failed to reuse lookahead token after an error, discard it. */
  456. /* return failure if at end of input */
  457. if (yychar == YYEOF)
  458. YYABORT;
  459. #if YYDEBUG != 0
  460. if (yydebug)
  461. fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  462. #endif
  463. yychar = YYEMPTY;
  464. }
  465. /* Else will try to reuse lookahead token
  466. after shifting the error token. */
  467. yyerrstatus = 3; /* Each real token shifted decrements this */
  468. goto yyerrhandle;
  469. yyerrdefault: /* current state does not do anything special for the error token. */
  470. #if 0
  471. /* This is wrong; only states that explicitly want error tokens
  472. should shift them. */
  473. yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
  474. if (yyn) goto yydefault;
  475. #endif
  476. yyerrpop: /* pop the current state because it cannot handle the error token */
  477. if (yyssp == yyss) YYABORT;
  478. yyvsp--;
  479. yystate = *--yyssp;
  480. #ifdef YYLSP_NEEDED
  481. yylsp--;
  482. #endif
  483. #if YYDEBUG != 0
  484. if (yydebug)
  485. {
  486. short *ssp1 = yyss - 1;
  487. fprintf (stderr, "Error: state stack now");
  488. while (ssp1 != yyssp)
  489. fprintf (stderr, " %d", *++ssp1);
  490. fprintf (stderr, "\n");
  491. }
  492. #endif
  493. yyerrhandle:
  494. yyn = yypact[yystate];
  495. if (yyn == YYFLAG)
  496. goto yyerrdefault;
  497. yyn += YYTERROR;
  498. if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  499. goto yyerrdefault;
  500. yyn = yytable[yyn];
  501. if (yyn < 0)
  502. {
  503. if (yyn == YYFLAG)
  504. goto yyerrpop;
  505. yyn = -yyn;
  506. goto yyreduce;
  507. }
  508. else if (yyn == 0)
  509. goto yyerrpop;
  510. if (yyn == YYFINAL)
  511. YYACCEPT;
  512. #if YYDEBUG != 0
  513. if (yydebug)
  514. fprintf(stderr, "Shifting error token, ");
  515. #endif
  516. *++yyvsp = yylval;
  517. #ifdef YYLSP_NEEDED
  518. *++yylsp = yylloc;
  519. #endif
  520. yystate = yyn;
  521. goto yynewstate;
  522. }