BISON.SIM 14 KB

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