bison.simple 11 KB

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