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.

693 lines
15 KiB

  1. // Copyright (c) 1993-1999 Microsoft Corporation
  2. /*
  3. * Created by CSD YACC (IBM PC) from "gram.y" */
  4. /****************************************************************************
  5. *** local defines
  6. ***************************************************************************/
  7. #define pascal
  8. #define FARDATA
  9. #define NEARDATA
  10. #define FARCODE
  11. #define NEARCODE
  12. #define NEARSWAP
  13. #define PASCAL pascal
  14. #define CDECL
  15. #define VOID void
  16. #define CONST const
  17. #define GLOBAL
  18. #define YYSTYPE lextype_t
  19. #define YYNEAR NEARCODE
  20. #define YYPASCAL PASCAL
  21. #define YYPRINT printf
  22. #define YYSTATIC static
  23. #define YYLEX yylex
  24. #define YYPARSER yyparse
  25. #define MAXARRAY 1000
  26. #define CASE_BUFFER_SIZE 10000
  27. #define CASE_FN_FORMAT ("\nvoid\n%s_case_fn_%.4d()")
  28. #define DISPATCH_ENTRY_FORMAT ("\n\t,%s_case_fn_%.4d")
  29. #define DISPATCH_FIRST_ENTRY ("\n\t %s_case_fn_%.4d")
  30. /****************************************************************************
  31. *** include files
  32. ***************************************************************************/
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <ctype.h>
  37. #include <assert.h>
  38. #include "lex.h"
  39. /****************************************************************************
  40. *** externals
  41. ***************************************************************************/
  42. extern int Incase;
  43. extern int ActionSensed;
  44. extern int yylex();
  45. extern int yyparse();
  46. extern char * name_prefix;
  47. /****************************************************************************
  48. *** local procs
  49. ***************************************************************************/
  50. void Init( void );
  51. void EmitCaseTableArray( void );
  52. void EmitDefaultCase( void );
  53. void EmitCaseBody( int );
  54. void RegisterCase( int );
  55. void BufferIt( char * pStr, int iLen );
  56. void ResetBuffer();
  57. void FlushBuffer();
  58. /****************************************************************************
  59. *** local data
  60. ***************************************************************************/
  61. unsigned long SavedIDCount = 0;
  62. unsigned long IDCount = 0;
  63. unsigned char CaseTable[ MAXARRAY ] = { 0 };
  64. int CaseNumber = 0;
  65. int MaxCaseNumber = 0;
  66. char * pBufStart;
  67. char * pBufCur;
  68. char * pBufEnd;
  69. # define ID 257
  70. # define NUMBER 258
  71. # define TOKEN_CASE 259
  72. # define TOKEN_CHAR 260
  73. # define TOKEN_END 261
  74. # define TOKEN_END_CASE 262
  75. # define TOKEN_MYACT 263
  76. # define TOKEN_START 264
  77. #define yyclearin yychar = -1
  78. #define yyerrok yyerrflag = 0
  79. #ifndef YYMAXDEPTH
  80. #define YYMAXDEPTH 150
  81. #endif
  82. YYSTYPE yylval, yyval;
  83. #ifndef YYFARDATA
  84. #define YYFARDATA /*nothing*/
  85. #endif
  86. #if ! defined YYSTATIC
  87. #define YYSTATIC /*nothing*/
  88. #endif
  89. #ifndef YYOPTTIME
  90. #define YYOPTTIME 0
  91. #endif
  92. #ifndef YYR_T
  93. #define YYR_T int
  94. #endif
  95. typedef YYR_T yyr_t;
  96. #ifndef YYEXIND_T
  97. #define YYEXIND_T unsigned int
  98. #endif
  99. typedef YYEXIND_T yyexind_t;
  100. #ifndef YYACT
  101. #define YYACT yyact
  102. #endif
  103. #ifndef YYPACT
  104. #define YYPACT yypact
  105. #endif
  106. #ifndef YYPGO
  107. #define YYPGO yypgo
  108. #endif
  109. #ifndef YYR1
  110. #define YYR1 yyr1
  111. #endif
  112. #ifndef YYR2
  113. #define YYR2 yyr2
  114. #endif
  115. #ifndef YYCHK
  116. #define YYCHK yychk
  117. #endif
  118. #ifndef YYDEF
  119. #define YYDEF yydef
  120. #endif
  121. #ifndef YYLOCAL
  122. #define YYLOCAL
  123. #endif
  124. # define YYERRCODE 256
  125. /*****************************************************************************
  126. * utility functions
  127. *****************************************************************************/
  128. YYSTATIC VOID FARCODE PASCAL
  129. yyerror(char *szError)
  130. {
  131. extern int Line;
  132. extern char LocalBuffer[];
  133. fprintf(stderr, "%s at Line %d near %s\n", szError, Line, LocalBuffer);
  134. }
  135. void
  136. Init()
  137. {
  138. pBufStart = pBufCur = malloc( CASE_BUFFER_SIZE );
  139. if( !pBufStart )
  140. {
  141. fprintf(stderr,"Out Of Memory\n");
  142. exit(1);
  143. }
  144. pBufEnd = pBufStart + CASE_BUFFER_SIZE;
  145. }
  146. void
  147. BufferIt(
  148. char * pStr,
  149. int iLen )
  150. {
  151. if( pBufCur + iLen > pBufEnd )
  152. {
  153. printf("ALERT iLen = %d\n", iLen );
  154. // assert( (pBufCur + iLen) <= pBufEnd );
  155. exit(1);
  156. }
  157. strncpy( pBufCur , pStr, iLen );
  158. pBufCur += iLen;
  159. *pBufCur = '\0';
  160. }
  161. void
  162. ResetBuffer()
  163. {
  164. pBufCur = pBufStart;
  165. *pBufCur= '\0';
  166. }
  167. void
  168. FlushBuffer()
  169. {
  170. fprintf(stdout, "%s", pBufStart);
  171. ResetBuffer();
  172. }
  173. void
  174. EmitCaseBody(
  175. int CaseNumber )
  176. {
  177. fprintf( stdout, CASE_FN_FORMAT, name_prefix, CaseNumber );
  178. FlushBuffer();
  179. fprintf( stdout, "}\n" );
  180. }
  181. void
  182. EmitCaseTableArray()
  183. {
  184. int i, iTemp;
  185. fprintf( stdout, "const pfn\t %s_case_fn_array[] = \n\t{", name_prefix );
  186. fprintf( stdout,DISPATCH_FIRST_ENTRY,name_prefix, 0 );
  187. for( i = 1 ; i <= MaxCaseNumber ; ++i )
  188. {
  189. iTemp = CaseTable[ i ] ? i : 0;
  190. fprintf(stdout,DISPATCH_ENTRY_FORMAT,name_prefix, iTemp );
  191. }
  192. fprintf( stdout, "\n\t};\n" );
  193. fprintf( stdout, "\nstatic void\nyy_vc_init()\n{ \n\tpcase_fn_array = (pfn *) %s_case_fn_array;\n\tyym_vc_max = %d;\n}\n" , name_prefix, MaxCaseNumber);
  194. }
  195. void
  196. EmitDefaultCase()
  197. {
  198. fprintf(stdout, "void\n%s_case_fn_%.4d() {\n\t}\n\n", name_prefix, 0 );
  199. }
  200. void
  201. RegisterCase(
  202. int iCase )
  203. {
  204. CaseTable[ iCase ] = 1;
  205. }
  206. YYSTATIC short yyexca[] ={
  207. #if !(YYOPTTIME)
  208. -1, 1,
  209. #endif
  210. 0, -1,
  211. -2, 0,
  212. };
  213. # define YYNPROD 16
  214. #if YYOPTTIME
  215. YYSTATIC yyexind_t yyexcaind[] = {
  216. 0,
  217. 0,
  218. };
  219. #endif
  220. # define YYLAST 39
  221. YYSTATIC short YYFARDATA YYACT[]={
  222. 8, 13, 28, 6, 7, 16, 5, 25, 23, 21,
  223. 24, 2, 20, 4, 3, 26, 19, 9, 15, 12,
  224. 10, 1, 11, 0, 14, 0, 0, 17, 18, 0,
  225. 0, 0, 22, 0, 0, 0, 0, 0, 27 };
  226. YYSTATIC short YYFARDATA YYPACT[]={
  227. -254,-1000,-264,-254,-1000,-1000,-1000,-1000,-1000,-1000,
  228. -254,-262,-254,-1000,-256,-254,-254,-250,-1000,-250,
  229. -1000,-252,-1000,-248,-253,-1000,-254,-260,-1000 };
  230. YYSTATIC short YYFARDATA YYPGO[]={
  231. 0, 21, 11, 20, 19, 18, 16, 12, 15, 14,
  232. 13 };
  233. YYSTATIC yyr_t YYFARDATA YYR1[]={
  234. 0, 3, 1, 5, 4, 6, 6, 8, 7, 2,
  235. 2, 9, 9, 10, 10, 10 };
  236. YYSTATIC yyr_t YYFARDATA YYR2[]={
  237. 0, 0, 8, 0, 4, 2, 1, 0, 7, 1,
  238. 0, 2, 1, 1, 1, 1 };
  239. YYSTATIC short YYFARDATA YYCHK[]={
  240. -1000, -1, -2, -9, -10, 260, 257, 258, 264, -10,
  241. -3, -2, -4, 263, -2, -5, 261, -2, -2, -6,
  242. -7, 259, -7, 260, 258, 260, -8, -2, 262 };
  243. YYSTATIC short YYFARDATA YYDEF[]={
  244. 10, -2, 0, 9, 12, 13, 14, 15, 1, 11,
  245. 10, 0, 10, 3, 0, 10, 10, 0, 2, 4,
  246. 6, 0, 5, 0, 0, 7, 10, 0, 8 };
  247. #ifdef YYRECOVER
  248. YYSTATIC short yyrecover[] = {
  249. -1000 };
  250. #endif
  251. /* SCCSWHAT( "@(#)yypars.c 2.4 88/05/09 15:22:59 " ) */
  252. static char *SCCSID = "@(#)yypars.c:1.3";
  253. # define YYFLAG -1000
  254. # define YYERROR goto yyerrlab
  255. # define YYACCEPT return(0)
  256. # define YYABORT return(1)
  257. #ifdef YYDEBUG /* RRR - 10/9/85 */
  258. #define yyprintf(a, b, c, d, e) printf(a, b, c, d, e)
  259. #else
  260. #define yyprintf(a, b, c, d)
  261. #endif
  262. #ifndef YYPRINT
  263. #define YYPRINT printf
  264. #endif
  265. #if ! defined YYSTATIC
  266. #define YYSTATIC
  267. #endif
  268. /* parser for yacc output */
  269. #ifdef YYDEBUG
  270. YYSTATIC int yydebug = 0; /* 1 for debugging */
  271. #endif
  272. YYSTATIC YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  273. YYSTATIC short yys[YYMAXDEPTH]; /* the parse stack */
  274. YYSTATIC int yychar = -1; /* current input token number */
  275. YYSTATIC int yynerrs = 0; /* number of errors */
  276. YYSTATIC short yyerrflag = 0; /* error recovery flag */
  277. short yyexpected;
  278. #ifdef YYRECOVER
  279. /*
  280. ** yyscpy : copy f onto t and return a ptr to the null terminator at the
  281. ** end of t.
  282. */
  283. YYSTATIC char *yyscpy(t,f)
  284. register char *t, *f;
  285. {
  286. while(*t = *f++)
  287. t++;
  288. return(t); /* ptr to the null char */
  289. }
  290. #endif
  291. #ifndef YYNEAR
  292. #define YYNEAR
  293. #endif
  294. #ifndef YYPASCAL
  295. #define YYPASCAL
  296. #endif
  297. #ifndef YYLOCAL
  298. #define YYLOCAL
  299. #endif
  300. #if ! defined YYPARSER
  301. #define YYPARSER yyparse
  302. #endif
  303. #if ! defined YYLEX
  304. #define YYLEX yylex
  305. #endif
  306. #ifdef VC_ERRORS
  307. static short yysavestate = 0;
  308. #endif
  309. YYLOCAL YYNEAR YYPASCAL YYPARSER()
  310. {
  311. register short yyn;
  312. short yystate, *yyps;
  313. YYSTYPE *yypv;
  314. short yyj, yym;
  315. #ifdef YYDEBUG
  316. yydebug = 1;
  317. #endif // YYDEBUG
  318. yystate = 0;
  319. yychar = -1;
  320. yynerrs = 0;
  321. yyerrflag = 0;
  322. yyps= &yys[-1];
  323. yypv= &yyv[-1];
  324. yystack: /* put a state and value onto the stack */
  325. #ifdef YYDEBUG
  326. yyprintf( "[yydebug] state %d, char %d = %c\n", yystate, yychar,yychar, 0 );
  327. #else // YYDEBUG
  328. yyprintf( "[yydebug] state %d, char %d\n", yystate, yychar, 0 );
  329. #endif // YYDEBUG
  330. if( ++yyps > &yys[YYMAXDEPTH] ) {
  331. #ifdef VC_ERRORS
  332. yyerror( "yacc stack overflow", -1 );
  333. #else // VC_ERRORS
  334. yyerror( "yacc stack overflow");
  335. #endif // VC_ERRORS
  336. return(1);
  337. }
  338. *yyps = yystate;
  339. ++yypv;
  340. #ifdef UNION
  341. yyunion(yypv, &yyval);
  342. #else
  343. *yypv = yyval;
  344. #endif
  345. yynewstate:
  346. #ifdef VC_ERRORS
  347. yysavestate = yystate;
  348. #endif
  349. yyn = yypact[yystate];
  350. yyexpected = -yyn;
  351. if( yyn <= YYFLAG ) { /* simple state, no lookahead */
  352. goto yydefault;
  353. }
  354. if( yychar < 0 ) { /* need a lookahead */
  355. yychar = YYLEX();
  356. }
  357. if( ((yyn += (short) yychar) < 0) || (yyn >= YYLAST) ) {
  358. goto yydefault;
  359. }
  360. if( yychk[ yyn = yyact[ yyn ] ] == yychar ) { /* valid shift */
  361. yychar = -1;
  362. #ifdef UNION
  363. yyunion(&yyval, &yylval);
  364. #else
  365. yyval = yylval;
  366. #endif
  367. yystate = yyn;
  368. if( yyerrflag > 0 ) {
  369. --yyerrflag;
  370. }
  371. goto yystack;
  372. }
  373. yydefault:
  374. /* default state action */
  375. if( (yyn = yydef[yystate]) == -2 ) {
  376. register short *yyxi;
  377. if( yychar < 0 ) {
  378. yychar = YYLEX();
  379. }
  380. /*
  381. ** search exception table, we find a -1 followed by the current state.
  382. ** if we find one, we'll look through terminal,state pairs. if we find
  383. ** a terminal which matches the current one, we have a match.
  384. ** the exception table is when we have a reduce on a terminal.
  385. */
  386. #if YYOPTTIME
  387. yyxi = yyexca + yyexcaind[yystate];
  388. while(( *yyxi != yychar ) && ( *yyxi >= 0 )){
  389. yyxi += 2;
  390. }
  391. #else
  392. for(yyxi = yyexca;
  393. (*yyxi != (-1)) || (yyxi[1] != yystate);
  394. yyxi += 2
  395. ) {
  396. ; /* VOID */
  397. }
  398. while( *(yyxi += 2) >= 0 ){
  399. if( *yyxi == yychar ) {
  400. break;
  401. }
  402. }
  403. #endif
  404. if( (yyn = yyxi[1]) < 0 ) {
  405. return(0); /* accept */
  406. }
  407. }
  408. if( yyn == 0 ){ /* error */
  409. /* error ... attempt to resume parsing */
  410. switch( yyerrflag ){
  411. case 0: /* brand new error */
  412. #ifdef YYRECOVER
  413. {
  414. register int i,j;
  415. for(i = 0;
  416. (yyrecover[i] != -1000) && (yystate > yyrecover[i]);
  417. i += 3
  418. ) {
  419. ;
  420. }
  421. if(yystate == yyrecover[i]) {
  422. #ifdef YYDEBUG
  423. yyprintf("recovered, from state %d to state %d on token %d\n",
  424. yystate,yyrecover[i+2],yyrecover[i+1], 0
  425. );
  426. #else // YYDEBUG
  427. yyprintf("recovered, from state %d to state %d on token %d\n",
  428. yystate,yyrecover[i+2],yyrecover[i+1]
  429. );
  430. #endif // YYDEBUG
  431. j = yyrecover[i + 1];
  432. if(j < 0) {
  433. /*
  434. ** here we have one of the injection set, so we're not quite
  435. ** sure that the next valid thing will be a shift. so we'll
  436. ** count it as an error and continue.
  437. ** actually we're not absolutely sure that the next token
  438. ** we were supposed to get is the one when j > 0. for example,
  439. ** for(+) {;} error recovery with yyerrflag always set, stops
  440. ** after inserting one ; before the +. at the point of the +,
  441. ** we're pretty sure the guy wants a 'for' loop. without
  442. ** setting the flag, when we're almost absolutely sure, we'll
  443. ** give him one, since the only thing we can shift on this
  444. ** error is after finding an expression followed by a +
  445. */
  446. yyerrflag++;
  447. j = -j;
  448. }
  449. if(yyerrflag <= 1) { /* only on first insertion */
  450. yyrecerr(yychar,j); /* what was, what should be first */
  451. }
  452. yyval = yyeval(j);
  453. yystate = yyrecover[i + 2];
  454. goto yystack;
  455. }
  456. }
  457. #endif
  458. #ifdef VC_ERRORS
  459. yyerror("syntax error", yysavestate);
  460. #else
  461. yyerror("syntax error");
  462. #endif
  463. // yyerrlab:
  464. ++yynerrs;
  465. case 1:
  466. case 2: /* incompletely recovered error ... try again */
  467. yyerrflag = 3;
  468. /* find a state where "error" is a legal shift action */
  469. while ( yyps >= yys ) {
  470. yyn = yypact[*yyps] + YYERRCODE;
  471. if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
  472. yystate = yyact[yyn]; /* simulate a shift of "error" */
  473. goto yystack;
  474. }
  475. yyn = yypact[*yyps];
  476. /* the current yyps has no shift onn "error", pop stack */
  477. #ifdef YYDEBUG
  478. yyprintf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1], 0, 0 );
  479. #else // YYDEBUG
  480. yyprintf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1], 0 );
  481. #endif // YYDEBUG
  482. --yyps;
  483. --yypv;
  484. }
  485. /* there is no state on the stack with an error shift ... abort */
  486. yyabort:
  487. return(1);
  488. case 3: /* no shift yet; clobber input char */
  489. #ifdef YYDEBUG
  490. yyprintf( "error recovery discards char %d\n", yychar, 0, 0, 0 );
  491. #else // YYDEBUG
  492. yyprintf( "error recovery discards char %d\n", yychar, 0, 0 );
  493. #endif // YYDEBUG
  494. if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
  495. yychar = -1;
  496. goto yynewstate; /* try again in the same state */
  497. }
  498. }
  499. /* reduction by production yyn */
  500. // yyreduce:
  501. {
  502. register YYSTYPE *yypvt;
  503. #ifdef YYDEBUG
  504. yyprintf("[yydebug] reduce %d\n",yyn, 0, 0, 0);
  505. #else // YYDEBUG
  506. yyprintf("[yydebug] reduce %d\n",yyn, 0, 0);
  507. #endif // YYDEBUG
  508. yypvt = yypv;
  509. yyps -= yyr2[yyn];
  510. yypv -= yyr2[yyn];
  511. #ifdef UNION
  512. yyunion(&yyval, &yypv[1]);
  513. #else
  514. yyval = yypv[1];
  515. #endif
  516. yym = yyn;
  517. yyn = (short) yyr1[yyn]; /* consult goto table to find next state */
  518. yyj = yypgo[yyn] + *yyps + 1;
  519. if( (yyj >= YYLAST) || (yychk[ yystate = yyact[yyj] ] != -yyn) ) {
  520. yystate = yyact[yypgo[yyn]];
  521. }
  522. switch(yym){
  523. case 1:
  524. {
  525. Init();
  526. } break;
  527. case 2:
  528. {
  529. EmitDefaultCase();
  530. EmitCaseTableArray();
  531. } break;
  532. case 3:
  533. {
  534. ActionSensed++;
  535. ResetBuffer();
  536. } break;
  537. case 4:
  538. {
  539. } break;
  540. case 5:
  541. {
  542. } break;
  543. case 6:
  544. {
  545. } break;
  546. case 7:
  547. {
  548. Incase = 1;
  549. CaseNumber = yypvt[-1].yynumber;
  550. if(yypvt[-1].yynumber >= MAXARRAY)
  551. {
  552. fprintf(stderr, "Case Limit Reached : Contact Dov/Vibhas\n");
  553. return 1;
  554. }
  555. SavedIDCount = IDCount;
  556. } break;
  557. case 8:
  558. {
  559. if(SavedIDCount != IDCount)
  560. {
  561. RegisterCase( CaseNumber );
  562. EmitCaseBody( CaseNumber );
  563. }
  564. ResetBuffer();
  565. if(CaseNumber > MaxCaseNumber)
  566. MaxCaseNumber = CaseNumber;
  567. Incase = 0;
  568. } break;
  569. case 9:
  570. {
  571. } break;
  572. case 10:
  573. {
  574. } break;
  575. case 11:
  576. {
  577. } break;
  578. case 12:
  579. {
  580. } break;
  581. case 13:
  582. {
  583. if(!ActionSensed)
  584. fprintf(stdout, "%c", yypvt[-0].yycharval);
  585. else
  586. BufferIt( &yypvt[-0].yycharval, 1);
  587. } break;
  588. case 14:
  589. {
  590. IDCount++;
  591. if(!ActionSensed)
  592. fprintf(stdout, "%s", yypvt[-0].yystring);
  593. else
  594. BufferIt( yypvt[-0].yystring, strlen(yypvt[-0].yystring) );
  595. } break;
  596. case 15:
  597. {
  598. if(!ActionSensed)
  599. fprintf(stdout, "%d", yypvt[-0].yynumber);
  600. else
  601. {
  602. char buffer[20];
  603. sprintf(buffer,"%d", yypvt[-0].yynumber );
  604. BufferIt( buffer, strlen(buffer) );
  605. }
  606. } break;/* End of actions */
  607. }
  608. }
  609. goto yystack; /* stack new state and value */
  610. }