bison.hairy 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /* header section */
  2. #include <stdio.h>
  3. #ifndef __STDC__
  4. #define const
  5. #endif
  6. $
  7. extern int timeclock;
  8. int yyerror; /* Yyerror and yycost are set by guards. */
  9. int yycost; /* If yyerror is set to a nonzero value by a */
  10. /* guard, the reduction with which the guard */
  11. /* is associated is not performed, and the */
  12. /* error recovery mechanism is invoked. */
  13. /* Yycost indicates the cost of performing */
  14. /* the reduction given the attributes of the */
  15. /* symbols. */
  16. /* YYMAXDEPTH indicates the size of the parser's state and value */
  17. /* stacks. */
  18. #ifndef YYMAXDEPTH
  19. #define YYMAXDEPTH 500
  20. #endif
  21. /* YYMAXRULES must be at least as large as the number of rules that */
  22. /* could be placed in the rule queue. That number could be determined */
  23. /* from the grammar and the size of the stack, but, as yet, it is not. */
  24. #ifndef YYMAXRULES
  25. #define YYMAXRULES 100
  26. #endif
  27. #ifndef YYMAXBACKUP
  28. #define YYMAXBACKUP 100
  29. #endif
  30. short yyss[YYMAXDEPTH]; /* the state stack */
  31. YYSTYPE yyvs[YYMAXDEPTH]; /* the semantic value stack */
  32. YYLTYPE yyls[YYMAXDEPTH]; /* the location stack */
  33. short yyrq[YYMAXRULES]; /* the rule queue */
  34. int yychar; /* the lookahead symbol */
  35. YYSTYPE yylval; /* the semantic value of the */
  36. /* lookahead symbol */
  37. YYSTYPE yytval; /* the semantic value for the state */
  38. /* at the top of the state stack. */
  39. YYSTYPE yyval; /* the variable used to return */
  40. /* semantic values from the action */
  41. /* routines */
  42. YYLTYPE yylloc; /* location data for the lookahead */
  43. /* symbol */
  44. YYLTYPE yytloc; /* location data for the state at the */
  45. /* top of the state stack */
  46. int yynunlexed;
  47. short yyunchar[YYMAXBACKUP];
  48. YYSTYPE yyunval[YYMAXBACKUP];
  49. YYLTYPE yyunloc[YYMAXBACKUP];
  50. short *yygssp; /* a pointer to the top of the state */
  51. /* stack; only set during error */
  52. /* recovery. */
  53. YYSTYPE *yygvsp; /* a pointer to the top of the value */
  54. /* stack; only set during error */
  55. /* recovery. */
  56. YYLTYPE *yyglsp; /* a pointer to the top of the */
  57. /* location stack; only set during */
  58. /* error recovery. */
  59. /* Yyget is an interface between the parser and the lexical analyzer. */
  60. /* It is costly to provide such an interface, but it avoids requiring */
  61. /* the lexical analyzer to be able to back up the scan. */
  62. yyget()
  63. {
  64. if (yynunlexed > 0)
  65. {
  66. yynunlexed--;
  67. yychar = yyunchar[yynunlexed];
  68. yylval = yyunval[yynunlexed];
  69. yylloc = yyunloc[yynunlexed];
  70. }
  71. else if (yychar <= 0)
  72. yychar = 0;
  73. else
  74. {
  75. yychar = yylex();
  76. if (yychar < 0)
  77. yychar = 0;
  78. else yychar = YYTRANSLATE(yychar);
  79. }
  80. }
  81. yyunlex(chr, val, loc)
  82. int chr;
  83. YYSTYPE val;
  84. YYLTYPE loc;
  85. {
  86. yyunchar[yynunlexed] = chr;
  87. yyunval[yynunlexed] = val;
  88. yyunloc[yynunlexed] = loc;
  89. yynunlexed++;
  90. }
  91. yyrestore(first, last)
  92. register short *first;
  93. register short *last;
  94. {
  95. register short *ssp;
  96. register short *rp;
  97. register int symbol;
  98. register int state;
  99. register int tvalsaved;
  100. ssp = yygssp;
  101. yyunlex(yychar, yylval, yylloc);
  102. tvalsaved = 0;
  103. while (first != last)
  104. {
  105. symbol = yystos[*ssp];
  106. if (symbol < YYNTBASE)
  107. {
  108. yyunlex(symbol, yytval, yytloc);
  109. tvalsaved = 1;
  110. ssp--;
  111. }
  112. ssp--;
  113. if (first == yyrq)
  114. first = yyrq + YYMAXRULES;
  115. first--;
  116. for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++)
  117. {
  118. if (symbol < YYNTBASE)
  119. state = yytable[yypact[*ssp] + symbol];
  120. else
  121. {
  122. state = yypgoto[symbol - YYNTBASE] + *ssp;
  123. if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp)
  124. state = yytable[state];
  125. else
  126. state = yydefgoto[symbol - YYNTBASE];
  127. }
  128. *++ssp = state;
  129. }
  130. }
  131. if ( ! tvalsaved && ssp > yyss)
  132. {
  133. yyunlex(yystos[*ssp], yytval, yytloc);
  134. ssp--;
  135. }
  136. yygssp = ssp;
  137. }
  138. int
  139. yyparse()
  140. {
  141. register int yystate;
  142. register int yyn;
  143. register short *yyssp;
  144. register short *yyrq0;
  145. register short *yyptr;
  146. register YYSTYPE *yyvsp;
  147. int yylen;
  148. YYLTYPE *yylsp;
  149. short *yyrq1;
  150. short *yyrq2;
  151. yystate = 0;
  152. yyssp = yyss - 1;
  153. yyvsp = yyvs - 1;
  154. yylsp = yyls - 1;
  155. yyrq0 = yyrq;
  156. yyrq1 = yyrq0;
  157. yyrq2 = yyrq0;
  158. yychar = yylex();
  159. if (yychar < 0)
  160. yychar = 0;
  161. else yychar = YYTRANSLATE(yychar);
  162. yynewstate:
  163. if (yyssp >= yyss + YYMAXDEPTH - 1)
  164. {
  165. yyabort("Parser Stack Overflow");
  166. YYABORT;
  167. }
  168. *++yyssp = yystate;
  169. yyresume:
  170. yyn = yypact[yystate];
  171. if (yyn == YYFLAG)
  172. goto yydefault;
  173. yyn += yychar;
  174. if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar)
  175. goto yydefault;
  176. yyn = yytable[yyn];
  177. if (yyn < 0)
  178. {
  179. yyn = -yyn;
  180. goto yyreduce;
  181. }
  182. else if (yyn == 0)
  183. goto yyerrlab;
  184. yystate = yyn;
  185. yyptr = yyrq2;
  186. while (yyptr != yyrq1)
  187. {
  188. yyn = *yyptr++;
  189. yylen = yyr2[yyn];
  190. yyvsp -= yylen;
  191. yylsp -= yylen;
  192. yyguard(yyn, yyvsp, yylsp);
  193. if (yyerror)
  194. goto yysemerr;
  195. yyaction(yyn, yyvsp, yylsp);
  196. *++yyvsp = yyval;
  197. yylsp++;
  198. if (yylen == 0)
  199. {
  200. yylsp->timestamp = timeclock;
  201. yylsp->first_line = yytloc.first_line;
  202. yylsp->first_column = yytloc.first_column;
  203. yylsp->last_line = (yylsp-1)->last_line;
  204. yylsp->last_column = (yylsp-1)->last_column;
  205. yylsp->text = 0;
  206. }
  207. else
  208. {
  209. yylsp->last_line = (yylsp+yylen-1)->last_line;
  210. yylsp->last_column = (yylsp+yylen-1)->last_column;
  211. }
  212. if (yyptr == yyrq + YYMAXRULES)
  213. yyptr = yyrq;
  214. }
  215. if (yystate == YYFINAL)
  216. YYACCEPT;
  217. yyrq2 = yyptr;
  218. yyrq1 = yyrq0;
  219. *++yyvsp = yytval;
  220. *++yylsp = yytloc;
  221. yytval = yylval;
  222. yytloc = yylloc;
  223. yyget();
  224. goto yynewstate;
  225. yydefault:
  226. yyn = yydefact[yystate];
  227. if (yyn == 0)
  228. goto yyerrlab;
  229. yyreduce:
  230. *yyrq0++ = yyn;
  231. if (yyrq0 == yyrq + YYMAXRULES)
  232. yyrq0 = yyrq;
  233. if (yyrq0 == yyrq2)
  234. {
  235. yyabort("Parser Rule Queue Overflow");
  236. YYABORT;
  237. }
  238. yyssp -= yyr2[yyn];
  239. yyn = yyr1[yyn];
  240. yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  241. if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  242. yystate = yytable[yystate];
  243. else
  244. yystate = yydefgoto[yyn - YYNTBASE];
  245. goto yynewstate;
  246. yysemerr:
  247. *--yyptr = yyn;
  248. yyrq2 = yyptr;
  249. yyvsp += yyr2[yyn];
  250. yyerrlab:
  251. yygssp = yyssp;
  252. yygvsp = yyvsp;
  253. yyglsp = yylsp;
  254. yyrestore(yyrq0, yyrq2);
  255. yyrecover();
  256. yystate = *yygssp;
  257. yyssp = yygssp;
  258. yyvsp = yygvsp;
  259. yyrq0 = yyrq;
  260. yyrq1 = yyrq0;
  261. yyrq2 = yyrq0;
  262. goto yyresume;
  263. }
  264. $