bison.hairy 6.3 KB

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