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.

153 lines
3.4 KiB

  1. // Copyright (c) 1993-1999 Microsoft Corporation
  2. #include "y1.h"
  3. /*
  4. * yclsur.1c
  5. *
  6. * Modified to make debug code conditionally compile.
  7. * 28-Aug-81
  8. * Bob Denny
  9. */
  10. void
  11. closure( int i)
  12. {
  13. /* generate the closure of state i */
  14. int work, k;
  15. SSIZE_T ch, c;
  16. register struct wset *u, *v;
  17. SSIZE_T *pi;
  18. SSIZE_T **s, **t;
  19. struct item *q;
  20. register struct item *p;
  21. ++zzclose;
  22. /* first, copy kernel of state i to wsets */
  23. cwp = wsets;
  24. ITMLOOP(i,p,q)
  25. {
  26. cwp->pitem = p->pitem;
  27. cwp->flag = 1; /* this item must get closed */
  28. SETLOOP(k) cwp->ws.lset[k] = p->look->lset[k];
  29. WSBUMP(cwp);
  30. }
  31. /* now, go through the loop, closing each item */
  32. work = 1;
  33. while( work )
  34. {
  35. work = 0;
  36. WSLOOP(wsets,u)
  37. {
  38. if( u->flag == 0 ) continue;
  39. c = *(u->pitem); /* dot is before c */
  40. if( c < NTBASE )
  41. {
  42. u->flag = 0;
  43. continue; /* only interesting case is where . is before nonterminal */
  44. }
  45. /* compute the lookahead */
  46. aryfil( clset.lset, tbitset, 0 );
  47. /* find items involving c */
  48. WSLOOP(u,v)
  49. {
  50. if( v->flag == 1 && *(pi=v->pitem) == c )
  51. {
  52. v->flag = 0;
  53. if( nolook ) continue;
  54. while( (ch= *++pi)>0 )
  55. {
  56. if( ch < NTBASE )
  57. {
  58. /* terminal symbol */
  59. SETBIT( clset.lset, ch );
  60. break;
  61. }
  62. /* nonterminal symbol */
  63. setunion( clset.lset, pfirst[ch-NTBASE]->lset );
  64. if( !pempty[ch-NTBASE] ) break;
  65. }
  66. if( ch<=0 ) setunion( clset.lset, v->ws.lset );
  67. }
  68. }
  69. /* now loop over productions derived from c */
  70. c -= NTBASE; /* c is now nonterminal number */
  71. t = pres[c+1];
  72. for( s=pres[c]; s<t; ++s )
  73. {
  74. /* put these items into the closure */
  75. WSLOOP(wsets,v)
  76. {
  77. /* is the item there */
  78. if( v->pitem == *s )
  79. {
  80. /* yes, it is there */
  81. if( nolook ) goto nexts;
  82. if( setunion( v->ws.lset, clset.lset ) ) v->flag = work = 1;
  83. goto nexts;
  84. }
  85. }
  86. /* not there; make a new entry */
  87. if( cwp-wsets+1 >= WSETSIZE ) error( "working set overflow" );
  88. cwp->pitem = *s;
  89. cwp->flag = 1;
  90. if( !nolook )
  91. {
  92. work = 1;
  93. SETLOOP(k) cwp->ws.lset[k] = clset.lset[k];
  94. }
  95. WSBUMP(cwp);
  96. nexts:
  97. ;
  98. }
  99. }
  100. }
  101. /* have computed closure; flags are reset; return */
  102. if( cwp > zzcwp ) zzcwp = cwp;
  103. #ifdef debug
  104. if( foutput!=NULL )
  105. {
  106. fprintf( foutput, "\nState %d, nolook = %d\n", i, nolook );
  107. WSLOOP(wsets,u)
  108. {
  109. if( u->flag ) fprintf( foutput, "flag set!\n");
  110. u->flag = 0;
  111. fprintf( foutput, "\t%s", writem(u->pitem));
  112. prlook( &u->ws );
  113. fprintf( foutput, "\n" );
  114. }
  115. }
  116. #endif
  117. }