Source code of Windows XP (NT5)
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.

86 lines
2.1 KiB

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