Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

314 lines
7.2 KiB

  1. /* SCCSWHAT( "@(#)yypars.c 2.4 88/05/09 15:22:59 " ) */
  2. static char *SCCSID = "@(#)yypars.c:1.3";
  3. # define YYFLAG -1000
  4. # define YYERROR goto yyerrlab
  5. # define YYACCEPT return(0)
  6. # define YYABORT return(1)
  7. #ifdef YYDEBUG /* RRR - 10/9/85 */
  8. #define yyprintf(a, b, c, d, e) printf(a, b, c, d, e)
  9. #else
  10. #define yyprintf(a, b, c, d)
  11. #endif
  12. #ifndef YYPRINT
  13. #define YYPRINT printf
  14. #endif
  15. #if ! defined YYSTATIC
  16. #define YYSTATIC
  17. #endif
  18. /* parser for yacc output */
  19. #ifdef YYDEBUG
  20. YYSTATIC int yydebug = 0; /* 1 for debugging */
  21. #endif
  22. YYSTATIC YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  23. YYSTATIC short yys[YYMAXDEPTH]; /* the parse stack */
  24. YYSTATIC int yychar = -1; /* current input token number */
  25. YYSTATIC int yynerrs = 0; /* number of errors */
  26. YYSTATIC short yyerrflag = 0; /* error recovery flag */
  27. short yyexpected;
  28. #ifdef YYRECOVER
  29. /*
  30. ** yyscpy : copy f onto t and return a ptr to the null terminator at the
  31. ** end of t.
  32. */
  33. YYSTATIC char *yyscpy(t,f)
  34. register char *t, *f;
  35. {
  36. while(*t = *f++)
  37. t++;
  38. return(t); /* ptr to the null char */
  39. }
  40. #endif
  41. #ifndef YYNEAR
  42. #define YYNEAR
  43. #endif
  44. #ifndef YYPASCAL
  45. #define YYPASCAL
  46. #endif
  47. #ifndef YYLOCAL
  48. #define YYLOCAL
  49. #endif
  50. #if ! defined YYPARSER
  51. #define YYPARSER yyparse
  52. #endif
  53. #if ! defined YYLEX
  54. #define YYLEX yylex
  55. #endif
  56. #ifdef VC_ERRORS
  57. static short yysavestate = 0;
  58. #endif
  59. YYLOCAL YYNEAR YYPASCAL YYPARSER()
  60. {
  61. register short yyn;
  62. short yystate, *yyps;
  63. YYSTYPE *yypv;
  64. short yyj, yym;
  65. #ifdef YYDEBUG
  66. yydebug = 1;
  67. #endif // YYDEBUG
  68. yystate = 0;
  69. yychar = -1;
  70. yynerrs = 0;
  71. yyerrflag = 0;
  72. yyps= &yys[-1];
  73. yypv= &yyv[-1];
  74. yystack: /* put a state and value onto the stack */
  75. #ifdef YYDEBUG
  76. yyprintf( "[yydebug] state %d, char %d = %c\n", yystate, yychar,yychar, 0 );
  77. #else // YYDEBUG
  78. yyprintf( "[yydebug] state %d, char %d\n", yystate, yychar, 0 );
  79. #endif // YYDEBUG
  80. if( ++yyps > &yys[YYMAXDEPTH] ) {
  81. yyerror( "yacc stack overflow" );
  82. return(1);
  83. }
  84. *yyps = yystate;
  85. ++yypv;
  86. #ifdef UNION
  87. yyunion(yypv, &yyval);
  88. #else
  89. *yypv = yyval;
  90. #endif
  91. yynewstate:
  92. #ifdef VC_ERRORS
  93. yysavestate = yystate;
  94. #endif
  95. yyn = yypact[yystate];
  96. yyexpected = -yyn;
  97. if( yyn <= YYFLAG ) { /* simple state, no lookahead */
  98. goto yydefault;
  99. }
  100. if( yychar < 0 ) { /* need a lookahead */
  101. yychar = YYLEX();
  102. }
  103. if( ((yyn += yychar) < 0) || (yyn >= YYLAST) ) {
  104. goto yydefault;
  105. }
  106. if( yychk[ yyn = yyact[ yyn ] ] == yychar ) { /* valid shift */
  107. yychar = -1;
  108. #ifdef UNION
  109. yyunion(&yyval, &yylval);
  110. #else
  111. yyval = yylval;
  112. #endif
  113. yystate = yyn;
  114. if( yyerrflag > 0 ) {
  115. --yyerrflag;
  116. }
  117. goto yystack;
  118. }
  119. yydefault:
  120. /* default state action */
  121. if( (yyn = yydef[yystate]) == -2 ) {
  122. register short *yyxi;
  123. if( yychar < 0 ) {
  124. yychar = YYLEX();
  125. }
  126. /*
  127. ** search exception table, we find a -1 followed by the current state.
  128. ** if we find one, we'll look through terminal,state pairs. if we find
  129. ** a terminal which matches the current one, we have a match.
  130. ** the exception table is when we have a reduce on a terminal.
  131. */
  132. #if YYOPTTIME
  133. yyxi = yyexca + yyexcaind[yystate];
  134. while(( *yyxi != yychar ) && ( *yyxi >= 0 )){
  135. yyxi += 2;
  136. }
  137. #else
  138. for(yyxi = yyexca;
  139. (*yyxi != (-1)) || (yyxi[1] != yystate);
  140. yyxi += 2
  141. ) {
  142. ; /* VOID */
  143. }
  144. while( *(yyxi += 2) >= 0 ){
  145. if( *yyxi == yychar ) {
  146. break;
  147. }
  148. }
  149. #endif
  150. if( (yyn = yyxi[1]) < 0 ) {
  151. return(0); /* accept */
  152. }
  153. }
  154. if( yyn == 0 ){ /* error */
  155. /* error ... attempt to resume parsing */
  156. switch( yyerrflag ){
  157. case 0: /* brand new error */
  158. #ifdef YYRECOVER
  159. {
  160. register int i,j;
  161. for(i = 0;
  162. (yyrecover[i] != -1000) && (yystate > yyrecover[i]);
  163. i += 3
  164. ) {
  165. ;
  166. }
  167. if(yystate == yyrecover[i]) {
  168. #ifdef YYDEBUG
  169. yyprintf("recovered, from state %d to state %d on token %d\n",
  170. yystate,yyrecover[i+2],yyrecover[i+1], 0
  171. );
  172. #else // YYDEBUG
  173. yyprintf("recovered, from state %d to state %d on token %d\n",
  174. yystate,yyrecover[i+2],yyrecover[i+1]
  175. );
  176. #endif // YYDEBUG
  177. j = yyrecover[i + 1];
  178. if(j < 0) {
  179. /*
  180. ** here we have one of the injection set, so we're not quite
  181. ** sure that the next valid thing will be a shift. so we'll
  182. ** count it as an error and continue.
  183. ** actually we're not absolutely sure that the next token
  184. ** we were supposed to get is the one when j > 0. for example,
  185. ** for(+) {;} error recovery with yyerrflag always set, stops
  186. ** after inserting one ; before the +. at the point of the +,
  187. ** we're pretty sure the guy wants a 'for' loop. without
  188. ** setting the flag, when we're almost absolutely sure, we'll
  189. ** give him one, since the only thing we can shift on this
  190. ** error is after finding an expression followed by a +
  191. */
  192. yyerrflag++;
  193. j = -j;
  194. }
  195. if(yyerrflag <= 1) { /* only on first insertion */
  196. yyrecerr(yychar,j); /* what was, what should be first */
  197. }
  198. yyval = yyeval(j);
  199. yystate = yyrecover[i + 2];
  200. goto yystack;
  201. }
  202. }
  203. #endif
  204. #ifdef VC_ERRORS
  205. yyerror("syntax error", yysavestate);
  206. #else
  207. yyerror("syntax error");
  208. #endif
  209. yyerrlab:
  210. ++yynerrs;
  211. case 1:
  212. case 2: /* incompletely recovered error ... try again */
  213. yyerrflag = 3;
  214. /* find a state where "error" is a legal shift action */
  215. while ( yyps >= yys ) {
  216. yyn = yypact[*yyps] + YYERRCODE;
  217. if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
  218. yystate = yyact[yyn]; /* simulate a shift of "error" */
  219. goto yystack;
  220. }
  221. yyn = yypact[*yyps];
  222. /* the current yyps has no shift onn "error", pop stack */
  223. #ifdef YYDEBUG
  224. yyprintf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1], 0, 0 );
  225. #else // YYDEBUG
  226. yyprintf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1], 0 );
  227. #endif // YYDEBUG
  228. --yyps;
  229. --yypv;
  230. }
  231. /* there is no state on the stack with an error shift ... abort */
  232. yyabort:
  233. return(1);
  234. case 3: /* no shift yet; clobber input char */
  235. #ifdef YYDEBUG
  236. yyprintf( "error recovery discards char %d\n", yychar, 0, 0, 0 );
  237. #else // YYDEBUG
  238. yyprintf( "error recovery discards char %d\n", yychar, 0, 0 );
  239. #endif // YYDEBUG
  240. if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
  241. yychar = -1;
  242. goto yynewstate; /* try again in the same state */
  243. }
  244. }
  245. /* reduction by production yyn */
  246. yyreduce:
  247. {
  248. register YYSTYPE *yypvt;
  249. #ifdef YYDEBUG
  250. yyprintf("[yydebug] reduce %d\n",yyn, 0, 0, 0);
  251. #else // YYDEBUG
  252. yyprintf("[yydebug] reduce %d\n",yyn, 0, 0);
  253. #endif // YYDEBUG
  254. yypvt = yypv;
  255. yyps -= yyr2[yyn];
  256. yypv -= yyr2[yyn];
  257. #ifdef UNION
  258. yyunion(&yyval, &yypv[1]);
  259. #else
  260. yyval = yypv[1];
  261. #endif
  262. yym = yyn;
  263. yyn = yyr1[yyn]; /* consult goto table to find next state */
  264. yyj = yypgo[yyn] + *yyps + 1;
  265. if( (yyj >= YYLAST) || (yychk[ yystate = yyact[yyj] ] != -yyn) ) {
  266. yystate = yyact[yypgo[yyn]];
  267. }
  268. switch(yym){
  269. $A
  270. }
  271. }
  272. goto yystack; /* stack new state and value */
  273. }