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.

80 lines
2.2 KiB

  1. // Copyright (c) 1993-1999 Microsoft Corporation
  2. #include "y1.h"
  3. int
  4. state( SSIZE_T c)
  5. {
  6. /* sorts last state,and sees if it equals earlier ones. returns state number */
  7. SSIZE_T size1,size2;
  8. register i;
  9. SSIZE_T *s; /*01*/
  10. struct looksets *ss; /*01*/
  11. int s__; /*01*/
  12. struct item *p1, *p2, *k, *l, *q1, *q2;
  13. p1 = pstate[nstate];
  14. p2 = pstate[nstate+1];
  15. if(p1==p2) return(0); /* null state */
  16. /* sort the items */
  17. for(k=p2-1;k>p1;k--)
  18. {
  19. /* make k the biggest */
  20. for(l=k-1;l>=p1;--l)if( l->pitem > k->pitem )
  21. {
  22. s = k->pitem;
  23. k->pitem = l->pitem;
  24. l->pitem = s;
  25. ss = k->look;
  26. k->look = l->look;
  27. l->look = ss;
  28. }
  29. }
  30. size1 = p2 - p1; /* size of state */
  31. for( i= (c>=NTBASE)?ntstates[c-NTBASE]:tstates[c]; i != 0; i = mstates[i] )
  32. {
  33. /* get ith state */
  34. q1 = pstate[i];
  35. q2 = pstate[i+1];
  36. size2 = q2 - q1;
  37. if (size1 != size2) continue;
  38. k=p1;
  39. for(l=q1;l<q2;l++)
  40. {
  41. if( l->pitem != k->pitem ) break;
  42. ++k;
  43. }
  44. if (l != q2) continue;
  45. /* found it */
  46. pstate[nstate+1] = pstate[nstate]; /* delete last state */
  47. /* fix up lookaheads */
  48. if( nolook ) return(i);
  49. for( l=q1,k=p1; l<q2; ++l,++k )
  50. {
  51. SETLOOP(s__) clset.lset[s__] = l->look->lset[s__];
  52. if( setunion( clset.lset, k->look->lset ) )
  53. {
  54. tystate[i] = MUSTDO;
  55. /* register the new set */
  56. l->look = flset( &clset );
  57. }
  58. }
  59. return (i);
  60. }
  61. /* state is new */
  62. if( nolook ) error( "yacc state/nolook error" );
  63. pstate[nstate+2] = p2;
  64. if(nstate+1 >= NSTATES) error("too many states" );
  65. if( c >= NTBASE )
  66. {
  67. mstates[ nstate ] = ntstates[ c-NTBASE ];
  68. ntstates[ c-NTBASE ] = nstate;
  69. }
  70. else
  71. {
  72. mstates[ nstate ] = tstates[ c ];
  73. tstates[ c ] = nstate;
  74. }
  75. tystate[nstate]=MUSTDO;
  76. return(nstate++);
  77. }