Windows NT 4.0 source code leak
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.

82 lines
2.0 KiB

4 years ago
  1. #include <stdlib.h>
  2. #include "y1.h"
  3. /*
  4. * 12-Apr-83 (RBD) Add symbolic exit status
  5. */
  6. void cempty(void)
  7. {
  8. /* mark nonterminals which derive the empty string */
  9. /* also, look for nonterminals which don't derive any token strings */
  10. # define EMPTY 1
  11. # define WHOKNOWS 0
  12. # define OK 1
  13. register i, *p;
  14. /* first, use the array pempty to detect productions that can never be reduced */
  15. /* set pempty to WHONOWS */
  16. aryfil( pempty, nnonter+1, WHOKNOWS );
  17. /* now, look at productions, marking nonterminals which derive something */
  18. more:
  19. PLOOP(0,i)
  20. {
  21. if( pempty[ *prdptr[i] - NTBASE ] ) continue;
  22. for( p=prdptr[i]+1; *p>=0; ++p )
  23. {
  24. if( *p>=NTBASE && pempty[ *p-NTBASE ] == WHOKNOWS ) break;
  25. }
  26. if( *p < 0 )
  27. {
  28. /* production can be derived */
  29. pempty[ *prdptr[i]-NTBASE ] = OK;
  30. goto more;
  31. }
  32. }
  33. /* now, look at the nonterminals, to see if they are all OK */
  34. NTLOOP(i)
  35. {
  36. /* the added production rises or falls as the start symbol ... */
  37. if( i == 0 ) continue;
  38. if( pempty[ i ] != OK )
  39. {
  40. fatfl = 0;
  41. error( "nonterminal %s never derives any token string", nontrst[i].name );
  42. }
  43. }
  44. if( nerrors )
  45. {
  46. summary();
  47. exit(EX_ERR);
  48. }
  49. /* now, compute the pempty array, to see which nonterminals derive the empty string */
  50. /* set pempty to WHOKNOWS */
  51. aryfil( pempty, nnonter+1, WHOKNOWS );
  52. /* loop as long as we keep finding empty nonterminals */
  53. again:
  54. PLOOP(1,i)
  55. {
  56. if( pempty[ *prdptr[i]-NTBASE ]==WHOKNOWS )
  57. {
  58. /* not known to be empty */
  59. for( p=prdptr[i]+1; *p>=NTBASE && pempty[*p-NTBASE]==EMPTY ; ++p ) ;
  60. if( *p < 0 )
  61. {
  62. /* we have a nontrivially empty nonterminal */
  63. pempty[*prdptr[i]-NTBASE] = EMPTY;
  64. goto again; /* got one ... try for another */
  65. }
  66. }
  67. }
  68. }