home *** CD-ROM | disk | FTP | other *** search
- /*
- HEADER: CUG nnn.nn;
- TITLE: YACC - Yet Another Compilier-Compilier
- VERSION: 1.0 for IBM-PC
- DATE: JAN 28, 1985
- DESCRIPTION: LALR(1) Parser Generator. From UNIX
- KEYWORDS: Parser Generator Compilier-Compilier YACC
- SYSTEM: IBM-PC and Compatiables
- FILENAME: YCPUNI.2C
- WARNINGS: This program is not for the casual user. It will
- be useful primarily to expert developers.
- CRC: N/A
- SEE-ALSO: LEX and PREP
- AUTHORS: Scott Guthery 11100 leafwood lane Austin, TX 78750
- COMPILERS: DESMET-C
- REFERENCES: UNIX Systems Manuals
- */
-
- #include "y1.h"
- #include "y2.h"
-
- void cpyunion( void )
- {
- /* copy the union declaration to the output, and the define file if present */
-
- int level, c;
- fprintf( ftable, "\n# line %d\n", lineno );
- fprintf( ftable, "\n#define UNION 1\n");
- fprintf( ftable, "typedef union " );
- if( fdefine ) fprintf( fdefine, "\ntypedef union " );
-
- level = 0;
- for(;;)
- {
- if( (c=unix_getc(finput)) < 0 ) error( "EOF encountered while processing %%union" );
- putc( c, ftable );
- if( fdefine ) putc( c, fdefine );
-
- switch( c )
- {
-
- case '\n':
- ++lineno;
- break;
-
- case '{':
- ++level;
- break;
-
- case '}':
- --level;
- if( level == 0 )
- {
- /* we are finished copying */
- fprintf( ftable, " YYSTYPE;\n" );
- if( fdefine ) fprintf( fdefine, " YYSTYPE;\nextern YYSTYPE yylval;\n" );
- return;
- }
- }
- }
- }
-