home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / comm / yaccunx / ycpuni.2c < prev    next >
Encoding:
Text File  |  1983-12-26  |  994 b   |  43 lines

  1. #include "y2.h"
  2.  
  3. cpyunion()
  4.    {
  5.    /* copy the union declaration to the output, and the define file if present */
  6.  
  7.    int level, c;
  8.    fprintf( ftable, "\n# line %d\n", lineno );
  9.    fprintf( ftable, "\n#define UNION 1\n");
  10.    fprintf( ftable, "typedef union " );
  11.    if( fdefine ) fprintf( fdefine, "\ntypedef union " );
  12.  
  13.    level = 0;
  14.    for(;;)
  15.       {
  16.       if( (c=unix_getc(finput)) < 0 ) error( "EOF encountered while processing %%union" );
  17.       putc( c, ftable );
  18.       if( fdefine ) putc( c, fdefine );
  19.  
  20.       switch( c )
  21.          {
  22.  
  23.       case '\n':
  24.          ++lineno;
  25.          break;
  26.  
  27.       case '{':
  28.          ++level;
  29.          break;
  30.  
  31.       case '}':
  32.          --level;
  33.          if( level == 0 ) 
  34.             {
  35.             /* we are finished copying */
  36.             fprintf( ftable, " YYSTYPE;\n" );
  37.             if( fdefine ) fprintf( fdefine, " YYSTYPE;\nextern YYSTYPE yylval;\n" );
  38.             return;
  39.             }
  40.          }
  41.       }
  42.    }
  43.