BISON.SIM 12 KB

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