Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!murtoa.cs.mu.oz.au!munnari.oz.au!otc!metro!extro!glenn From: glenn@extro.ucc.su.oz (G. Geers [ext 3241]) Newsgroups: comp.os.minix Subject: yacc for minix (3 of 4) Message-ID: <489@extro.ucc.su.oz> Date: 28 Jun 89 10:41:34 GMT Reply-To: glenn@extro.ucc.su.oz (G. Geers [ext 3241]) Organization: University Computing Service, Uni. of Sydney, Australia. Lines: 1541 --- cut here --- cut here --- cut here --- cut here --- cut here --- #!/bin/sh # This is a shell archive. Remove anything before the /bin/sh line # then unpack it by saving it in a file and typing "sh file" # (Files unpacked will be owned by you and have default permissions). # Don't worry about trailing garbage - the archive ends with exit # This archive contains the following files: # ./dtxtrn.h # ./parse.y # ./system.h # ./y1.h # ./y1imp.c # ./y2.h # ./y2imp.c # ./y3.h # ./y3imp.c # ./y4.h # ./y4imp.c # ./yaoput.c # ./yapack.c # if `test ! -s ./dtxtrn.h` then echo "writing ./dtxtrn.h" cat > ./dtxtrn.h << '\EOF\' /* * DTXTRN.H -- Original extern file for UNIX YACC. * * Modified to call in "decus" or "vax11c" .H files to set up * parameters as appropriate. */ #include #include "system.h" /* MANIFEST CONSTANT DEFINITIONS */ /* base of nonterminal internal numbers */ #define NTBASE 010000 /* internal codes for error and accept actions */ #define ERRCODE 8190 #define ACCEPTCODE 8191 /* sizes and limits */ #ifdef HUGETAB #define ACTSIZE 12000 #define MEMSIZE 12000 #define NSTATES 750 #define NTERMS 127 #define NPROD 600 #define NNONTERM 300 #define TEMPSIZE 1200 #define CNAMSZ 5000 #define LSETSIZE 600 #define WSETSIZE 350 #endif #ifdef MEDTAB #define ACTSIZE 4000 #define MEMSIZE 5200 #define NSTATES 600 #define NTERMS 127 #define NPROD 400 #define NNONTERM 200 #define TEMPSIZE 800 #define CNAMSZ 5000 #define LSETSIZE 450 #define WSETSIZE 250 #endif #ifdef SMALLTAB #define ACTSIZE 1000 #define MEMSIZE 1500 #define NSTATES 450 #define NTERMS 127 #define NPROD 200 #define NNONTERM 100 #define TEMPSIZE 600 #define CNAMSZ 5000 #define LSETSIZE 200 #define WSETSIZE 125 #endif #define NAMESIZE 50 #define NTYPES 63 #ifdef WORD32 #define TBITSET ((32+NTERMS)/32) /* bit packing macros (may be machine dependent) */ #define BIT(a,i) ((a)[(i)>>5] & (1<<((i)&037))) #define SETBIT(a,i) ((a)[(i)>>5] |= (1<<((i)&037))) /* number of words needed to hold n+1 bits */ #define NWORDS(n) (((n)+32)/32) #else #define TBITSET ((16+NTERMS)/16) /* bit packing macros (may be machine dependent) */ #define BIT(a,i) ((a)[(i)>>4] & (1<<((i)&017))) #define SETBIT(a,i) ((a)[(i)>>4] |= (1<<((i)&017))) /* number of words needed to hold n+1 bits */ #define NWORDS(n) (((n)+16)/16) #endif /* relationships which must hold: TBITSET ints must hold NTERMS+1 bits... WSETSIZE >= NNONTERM LSETSIZE >= NNONTERM TEMPSIZE >= NTERMS + NNONTERMs + 1 TEMPSIZE >= NSTATES */ /* associativities */ #define NOASC 0 /* no assoc. */ #define LASC 1 /* left assoc. */ #define RASC 2 /* right assoc. */ #define BASC 3 /* binary assoc. */ /* flags for state generation */ #define DONE 0 #define MUSTDO 1 #define MUSTLOOKAHEAD 2 /* flags for a rule having an action, and being reduced */ #define ACTFLAG 04 #define REDFLAG 010 /* output parser flags */ #define YYFLAG1 (-1000) /* macros for getting associativity and precedence levels */ #define ASSOC(i) ((i)&03) #define PLEVEL(i) (((i)>>4)&077) #define TYPE(i) ((i>>10)&077) /* macros for setting associativity and precedence levels */ #define SETASC(i,j) i|=j #define SETPLEV(i,j) i |= (j<<4) #define SETTYPE(i,j) i |= (j<<10) /* looping macros */ #define TLOOP(i) for(i=1;i<=ntokens;++i) #define NTLOOP(i) for(i=0;i<=nnonter;++i) #define PLOOP(s,i) for(i=s;i ./parse.y << '\EOF\' /* parse.y - parser for flex input */ /* * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * Vern Paxson. * * The United States Government has rights in this work pursuant to * contract no. DE-AC03-76SF00098 between the United States Department of * Energy and the University of California. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ %token CHAR NUMBER SECTEND SCDECL XSCDECL WHITESPACE NAME PREVCCL EOF_OP %{ #include "flexdef.h" #ifndef lint static char copyright[] = "@(#) Copyright (c) 1989 The Regents of the University of California.\n"; static char CR_continuation[] = "@(#) All rights reserved.\n"; static char rcsid[] = "@(#) $Header: parse.y,v 2.1 89/06/20 17:23:54 vern Exp $ (LBL)"; #endif int pat, scnum, eps, headcnt, trailcnt, anyccl, lastchar, i, actvp, rulelen; int trlcontxt, xcluflg, cclsorted, varlength, variable_trail_rule; char clower(); static int madeany = false; /* whether we've made the '.' character class */ int previous_continued_action; /* whether the previous rule's action was '|' */ %} %% goal : initlex sect1 sect1end sect2 initforrule { /* add default rule */ int def_rule; pat = cclinit(); cclnegate( pat ); def_rule = mkstate( -pat ); finish_rule( def_rule, false, 0, 0 ); for ( i = 1; i <= lastsc; ++i ) scset[i] = mkbranch( scset[i], def_rule ); if ( spprdflt ) fputs( "YY_FATAL_ERROR( \"flex scanner jammed\" )", temp_action_file ); else fputs( "ECHO", temp_action_file ); fputs( ";\n\tYY_BREAK\n", temp_action_file ); } ; initlex : { /* initialize for processing rules */ /* create default DFA start condition */ scinstal( "INITIAL", false ); } ; sect1 : sect1 startconddecl WHITESPACE namelist1 '\n' | | error '\n' { synerr( "unknown error processing section 1" ); } ; sect1end : SECTEND ; startconddecl : SCDECL { /* these productions are separate from the s1object * rule because the semantics must be done before * we parse the remainder of an s1object */ xcluflg = false; } | XSCDECL { xcluflg = true; } ; namelist1 : namelist1 WHITESPACE NAME { scinstal( nmstr, xcluflg ); } | NAME { scinstal( nmstr, xcluflg ); } | error { synerr( "bad start condition list" ); } ; sect2 : sect2 initforrule flexrule '\n' | ; initforrule : { /* initialize for a parse of one rule */ trlcontxt = variable_trail_rule = varlength = false; trailcnt = headcnt = rulelen = 0; current_state_type = STATE_NORMAL; previous_continued_action = continued_action; new_rule(); } ; flexrule : scon '^' re eol { pat = link_machines( $3, $4 ); finish_rule( pat, variable_trail_rule, headcnt, trailcnt ); for ( i = 1; i <= actvp; ++i ) scbol[actvsc[i]] = mkbranch( scbol[actvsc[i]], pat ); if ( ! bol_needed ) { bol_needed = true; if ( performance_report ) fprintf( stderr, "'^' operator results in sub-optimal performance\n" ); } } | scon re eol { pat = link_machines( $2, $3 ); finish_rule( pat, variable_trail_rule, headcnt, trailcnt ); for ( i = 1; i <= actvp; ++i ) scset[actvsc[i]] = mkbranch( scset[actvsc[i]], pat ); } | '^' re eol { pat = link_machines( $2, $3 ); finish_rule( pat, variable_trail_rule, headcnt, trailcnt ); /* add to all non-exclusive start conditions, * including the default (0) start condition */ for ( i = 1; i <= lastsc; ++i ) if ( ! scxclu[i] ) scbol[i] = mkbranch( scbol[i], pat ); if ( ! bol_needed ) { bol_needed = true; if ( performance_report ) fprintf( stderr, "'^' operator results in sub-optimal performance\n" ); } } | re eol { pat = link_machines( $1, $2 ); finish_rule( pat, variable_trail_rule, headcnt, trailcnt ); for ( i = 1; i <= lastsc; ++i ) if ( ! scxclu[i] ) scset[i] = mkbranch( scset[i], pat ); } | scon EOF_OP { build_eof_action(); } | EOF_OP { /* this EOF applies only to the INITIAL start cond. */ actvsc[actvp = 1] = 1; build_eof_action(); } | error { synerr( "unrecognized rule" ); } ; scon : '<' namelist2 '>' ; namelist2 : namelist2 ',' NAME { if ( (scnum = sclookup( nmstr )) == 0 ) lerrsf( "undeclared start condition %s", nmstr ); else actvsc[++actvp] = scnum; } | NAME { if ( (scnum = sclookup( nmstr )) == 0 ) lerrsf( "undeclared start condition %s", nmstr ); else actvsc[actvp = 1] = scnum; } | error { synerr( "bad start condition list" ); } ; eol : '$' { if ( trlcontxt ) { synerr( "trailing context used twice" ); $$ = mkstate( SYM_EPSILON ); } else { trlcontxt = true; if ( ! varlength ) headcnt = rulelen; ++rulelen; trailcnt = 1; eps = mkstate( SYM_EPSILON ); $$ = link_machines( eps, mkstate( '\n' ) ); } } | { $$ = mkstate( SYM_EPSILON ); if ( trlcontxt ) { if ( varlength && headcnt == 0 ) /* both head and trail are variable-length */ variable_trail_rule = true; else trailcnt = rulelen; } } ; re : re '|' series { varlength = true; $$ = mkor( $1, $3 ); } | re2 series { if ( transchar[lastst[$2]] != SYM_EPSILON ) /* provide final transition \now/ so it * will be marked as a trailing context * state */ $2 = link_machines( $2, mkstate( SYM_EPSILON ) ); mark_beginning_as_normal( $2 ); current_state_type = STATE_NORMAL; if ( previous_continued_action ) { /* we need to treat this as variable trailing * context so that the backup does not happen * in the action but before the action switch * statement. If the backup happens in the * action, then the rules "falling into" this * one's action will *also* do the backup, * erroneously. */ if ( ! varlength || headcnt != 0 ) { fprintf( stderr, "flex: warning - trailing context rule at line %d made variable because\n", linenum ); fprintf( stderr, " of preceding '|' action\n" ); } /* mark as variable */ varlength = true; headcnt = 0; } if ( varlength && headcnt == 0 ) { /* variable trailing context rule */ /* mark the first part of the rule as the accepting * "head" part of a trailing context rule */ /* by the way, we didn't do this at the beginning * of this production because back then * current_state_type was set up for a trail * rule, and add_accept() can create a new * state ... */ add_accept( $1, num_rules | YY_TRAILING_HEAD_MASK ); } $$ = link_machines( $1, $2 ); } | series { $$ = $1; } ; re2 : re '/' { /* this rule is separate from the others for "re" so * that the reduction will occur before the trailing * series is parsed */ if ( trlcontxt ) synerr( "trailing context used twice" ); else trlcontxt = true; if ( varlength ) /* we hope the trailing context is fixed-length */ varlength = false; else headcnt = rulelen; rulelen = 0; current_state_type = STATE_TRAILING_CONTEXT; $$ = $1; } ; series : series singleton { /* this is where concatenation of adjacent patterns * gets done */ $$ = link_machines( $1, $2 ); } | singleton { $$ = $1; } ; singleton : singleton '*' { varlength = true; $$ = mkclos( $1 ); } | singleton '+' { varlength = true; $$ = mkposcl( $1 ); } | singleton '?' { varlength = true; $$ = mkopt( $1 ); } | singleton '{' NUMBER ',' NUMBER '}' { varlength = true; if ( $3 > $5 || $3 < 0 ) { synerr( "bad iteration values" ); $$ = $1; } else { if ( $3 == 0 ) $$ = mkopt( mkrep( $1, $3, $5 ) ); else $$ = mkrep( $1, $3, $5 ); } } | singleton '{' NUMBER ',' '}' { varlength = true; if ( $3 <= 0 ) { synerr( "iteration value must be positive" ); $$ = $1; } else $$ = mkrep( $1, $3, INFINITY ); } | singleton '{' NUMBER '}' { /* the singleton could be something like "(foo)", * in which case we have no idea what its length * is, so we punt here. */ varlength = true; if ( $3 <= 0 ) { synerr( "iteration value must be positive" ); $$ = $1; } else $$ = link_machines( $1, copysingl( $1, $3 - 1 ) ); } | '.' { if ( ! madeany ) { /* create the '.' character class */ anyccl = cclinit(); ccladd( anyccl, '\n' ); cclnegate( anyccl ); if ( useecs ) mkeccl( ccltbl + cclmap[anyccl], ccllen[anyccl], nextecm, ecgroup, CSIZE ); madeany = true; } ++rulelen; $$ = mkstate( -anyccl ); } | fullccl { if ( ! cclsorted ) /* sort characters for fast searching. We use a * shell sort since this list could be large. */ cshell( ccltbl + cclmap[$1], ccllen[$1] ); if ( useecs ) mkeccl( ccltbl + cclmap[$1], ccllen[$1], nextecm, ecgroup, CSIZE ); ++rulelen; $$ = mkstate( -$1 ); } | PREVCCL { ++rulelen; $$ = mkstate( -$1 ); } | '"' string '"' { $$ = $2; } | '(' re ')' { $$ = $2; } | CHAR { ++rulelen; if ( $1 == '\0' ) synerr( "null in rule" ); if ( caseins && $1 >= 'A' && $1 <= 'Z' ) $1 = clower( $1 ); $$ = mkstate( $1 ); } ; fullccl : '[' ccl ']' { $$ = $2; } | '[' '^' ccl ']' { /* *Sigh* - to be compatible Unix lex, negated ccls * match newlines */ #ifdef NOTDEF ccladd( $3, '\n' ); /* negated ccls don't match '\n' */ cclsorted = false; /* because we added the newline */ #endif cclnegate( $3 ); $$ = $3; } ; ccl : ccl CHAR '-' CHAR { if ( $2 > $4 ) synerr( "negative range in character class" ); else { if ( caseins ) { if ( $2 >= 'A' && $2 <= 'Z' ) $2 = clower( $2 ); if ( $4 >= 'A' && $4 <= 'Z' ) $4 = clower( $4 ); } for ( i = $2; i <= $4; ++i ) ccladd( $1, i ); /* keep track if this ccl is staying in alphabetical * order */ cclsorted = cclsorted && ($2 > lastchar); lastchar = $4; } $$ = $1; } | ccl CHAR { if ( caseins ) if ( $2 >= 'A' && $2 <= 'Z' ) $2 = clower( $2 ); ccladd( $1, $2 ); cclsorted = cclsorted && ($2 > lastchar); lastchar = $2; $$ = $1; } | { cclsorted = true; lastchar = 0; $$ = cclinit(); } ; string : string CHAR { if ( caseins ) if ( $2 >= 'A' && $2 <= 'Z' ) $2 = clower( $2 ); ++rulelen; $$ = link_machines( $1, mkstate( $2 ) ); } | { $$ = mkstate( SYM_EPSILON ); } ; %% /* build_eof_action - build the "<>" action for the active start * conditions */ build_eof_action() { register int i; for ( i = 1; i <= actvp; ++i ) { if ( sceof[actvsc[i]] ) lerrsf( "multiple <> rules for start condition %s", scname[actvsc[i]] ); else { sceof[actvsc[i]] = true; fprintf( temp_action_file, "case YY_STATE_EOF(%s):\n", scname[actvsc[i]] ); } } line_directive_out( temp_action_file ); } /* synerr - report a syntax error * * synopsis * char str[]; * synerr( str ); */ synerr( str ) char str[]; { syntaxerror = true; fprintf( stderr, "Syntax error at line %d: %s\n", linenum, str ); } /* yyerror - eat up an error message from the parser * * synopsis * char msg[]; * yyerror( msg ); */ yyerror( msg ) char msg[]; { } \EOF\ else echo "will not over write ./parse.y" fi if `test ! -s ./system.h` then echo "writing ./system.h" cat > ./system.h << '\EOF\' /* ********************* * * S Y S T E M . H * * ********************* * * This file replaces the original "files." header file. It defines, for * the IBM PC/XT version, the target parser function source file, overriding * file name string defines, and other system-specific definitions and * parameters. * * Bob Denny 06-Dec-80 * * Edits: * 18-Dec-80 ZAPFILE no longer used in Decus Yacc. * Parser file renamed yypars.c * * 28-Aug-81 Temp files for RSX have specific version * numbers of 1 to avoid multi-versions. Rename * parser info file ".i". * * 12-Apr-83 Add FNAMESIZE & EX_xxx parameters. * *Scott Guthery 23-Dec-83 Adapt for the IBM PC/XT & DeSmet C compiler. * */ /* Define WORD32 if target machine is a 32 bitter */ # undef WORD32 /* * Target parser source file */ #define PARSER "/usr/lib/yypars" /* * basic size of the Yacc implementation */ #define MEDIUM YES /* * Table size for this Yacc */ # define MEDTAB YES /* * Filespec definitions */ # define ACTNAME "yacc2.tmp" # define TEMPNAME "yacc1.tmp" # define FNAMESIZE 24 /* * Exit status values */ #define EX_SUC 1 #define EX_WAR 0 #define EX_ERR 2 #define EX_SEV 4 \EOF\ else echo "will not over write ./system.h" fi if `test ! -s ./y1.h` then echo "writing ./y1.h" cat > ./y1.h << '\EOF\' /*****************************************************************************/ /* ************* */ /* * Y 1 . H * */ /* ************* */ /* */ /* This file contains the external declarations needed to hook Yacc modules */ /* which were originally in Y1.C to their impure data in Y1IMP.1C. Also does */ /* the include of the original data/external file DTXTRN.H. */ /* */ /*****************************************************************************/ #include "dtxtrn.h" /* lookahead computations */ extern int tbitset; /* size of lookahead sets */ extern int nlset; /* next lookahead set index */ extern struct looksets clset; /* temporary storage for lookahead computations */ /* other storage areas */ extern int fatfl; /* if on, error is fatal */ extern int nerrors; /* number of errors */ /* storage for information about the nonterminals */ extern int **pres[ ]; /* vector of pointers to productions yielding each nonterminal */ extern struct looksets *pfirst[ ]; /* vector of pointers to first sets for each nonterminal */ extern int pempty[ ]; /* vector of nonterminals nontrivially deriving e */ /* accumulators for statistics information */ extern struct wset *zzcwp; extern int *zzmemsz; \EOF\ else echo "will not over write ./y1.h" fi if `test ! -s ./y1imp.c` then echo "writing ./y1imp.c" cat > ./y1imp.c << '\EOF\' /* * y1imp.c - impure data used by modules originally in y1.c. * * HISTORY */ #define y1imp yes #include "dtxtrn.h" /* lookahead computations */ int tbitset; /* size of lookahead sets */ struct looksets lkst[LSETSIZE]; int nlset = 0; /* next lookahead set index */ int nolook = 0; /* flag to suppress lookahead computations */ struct looksets clset; /* temporary storage for lookahead */ /* working set computations */ struct wset wsets[WSETSIZE]; struct wset *cwp; /* state information */ int nstate = 0; /* number of states */ struct item *pstate[NSTATES+2]; /* pointers to descriptions of states */ int tystate[NSTATES]; /* contains type information about states */ int indgo[NSTATES]; /* index to the stored goto table */ int tstates[NTERMS]; /* states generated by terminal gotos */ int ntstates[NNONTERM]; /* states generated by nonterminal gotos */ int mstates[NSTATES]; /* overflow of term/nonterm generation lists */ /* storage for the actions in the parser */ int amem[ACTSIZE]; /* action table storage */ int *memp = amem; /* next free action table position */ /* other storage areas */ int temp1[TEMPSIZE]; /* temporary storage, indexed by terms + ntokens or states */ int lineno = 1; /* current input line number */ int fatfl = 1; /* if on, error is fatal */ int nerrors = 0; /* number of errors */ /* storage for information about the nonterminals */ int **pres[NNONTERM+2]; /* vector of pointers to productions yielding each nonterminal */ struct looksets *pfirst[NNONTERM+2]; /* vector of pointers to first sets for each nonterminal */ int pempty[NNONTERM+1]; /* vector of nonterminals nontrivially deriving e */ /* accumulators for statistics information */ struct wset *zzcwp = wsets; int zzgoent = 0; int zzgobest = 0; int zzacent = 0; int zzexcp = 0; int zzclose = 0; int zzsrconf = 0; int *zzmemsz = mem0; int zzrrconf = 0; /* data pulled from internal static to here */ /* declared external only in user module */ int *pyield[NPROD]; /* from ycpres */ char sarr[ISIZE]; /* from ywritm */ \EOF\ else echo "will not over write ./y1imp.c" fi if `test ! -s ./y2.h` then echo "writing ./y2.h" cat > ./y2.h << '\EOF\' /*****************************************************************************/ /* ************* */ /* * Y 2 . H * */ /* ************* */ /* */ /* This file contains the external declarations needed to hook Yacc modules */ /* which were originally in Y2.C to their impure data in Y2IMP.2C. Also does */ /* the include of the original data/external file DTXTRN.H. */ /* */ /*****************************************************************************/ # include "dtxtrn.h" # define IDENTIFIER 257 # define MARK 258 # define TERM 259 # define LEFT 260 # define RIGHT 261 # define BINARY 262 # define PREC 263 # define LCURLY 264 # define C_IDENTIFIER 265 /* name followed by colon */ # define NUMBER 266 # define START 267 # define TYPEDEF 268 # define TYPENAME 269 # define UNION 270 # define ENDFILE 0 /* communication variables between various I/O routines */ extern char *infile; /* input file name */ extern int numbval; /* value of an input number */ extern char tokname[ ]; /* input token name */ /* storage of names */ extern char cnames[ ]; /* place where token and nonterminal names are stored */ extern int cnamsz; /* size of cnames */ extern char *cnamp; /* place where next name is to be put in */ extern int ndefout; /* number of defined symbols output */ /* storage of types */ extern int ntypes; /* number of types defined */ extern char *typeset[ ]; /* pointers to type tags */ /* symbol tables for tokens and nonterminals */ extern int start; /* start symbol */ /* assigned token type values */ extern int extval; \EOF\ else echo "will not over write ./y2.h" fi if `test ! -s ./y2imp.c` then echo "writing ./y2imp.c" cat > ./y2imp.c << '\EOF\' /* * y2imp.c - impure date needed by routines pulled from y2.c * * HISTORY */ #define y2imp YES #include "dtxtrn.h" /* communication variables between various I/O routines */ char *infile; /* input file name */ int numbval; /* value of an input number */ char tokname[NAMESIZE]; /* input token name */ /* storage of names */ char cnames[CNAMSZ]; /* token and nonterminal name storage */ int cnamsz = CNAMSZ; /* size of cnames */ char *cnamp = cnames; /* place where next name is to be put in */ int ndefout = 3; /* number of defined symbols output */ /* storage of types */ int ntypes; /* number of types defined */ char *typeset[NTYPES]; /* pointers to type tags */ /* symbol tables for tokens and nonterminals */ int ntokens = 0; struct toksymb tokset[NTERMS]; int toklev[NTERMS]; int nnonter = -1; struct ntsymb nontrst[NNONTERM]; int start; /* start symbol */ /* assigned token type values */ int extval = 0; /* input and output file descriptors */ FILE *finput; /* yacc input file */ FILE *faction; /* file for saving actions */ FILE *fdefine; /* file for # defines */ FILE *ftable; /* y.tab.c file */ FILE *ftemp; /* tempfile to pass 2 */ FILE *foutput; /* y.output file */ /* storage for grammar rules */ int mem0[MEMSIZE]; /* production storage */ int *mem = mem0; int nprod = 1; /* number of productions */ int *prdptr[NPROD]; /* pointers to descriptions of productions */ int levprd[NPROD]; /* precedence levels for the productions */ /* Statics pulled from modules */ int peekline; /* from gettok() */ \EOF\ else echo "will not over write ./y2imp.c" fi if `test ! -s ./y3.h` then echo "writing ./y3.h" cat > ./y3.h << '\EOF\' /*****************************************************************************/ /* ************* */ /* * Y 3 . H * */ /* ************* */ /* */ /* This file contains the external declarations needed to hook Yacc modules */ /* which were originally in Y3.C to their impure data in Y3IMP.3C. Also does */ /* the include of the original data/external file DTXTRN.H. */ /* */ /*****************************************************************************/ #include "dtxtrn.h" extern int lastred; /* the number of the last reduction of a state */ \EOF\ else echo "will not over write ./y3.h" fi if `test ! -s ./y3imp.c` then echo "writing ./y3imp.c" cat > ./y3imp.c << '\EOF\' /* * y3imp.c - impure data from modules split from y3.c * * HISTORY */ #define y3imp YES #include "dtxtrn.h" int lastred; /* the number of the last reduction of a state */ int defact[NSTATES]; /* the default actions of states */ \EOF\ else echo "will not over write ./y3imp.c" fi if `test ! -s ./y4.h` then echo "writing ./y4.h" cat > ./y4.h << '\EOF\' /*****************************************************************************/ /* ************* */ /* * Y 4 . H * */ /* ************* */ /* */ /* This file contains the external declarations needed to hook Yacc modules */ /* which were originally in Y4.C to their impure data in Y4IMP.4C. Also does */ /* the include of the original data/external file DTXTRN.H. */ /* */ /*****************************************************************************/ # include "dtxtrn.h" # define a amem # define pa indgo # define yypact temp1 # define greed tystate # define NOMORE -1000 extern int *ggreed; extern int *pgo; extern int *yypgo; extern int maxspr; /* maximum spread of any entry */ extern int maxoff; /* maximum offset into a array */ extern int *pmem; extern int *maxa; extern int nxdb; extern int adb; \EOF\ else echo "will not over write ./y4.h" fi if `test ! -s ./y4imp.c` then echo "writing ./y4imp.c" cat > ./y4imp.c << '\EOF\' /* * y4imp.c - impure data from y4.c modules * * HISTORY */ # include "dtxtrn.h" # define a amem # define pa indgo # define yypact temp1 # define greed tystate # define NOMORE -1000 int *ggreed = lkst[0].lset; int *pgo = wsets[0].ws.lset; int *yypgo = &nontrst[0].tvalue; int maxspr = 0; /* maximum spread of any entry */ int maxoff = 0; /* maximum offset into a array */ int *pmem = mem0; int *maxa; int nxdb = 0; int adb = 0; \EOF\ else echo "will not over write ./y4imp.c" fi if `test ! -s ./yaoput.c` then echo "writing ./yaoput.c" cat > ./yaoput.c << '\EOF\' /* * yaoput.c - write out the optimized parser * * HISTORY */ #include "y4.h" int aoutput() { fprintf(ftable, "# define YYLAST %d\n", maxa - a + 1); arout("yyact", a, (maxa - a) + 1); arout("yypact", pa, nstate); arout("yypgo", pgo, nnonter + 1); } \EOF\ else echo "will not over write ./yaoput.c" fi if `test ! -s ./yapack.c` then echo "writing ./yapack.c" cat > ./yapack.c << '\EOF\' /* * yapack.c - * * HISTORY * {1} 28-Aug-81 Bob Denny * Modified to make debug code conditionally compile. */ #include "y3.h" int apack(p, n ) int *p; { /* pack state i from temp1 into amem */ int off; register *pp, *qq, *rr; int *q, *r; /* * we don't need to worry about checking because we we will only * look entries known to be there... */ /* eliminate leading and trailing 0's */ q = p + n; for (pp = p, off = 0; *pp == 0 && pp <= q; ++pp, --off) /* VOID */; if (pp > q) return (0); /* no actions */ p = pp; /* now, find a place for the elements from p to q, inclusive */ r = &amem[ACTSIZE - 1]; for (rr = amem; rr <= r; ++rr, ++off) { /* try rr */ for (qq = rr, pp = p; pp <= q; ++pp, ++qq) { if (*pp != 0) { if (*pp != *qq && *qq != 0) goto nextk; } } /* we have found an acceptable k */ #ifdef debug if (foutput != NULL) fprintf(foutput, "off = %d, k = %d\n", off, rr - amem); #endif for (qq = rr, pp = p; pp <= q; ++pp, ++qq) { if (*pp) { if (qq > r) error("action table overflow"); if (qq > memp) memp = qq; *qq = *pp; } } #ifdef debug if (foutput != NULL) { for (pp = amem; pp <= memp; pp += 10) { fprintf(foutput, "\t"); for (qq = pp; qq <= pp + 9; ++qq) fprintf(foutput, "%d ", *qq); fprintf(foutput, "\n"); } } #endif return (off); nextk: ; } error("no space in action table"); /* NOTREACHED */ } \EOF\ else echo "will not over write ./yapack.c" fi echo "Finished archive 3 of 4" # if you want to concatenate archives, remove anything after this line exit 0