bison.simple 16 KB

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