IMD 1.17: 19/01/2010 20:35:42 yacc 1-6-87 yacc   UniFLEX Backup* exit_code - The exit code number. Some exit codes have * special meanings (see Exit Codes). Does not * normally cause an exit. * * tag - The index into the verbose error message system. * If the exit code is P_WARN or P_ERR and the * tag is NULL or "", the tag is set to (sys#), * where # is the value of errno. If the exit code * is USAGE, no tag is printed. * * out_code - The output file specifier. These are defined * in and the macros must be used, since * they  ࢊ ࢊjTektronix 44042  !"#$%&'()*+,-./01234('&%$#"! contain three parameters. * Codes : * O_ERR - print on stderr * O_OUT - print on stdout * NO_OUT - don't print anything * * format - An error message format like that of printf(1). * * args - Variables corresponding to the % specifications * in the format. * * Exit Codes and Message Format: * * The error message has the basic format : * * program_name : [special] message given [:system message] (tag) * ["At line" number "in Source file" file] * * where * * 'prog&  &  ERROR.c. ڌt: ^ "*%-z Sx1-6-87 yacc~Czc"ram_name' is the basename of the program * 'special' is defined for the special exit codes below * 'message given' is the formatted message (format+args) * 'system message' is the message from the system error list * * The second line is printed for INTERNAL errors always, * and is printed for other codes if the environment variable * PRLINE is set. * * The special exit codes are : * NO_ERRS - no message printed * does not exit (warning code set to 0) * * NO_CMD - Used only by /* this is a copy of the file "/sys/UTek/src/lib/libc/ecs/ERROR.c" */ /* * ERROR * * $Header: ERROR.c,v 1.27 86/09/02 16:29:19 julia Exp $ * $Locker: $ * * Copyright (c) 1983, 1985 Tektronix Inc. * All Rights Reserved * */ /* * Name of subroutine: ERROR - error-handling routine * * Author: David Elliott - ECS * * Descripton: * * This version denotes a major rewrite of the ERROR subroutine. * * Usage: * * ERROR (exit_code, tag, out_code, format, args...); * * Parameters: * sh(1) when command is not * executed. * * NP_WARN - 'special' is null * no 'system message' * does not exit (warning code set to 122) * * NP_ERR - 'special' is null * no 'system message' * exits with code 123 * * P_WARN - 'special' is null * 'system message' printed * does not exit (warning code set to 124) * * P_ERR - 'special' is null * 'system message' printed * exits with code 125 * * USAGE - 'special' is "usage : "'program name' * no 'system message' * exits with code 126 * * INTERNAL- 'special is "INTERNAL ERROR : " * no 'system message' * aborts (dumps core) * * Warning: * This subroutine is unportable. It uses _doprnt and must * therefore be modified if the interface to _doprnt is * not the same as in 4.2BSD Unix. In other words, if you * have to change fprintf(1), you have to change ERROR. * * Log of Revisions: * * $Log: ERROR.c,v $ * Revision 1.27 86/09/02 16:29:19 julia * add 19 Revision 1.16 83/11/30 13:48:25 dce * Fixed USAGE format. * * Revision 1.15 83/11/30 12:28:17 dce * Major rewrite. Uses printf format. * * */ /*VARARGS*/ #include #include "errdefs.h" #include #include #define _IOWRT 02 #define _IONBF 04 #define NO_PR -1 /* Don't print message. */ #define PR_STDOUT 1 /* Print message on stdout too. */ #define PLACE if (prline_set) { _doprnt (ERROR_pr_line, &linenum, out_stream); _doprnt (ERROR_pr_file, &srcfile, 85 to copyright notice * * Revision 1.26 85/03/13 09:43:30 dce * Changed so that negative error numbers are handled better. * Fixed so that INTERNAL errors don't print tag line if * srcfile is null. * * Revision 1.25 85/01/06 16:08:16 dce * Changed globals to locals where possible and added checking * for error number out of bounds. * * Revision 1.24 84/08/25 09:15:39 dce * Now marks stderr as line buffered while printing. This speeds up * printing of messages. * * Also, both stdout_stream);} /* * Variables set by crt0 and the system. */ int _last_err; /* Last exit code set. */ char *_pgmname; /* Name of current program. */ /* int errno; System error code. */ int sys_nerr; /* Number of system error messages. */ char *sys_errlist[]; /* System error messages. */ void ERROR (exit_code, tag, out_code, srcfile, linenum, err_msg, args) char *tag, *srcfile, *err_msg; int linenum, exit_code, out_code, args; { int save_errno; register FILE *out_stream; /* Ouput file poiout and stderr are flushed before the message is * printed. * * * * Revision 1.23 84/05/27 11:13:57 dce * Now uses shared strings and FORCETAGS is gone. * * Revision 1.22 84/03/14 20:50:58 dce * Added code to check for the environment variables NOTAGS and FORCETAGS. * NOTAGS turns off tags, and FORCETAGS turns them on for good. * FORCETAGS should be removed when unset is available in the shell (sh). * * Revision 1.21 84/02/02 12:31:07 dce * Much smaller version of ERROR. * Firstnter. */ register int prline_set = 0; /* Global verbose flag. */ register int pr_tag = 1; /* Global tag flag. */ /* * These are strings for sharing in messages. */ char *ERROR_pr_rtag = " (%s)\n"; char *ERROR_pr_nl = "\n"; char *ERROR_pr_line = "\tAt line %d "; char *ERROR_pr_file = "in Source file %s\n"; char *ERROR_pr_pgm = "%s : "; save_errno = errno; _last_err = exit_code; /* * Set the output stream depending upon the output code. */ if (out_code == PR_STDOUT) { out_stream = st, null tags are not printed. * Second, invalid exit codes (11-120) are not checked for. * * Revision 1.20 84/01/24 09:39:25 dce * Changed USAGE to not print tag. * * Revision 1.19 84/01/23 15:02:30 dce * Added special code to set tag to "sys#" if it is null * (# is errno). * * Revision 1.18 84/01/23 13:38:48 dce * Added 'tag' argument which prints an index into the verbose * error message database. * * Revision 1.17 84/01/05 14:50:31 peterg * Changed dir.h to sys/dir.h. * *dout; } else { out_stream = stderr; } /* * Check for NO_ERRS. */ if (exit_code == NO_ERRS) { return; } /* * Check environment variables for global flags. */ if (srcfile && getenv("PRLINE")) { prline_set = 1; } if (getenv("NOTAGS")) { pr_tag = 0; } /* * Flush the output files and set up stderr for buffered mode. */ fflush (stdout); fflush (stderr); if (out_stream == stderr) { out_stream->_flag = _IOWRT; } /* * Take action depending upon exit code given. */ switch (exit_code) { case NP_WARN : /* No perror call, continue processing. */ case NP_ERR : /* No perror call, abort processing. */ if (out_code != NO_PR) { _doprnt (ERROR_pr_pgm, &_pgmname, out_stream); _doprnt (err_msg, &args, out_stream); if (pr_tag && *tag != '\0' && tag != NULL) { _doprnt (ERROR_pr_rtag, &tag, out_stream); } else { _doprnt (ERROR_pr_nl, NULL, out_stream); } PLACE; (void) fflush (out_stream); } if (out_stream == stderr) { out_stream->_cnt= 0; out_stretag && *tag != '\0' && tag != NULL) { _doprnt (ERROR_pr_rtag, &tag, out_stream); } else { _doprnt (ERROR_pr_nl, NULL, out_stream); } if (srcfile) { _doprnt (ERROR_pr_line, &linenum, out_stream); _doprnt (ERROR_pr_file, &srcfile, out_stream); } (void) fflush (out_stream); if (out_stream == stderr) { out_stream->_cnt= 0; out_stream->_flag = _IOWRT | _IONBF; } abort (); break; default : /* Other error code. */ if (out_code != NO_PR && err_msg[0] != NULL) { _doam->_flag = _IOWRT | _IONBF; } if (exit_code == NP_ERR) { exit (NP_ERR); } break; case P_WARN : /* Call perror, continue processing. */ case P_ERR : /* Call print, abort processing. */ if (out_code != NO_PR) { _doprnt (ERROR_pr_pgm, &_pgmname, out_stream); _doprnt (err_msg, &args, out_stream); if (save_errno < sys_nerr && save_errno > 0) { _doprnt (" : %s", &sys_errlist[save_errno], out_stream); } else { _doprnt (" : Unknown error number %d", &save_errno, out_stream)prnt (ERROR_pr_pgm, &_pgmname, out_stream); _doprnt (err_msg, &args, out_stream); if (pr_tag && *tag != '\0' && tag != NULL) { _doprnt (ERROR_pr_rtag, &tag, out_stream); } else { _doprnt (ERROR_pr_nl, NULL, out_stream); } PLACE; (void) fflush (out_stream); if (out_stream == stderr) { out_stream->_cnt= 0; out_stream->_flag = _IOWRT | _IONBF; } } } } _doprnt(fmt,argv,stream) register char *fmt; unsigned int *argv; register FILE *stream; { fprintf(stream,"; } if (pr_tag) { if (tag == NULL || *tag == '\0') { _doprnt (" (sys%d)\n", &save_errno, out_stream); } else { _doprnt (ERROR_pr_rtag, &tag, out_stream); } } else { _doprnt (ERROR_pr_nl, NULL, out_stream); } PLACE; (void) fflush (out_stream); } if (out_stream == stderr) { out_stream->_cnt= 0; out_stream->_flag = _IOWRT | _IONBF; } if (exit_code == P_ERR) { exit (P_ERR); } break; case USAGE : /* Usage error, abort processing. */ if (out__doprint: %s\n",fmt); } ine_set = 0; /* Global verbose flag. */ register int pr_tag = 1; /* Global tag flag. */ /* * These are strings for sharing in messages. */ char *ERROR_pr_rtag = " (%s)\n"; char *ERROR_pr_nl = "\n"; char *ERROR_pr_line = "\tAt line %d "; char *ERROR_pr_file = "in Source file %s\n"; char *ERROR_pr_pgm = "%s : "; save_errno = errno; _last_err = exit_code; /* * Set the output stream depending upon the output code. */ if (out_code == PR_STDOUT) { out_stream = stcode != NO_PR) { _doprnt ("%s : usage : ", &_pgmname, out_stream); _doprnt ("%s ", &_pgmname, out_stream); _doprnt (err_msg, &args, out_stream); putc ('\n', out_stream); PLACE; (void) fflush (out_stream); } if (out_stream == stderr) { out_stream->_cnt= 0; out_stream->_flag = _IOWRT | _IONBF; } exit (USAGE); break; case INTERNAL: /* Internal error, dump core. */ _doprnt ("%s : INTERNAL ERROR : ", &_pgmname, out_stream); _doprnt (err_msg, &args, out_stream); if (pr_G H  Makefile. ڌt: ^ "*-z-z Sx1-6-87 yacc~Cze"CFLAGS = +Oswr DESTDIR = /bin EXTLIBS = GROUP = HDRS = errdefs.h INCL = dextern files IOPTS = LIBS = LIB = /usr/lib LIBY = liby.a LIBYOBJS = libmai.r libzer.r LIBYSRCS = libmai.c libzer.c LDFLAGS = OBJS = y1.r y2.r y3.r y4.r ERROR.r PGM = yacc YFLAGS = SRCS = y1.c y2.c y3.c y4.c ERROR.c .SUFFIXES: .SUFFIXES: .c .r .c.r: $(CC) $(CFLAGS) $< all: $(PGM) $(LIBY) $(PGM): $(OBJS) $(INCL) $(LIBS) $(EXTLIBS) yaccpar $(CC) $(OBJS) +o=yacc $(LIBY): $(LIBYSRCS) libyrcsid.r $(CC) $(CFLAGS) $(LIBYSries used from other directories, it must use # the entire path name. # GROUP - The complete '-g groupname' option for the install script. # HDRS - Header files, .h files from this directory and other # directories. The use of 'make depend' inserts all # headers into this makefile. # INCL - Local include file listing. Used by clean and print # for specific files. Maintained manually. # IOPTS - compiler -I options listing. # LIBS - Libraries found in this directory. # LDFLAGS - LoaderRCS) y1.c: dextern files y2.c: dextern files y3.c: dextern files y4.c: dextern files libyrcsid.r: libyrcsid.c libyrcsid.c: $(LIBYSRCS) depend: $(SRCS) $(INCL) # Compare SRCS includes to *HDRS and comment or correct # depending on option flag. makedepend -fix "$(IOPTS)" $(SRCS) index: ctags -wx $(HDRS) $(SRCS) ut_stream->_cnt= 0; out_stream->_flag = _IOWRT | _IONBF; } abort (); break; default : /* Other error code. */ if (out_code != NO_PR && err_msg[0] != NULL) { _do flags. Note that the full name of the -l* # libraries uses should be in either LIBS or EXTLIBS. # LPR - Line printer utility call. This is sometimes a # call to something other than 'lpr'. # OBJS - Names of compiled object files. # OLDDIR - Directory for relocation of the previous version. # OWNER - The complete '-o ownername' option for the install script. # PGM - The name of the utility being made. There are no # mixed multiple program makefiles in the utilities. # If multipl   Makefile.old. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czd"e programs are to be made use PGMS and # add explicit targets for the listed programs. # PREFIX - The complete '+p prefix' option for the install script. # PREV - Previous version make flag. # PRINT - Printing utility to be used. # SRCS - Names of the source files combined to make PGM. # STATE - State of the made version (RCS). # TESTS - Names of the test scripts. There must be at least # one test. # WHICH - Location utility in use on this system. # X* - Programs specific to cross cod# # Makefile template for utilities ported to Merlin. This form # is based on "ECS Mid-Range Software Standards", by Anne Jacko; # additions have been made for specific cases not covered by the # general rules. # Paul K. Hyder {tekecs!hyder} 14 June 1983 # $Header: Makefile,v 1.13 86/09/20 12:51:16 paulh Exp $ # $Locker: $ # # Standard variables defined. # DESTDIR - Destination directory, default is the vax/unix tree # EXTLIBS - External libraries. This is the whole path name of all # librae generation on the # vax. Use 'make xall' to make cross code binaries. # # Make defines these variables. (MAKE MUST INCLUDE RCS HANDLING.) #Consult make(1) for complete variable information. Those of #importance are annotated below. # AS - Assembler used by default rules. # CC - C compiler used by default rules. # CFLAGS - C compiler option flags. # CO - Version control checkout. # COFLAGS - Checkout option flags. # LFLAGS - Lex option flags. (N.B. this is not LDFLAGS.) # LOADLIBES - Berekely standard keyword, this makefile uses *LIBS. # # CFLAGS= -O -DWORD32 DESTDIR = /bin EXTLIBS = GROUP = HDRS = /usr/include/errdefs.h INCL = dextern files IOPTS = LIBS = LIB = /usr/lib LIBY = liby.a LIBYOBJS = libmai.o libzer.o LIBYSRCS = libmai.c libzer.c LDFLAGS = LPR = lpr -Plpw OBJS = y1.o y2.o y3.o y4.o OLDDIR = OLD OWNER = -o sys PGM = yacc YFLAGS = PREFIX = +p mr- PREV = -r PRINT = pr SRCS = y1.c y2.c y3.c y4.c STATE = -sExp TESTDIR = ../../Tests TESTS = WHICH = pathof XAS = /merlin/v: clean mkprev $(PREV) rcsid.c make $(PGM) print: $(SRCS) $(INCL) documents $(PRINT) documents $(SRCS) $(INCL) Makefile | $(LPR) touch printnew printnew: documents $(SRCS) $(INCL) $(PRINT) $? Makefile | $(LPR) touch printnew test: test.yacc macdefs mfile1 manifest yacc test.yacc cc y.tab.c rcsin -v test.yacc macdefs mfile1 manifest testclean: rm -f test.yacc macdefs mfile1 manifest *.o a.out y.tab.c state: clean make all STATE=$(STATE) tags: $(HDRS) $(SRCS) @ctags -w $(Htools/bin/a16 XCC = /merlin/tools/bin/c16 XDESTDIR = /merlin/disks/current XTESTDIR = /merlin/disks/TESTS1.1 XCFLAGS = "-O -k -DWORD32" all: $(PGM) $(LIBY) $(PGM): $(OBJS) $(INCL) rcsid.o $(LIBS) $(EXTLIBS) yaccpar $(CC) $(CFLAGS) $(OBJS) rcsid.o -o yacc $(LIBY): $(LIBYSRCS) libyrcsid.o $(CC) -O -c $(LIBYSRCS) ar r $(LIBY) $(LIBYOBJS) libyrcsid.o ranlib $(LIBY) install: $(PGM) $(LIBY) dextern files # Use the new modified install script. # This should be without the copy (-c) option.DRS) $(SRCS) update: $(DESTDIR)/$(PGM) $(DESTDIR)/$(PGM): $(SRCS) $(LIBS) $(HDRS) $(EXTLIBS) @make clean @make DESTDIR=$(DESTDIR) install xall: clean @make DESTDIR="$(XDESTDIR)$(DESTDIR)" CC=$(XCC) AS=$(XAS) CFLAGS=$(XCFLAGS) STATE=$(STATE) -mv -f $(XDESTDIR)$(DESTDIR)/$(PGM) $(XDESTDIR)$(DESTDIR)/$(OLDDIR) -mv -f $(XDESTDIR)$(LIB)/yaccpar $(XDESTDIR)$(LIB)/$(OLDDIR) -mv -f $(XDESTDIR)$(LIB)/$(LIBY) $(XDESTDIR)$(LIB)/$(OLDDIR) install $(PREFIX) -s $(OWNER) $(GROUP) $(PGM) $(XDESTDIR)$(DES -mv -f $(DESTDIR)/$(PGM) $(DESTDIR)/$(OLDDIR) -mv -f $(LIB)/yaccpar $(LIB)/$(OLDDIR) -mv -f $(LIB)/$(LIBY) $(LIB)/$(OLDDIR) install $(PREFIX) -s $(OWNER) $(GROUP) $(PGM) $(DESTDIR) install $(PREFIX) $(OWNER) $(GROUP) yaccpar $(LIB) install $(PREFIX) $(OWNER) $(GROUP) $(LIBY) $(LIB) y1.c: dextern files y2.c: dextern files y3.c: dextern files y4.c: dextern files clean: rcsin -v $(INCL) $(SRCS) libyrcsid.c rcsid.c dextern files $(LIBYSRCS) -rm -f $(SRCS) $(INCL) $(OBJS) $(PGM) documents TDIR) install $(PREFIX) $(OWNER) $(GROUP) yaccpar $(XDESTDIR)$(LIB) install $(PREFIX) $(OWNER) $(GROUP) $(LIBY) $(XDESTDIR)$(LIB) for the install script. # PREV - Previous version make flag. # PRINT - Printing utility to be used. # SRCS - Names of the source files combined to make PGM. # STATE - State of the made version (RCS). # TESTS - Names of the test scripts. There must be at least # one test. # WHICH - Location utility in use on this system. # X* - Programs specific to cross codrcsid.[co] \ dextern files libyrcsid.[co] $(LIBYSRCS) $(LIBYOBJS) rcsid.o: rcsid.c rcsid.c: $(SRCS) $(HDRS) $(LIBS) $(EXTLIBS) mklog -f "$(EXTLIBS) $(HDRS) `$(WHICH) $(CC)`" $(STATE) \ rcsid.c $(SRCS) $(INCL) $(LIBS) libyrcsid.o: libyrcsid.c libyrcsid.c: $(LIBYSRCS) mklog $(STATE) libyrcsid.c $(LIBYSRCS) depend: $(SRCS) $(INCL) # Compare SRCS includes to *HDRS and comment or correct # depending on option flag. makedepend -fix "$(IOPTS)" $(SRCS) index: ctags -wx $(HDRS) $(SRCS) pre| }  dextern. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czn"/* dextern 4.1 (Berkeley) 2/11/83 */ /* * DEXTERN - yacc include file. * * $Header: dextern,v 1.4 84/06/06 13:46:12 jimd Exp $ * $Locker: $ * * Modification from Berkeley 4.2 * Copyright (c) Tektronix Inc. * All Rights Reserved. */ /* * Author: Not Listed. * * Engineer: Jim Dailey - ECS * * Origin: Berkeley 4.2 * * Log of Revisions: * * $Log: dextern,v $ # Revision 1.4 84/06/06 13:46:12 jimd # added more descriptive comments. # */ # include # include # include  /* * 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 */ "files" # include "errdefs.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 HUGE # define ACTSIZE 12000 # define MEMSIZE 12000 # define NSTATES 750 # define NTERMS 255 # define NPROD 600 # define NNONTERM 300 # define TEMPSIZE 1200 # define CNAMSZ 5000 # define LSETSIZE 600 # define WSETSIZE 350 # endif ## 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>5] & (1<<((i)&037))) # define SETBIT(a,i) ((a)[(i)>>5] |= (1<<((i)&037))) /* * number of words needed to hold n+1FILE * ftable; /* y.tab.c file */ extern FILE * ftemp; /* tempfile to pass 2 */ extern FILE * foutput; /* y.output file */ /* * structure declarations */ struct looksets { int lset[TBITSET]; }; struct item { int *pitem; struct looksets *look; }; struct toksymb { char *name; int value; }; struct ntsymb { char *name; int tvalue; }; struct wset { int *pitem; int flag; struct looksets ws; }; /* * token information */ extern int ntokens ; /* number of tokens */ extern struct toksymb tok bits */ # define NWORDS(n) (((n)+32)/32) /* * 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 set[]; extern int toklev[]; /* vector w/ the precedence of the terminals */ /* * nonterminal information */ extern int nnonter ; /* the number of nonterminals */ extern struct ntsymb nontrst[]; /* * grammar rule information */ extern int nprod ; /* number of productions */ extern int *prdptr[]; /* pointers to descriptions of productions */ extern int levprd[] ; /* production levels to break conflicts */ /* * state information */ extern int nstate ; /* number of states */ extern struct item *pstate[]; /* pointers to the descriptions of the states */ extern int tystate[]; /* contains type information about the states */ extern int defact[]; /* the default action of the state */ extern int tstates[]; /* the states deriving each token */ extern int ntstates[]; /* the states deriving each nonterminal */ extern int mstates[]; /* cont. of chains begun in tstates & ntstates*/ /* * lookahead set information */ extern struct looksets lkst[]; extern int nolook; /* flag to turn off lookahead c   doprnt.c. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czc"omputations */ /* * working set information */ extern struct wset wsets[]; extern struct wset *cwp; /* * storage for productions */ extern int mem0[]; extern int *mem; /* * storage for action table */ extern int amem[]; /* action table storage */ extern int *memp ; /* next free action table position */ extern int indgo[]; /* index to the stored goto table */ /* * temporary vector, indexable by states, terms, or ntokens */ extern int temp1[]; extern int lineno; /* current line number */ /* * doprnt.c * * $Header: doprnt.c,v 1.2 86/09/03 18:52:19 julia Exp $ * $Locker: $ * * Modifications from Bell Labs code. * Copyright (C) 1981, 1986 Tektronix Inc. * All rights Reserved * * $Log: doprnt.c,v $ * Revision 1.2 86/09/03 18:52:19 julia * added 1986 to copyright notice * * Revision 1.1 86/08/12 10:12:40 julia * Initial revision * * Revision 1.2 85/03/04 16:31:06 toddb * Cleanup to make doprnt compatible with 4.2's vax doprnt. * * Revision 1.1 84/04/25 22:56:45/* * statistics collection variables */ extern int zzgoent ; extern int zzgobest ; extern int zzacent ; extern int zzexcp ; extern int zzclose ; extern int zzrrconf ; extern int zzsrconf ; /* * define functions with strange types... */ extern char *cstash(); extern struct looksets *flset(); extern char *symnam(); extern char *writem(); /* * default settings for a number of macros */ /* * name of yacc tempfiles */ # ifndef TEMPNAME # define TEMPNAME "yacc.tmp" # endif # ifndef ACTNAME # define toddb * Initial revision * */ #include #include #define FALSE 0 #define TRUE (!FALSE) #define FP 1 char *fcvt(), *ecvt(), *gcvt(); _doprnt(fmt,argv,stream) register char *fmt; unsigned int *argv; register FILE *stream; { register c; unsigned long num; int decpt, sign; /* must be addressed as integers for address passing */ int pad; /* MUST be signed */ register char *s,*bp; char buf[128]; int alternate, width, prec, base, strprec, i, z ACTNAME "yacc.acts" # endif /* * output file name */ # ifndef OFILE # define OFILE "y.tab.c" # endif /* * user output file name */ # ifndef FILEU # define FILEU "y.output" # endif /* * output file for # defines */ # ifndef FILED # define FILED "y.tab.h" # endif /* * command to clobber tempfiles after use */ # ifndef ZAPFILE # define ZAPFILE(x) unlink(x) # endif fine BASC 3 /* binary assoc. */ /* * flags for state generation */ # define DONE 0 # define MUSTDO 1 # define MUSTLOOKAHEAD 2 pad, hexfix; #ifdef BIGHEXNUM hexfix = 'A' - ':'; #else hexfix = 'a' - ':'; #endif while (c = *fmt++) { if (c == '%') { pad = 1; /* padding flag, initially on the left */ alternate = 0; if (*fmt == '-') { pad = -1; fmt++; } zpad = FALSE; /* zero or blank padding flag */ if (*fmt == '0') { zpad = TRUE; fmt++; } width = 0; strprec = 10000; /* very large so get all of string */ prec = 6; scanfmt: switch(c = *fmt++) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* this first number is the width */ width = c-'0'; while (((c = *fmt++) >= '0') && (c <= '9')) width = 10*width + c-'0'; fmt--; goto scanfmt; case '*': width = *argv++; goto scanfmt; case '.': if ((*fmt)=='*'){ strprec = prec = *argv++; fmt++; } else { prec = 0; while (((c = *fmt++) >= '0') && (c <= '9')) prec = 10*prec + c-'0'; fmt--; } if (prec != 0) strprec = ger */ base = 10; goto putints; #ifdef FP case 'f': /* float */ bp = buf; decpt = 0; s = fcvt(*(double *)argv,prec,&decpt,&sign); argv += 2; if (sign != 0) *bp++ = '-'; /* * No leading digits before decimal point */ if (decpt <= 0) *bp++ = '0'; /* * leading non-zero characters */ if ((base = decpt) > 0) while (base--) *bp++ = *s++; if ((base = prec) != 0 || alternate) *bp++ = '.'; if ((decpt *= -1) > 0) /* * leading zeros prec; goto scanfmt; case '#': /* alternate form */ alternate = 1; goto scanfmt; case 'l': case 'L': goto scanfmt; case 'D': case 'd': /* decimal integer */ base = -10; putints: /* having decided the base, get the number */ num = *(long *)argv++; bp = buf; i = 0; /* adjust for any signs */ if (base < 0) { base = -base; if (num & 0x80000000) /* ie. sign bit set */ { *bp++ = '-'; num = -num; } } do { /* build number in reverse orafter decimal point before first * significant digit */ while (base-- > 0) { *bp++ = '0'; if (--decpt <= 0) break; } while (base-- > 0) /* significant digits after decimal point */ *bp++ = *s++; *bp = '\0'; base = strlen(buf); width -= base; if (width < 0) width = 0; if (pad > 0) width *= -1; _strout(base, buf, width , stream, zpad ? '0' : ' '); break; case 'e': /* exponential */ bp = buf; s = (char *)ecvt(*(double *)argv,prec+1,&der in buffer */ i++; /* i is the length of the actual number */ *bp = num%base + '0'; if (*bp > '9') *bp += hexfix; bp++; } while (num = num/base); width = width - (int)(bp-buf); if (alternate && (c == 'o' || c == 'O' || c == 'x' || c == 'X')) { putc('0', stream); if (c == 'x' || c == 'X') putc(c, stream); } if (pad > 0) /* left padding if necessary */ while (width-- > 0) if (zpad) putc('0',stream); else putc(' ',stream); ifdecpt,&sign); argv += 2; if (sign) *bp++ = '-'; if (*s == '0') /* signicant digit is zero */ decpt++; *bp++ = *s++; /* digit before . */ *bp++ = '.'; while (prec--) *bp++ = *s++; /* digits after . */ *bp++ = 'e'; decpt--; if (decpt<0) { *bp++ = '-'; decpt = -decpt; } else *bp++ = '+'; *bp++ = (char)(decpt/10 + '0'); *bp++ = (char)(decpt%10 +'0'); /* while (pad++) *(bp++) = ' '; */ *bp = '\0'; base = strlen(buf); width -= base; if (width < 0) (buf[0] == '-') putc('-',stream); while (i--) /* put out number from buffer */ putc(*(--bp),stream); if (pad < 0) /* right padding if necessary */ while (width-- > 0) if (zpad) putc('0',stream); else putc(' ',stream); break; case 'O': /* octal integer */ case 'o': base = 8; /* unsigned assumed */ goto putints; case 'X': /* hexidecimal integer */ case 'x': base = 16; /* unsigned assumed */ goto putints; case 'U': case 'u': /* unsigned inte width = 0; if (pad > 0) width *= -1; _strout(base, buf, width , stream, zpad ? '0' : ' '); break; case 'g': /* general: just make it fit */ (void) gcvt(*(double *)argv,prec? prec:6,buf); base = strlen(buf); width -= base; if (width < 0) width = 0; if (pad > 0) width *= -1; _strout(base, buf, width , stream, zpad ? '0' : ' '); argv += 2; break; #else /* if floating point is NOT supported, just print out * the argument as two long hexidecimal integers */ case 'f': case 'e': case 'g': doprnt("0x%08X %08X",argv,stream); argv += 2; break; #endif case 'c': putc(*(int *)argv++,stream); break; case 's': if ((bp = *(char **)argv++)==NULL) bp = "(NULL)"; s = bp; for (i=0; strprec-- && *bp++; i++); width = width - i; if (pad > 0) while (width-- > 0) if (zpad) putc('0',stream); else putc(' ',stream); while (i--) putc(*s++,stream); if (pad < 0) while (width-- > 0) if (zpad) putc('0',stream); WORD32 tells yacc that there are at least 32 bits per * int on some systems, notably IBM, the names for the * output files and tempfiles must also be changed. * * Log of Revisions: * * $Log: files,v $ # Revision 1.3 84/06/06 13:46:39 jimd # added more descriptive comments. # */ /* * location of the parser text file */ # define PARSER "/sys/usr/lib/yaccpar" /* * basic size of the Yacc implementation */ # define HUGE *bp = '\0'; base = strlen(buf); width -= base; if (width < 0) else putc(' ',stream); break; case 0: putc('%',stream); return; /* fmt ended with %" */ /* case '%': */ default: putc(c,stream); break; } /* switch (c */ } /* if (c == '%') */ else putc(c,stream); } /* while */ } /* doprnt */ v++; bp = buf; i = 0; /* adjust for any signs */ if (base < 0) { base = -base; if (num & 0x80000000) /* ie. sign bit set */ { *bp++ = '-'; num = -num; } } do { /* build number in reverse or    hoc.y. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czy"   files. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czs"%{ #define YYSTYPE double /* data type of yacc stack */ %} %token NUMBER %left '+' '-' /* left associative, same precedence */ %left '*' '/' /* left assoc., higher precedence */ %% list: /* nothing */ | list '\n' | list expr '\n' { printf("\t%.8g\n", $2); } ; expr: NUMBER { $$ = $1; } | expr '+' expr { $$ = $1 + $3; } | expr '-' expr { $$ = $1 - $3; } | expr '*' expr { $$ = $1 * $3; } | expr '/' expr { $$ = $1 / $3; } | '(' expr ')' { $$ = $2; } ; %% /* end of grammar */ #include #include char *progname; /* for error messages */ int lineno = 1; main(argc, argv) /* hoc1 */ char *argv[]; { progname = argv[0]; yyparse(); } yylex() /* hoc1 */ { int c; while ((c=getchar()) == ' ' || c == '\t') ; if (c == EOF) return 0; if (c == '.' || isdigit(c)) { /* number */ ungetc(c, stdin); scanf("%lf", &yylval); return NUMBER; } if (c == '\n') lineno++; return c; } yyerror(s) /* called for yacc syntax error */ char *s; { warning(s, (char *) 0); } warning(s, t) /* print warning message */ char *s, *t; { fprintf(stderr, "%s: %s", progname, s); if (t) fprintf(stderr, " %s", t); fprintf(stderr, " near line %d\n", lineno); } t(*(double *)argv,prec? prec:6,buf); base = strlen(buf); width -= base; if (width < 0) width = 0; if (pad > 0) width *= -1; _strout(base, buf, width , stream, zpad ? '0' : ' '); argv += 2; break; #else /* if floating point is NOT supported, just print out * the argument as two long hexidecimal inchar _libyrcsid[] = "$Header: libyrcsid.c,v 1.19 86/11/17 21:32:02 hutch Exp $"; /* + libmai.c: * libmai.c,v 1.2 84/06/06 13:47:07 jimd Exp $Locker: $ + libzer.c: * libzer.c,v 1.1 84/04/10 09:57:21 jimd Exp $Locker: $ + /usr/bin/cc: + rcsid.c,v 1.34 85/08/08 15:40:43 steveh Exp + /usr/bin/make: + rcsid.c,v 1.106 85/09/20 17:07:40 maynard Exp */ 56:58 jimd * Initial revision * */ main(){ yyparse(); } ')' { $$ = $2; } ; %% /* end of grammar */ #include yyerror( s ) char *s; { fprintf( stderr, "%s\n", s ); } * Initial revision * */ main(){ yyparse(); } ')' { $$ = $2; } ; %% /* end of grammar */ #include #include char *progname; /* for error messages */ int lineno = 1; main(argc, argv) /* hoc1 */ char *argv[]; { progname = argv[0]; yyparse(); } yylex() /* hoc1 */ { int c; while ((c=getchar()) == ' ' || c == '\t')T  U  t1.y. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czy" ; if (c == EOF) return 0; if (c == '.' || isdigit(c)) { /* number */ ungetc(c, stdin); scanf("%lf", &yylval); return NUMBER; } if (c == '\n') lineno++; return c; } yyerror(s) /* called for yacc syntax error */ char *s; { warning(s, (char *) 0); } warning(s, t) /* print warning message */ char *s, *t; { fprintf(stderr, "%s: %s", progname, s); if (t) fprintf(stderr, " %s", t); fprintf(stderr, " near line %d\n", lineno); } error */ char *s; { warning(s, (char *) 0); } warning(s%token DING DONG DELL %% rhyme : sound place ; sound : DING DONG ; place : DELL ; * y1.c,v 1.2 83/12/23 13:35:38 jimd Exp $Locker: $ + y2.c: * y2.c,v 1.6 84/06/22 11:06:26 jimd Exp $Locker: $ + y3.c: * y3.c,v 1.2 83/12/23 13:37:39 jimd Exp $Locker: $ + y4.c: * y4.c,v 1.2 83/12/23 13:37:52 jimd Exp $Locker: $ + dextern: * dextern,v 1.4 84/06/06 13:46:12 jimd Exp $Locker: $ + files: * files,v 1.3 84/06/06 13:46:39 jimd Exp $Locker: $ + /usr/bin/cc    t3.y. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czy"%{ #define YYSTYPE double /* data type of yacc stack */ %} %token NUMBER %left '+' %% list: /* nothing */ | list 'z' | list expr 'z' { printf("\t%.8g\n", $2); } ; expr: NUMBER { $$ = $1; } | expr '+' expr { $$ = $1 + $3; } ; %% /* end of grammar */ #include #include char *progname; /* for error messages */ int lineno = 1; main(argc, argv) /* hoc1 */ char *argv[]; { progname = argv[0]; yyparse(); } yylex() /* hoc1 */ { int c; while ((c=getchar()) == ' ' || c == '\t')  4, 3 }; short yyr1[]={ 0, 1, 2, 3 }; short yyr2[]={ 0, 2, 2, 1 }; short yychk[]={ -1000, -1, -2, 257, -3, 259, 258 }; short yydef[]={ 0, -2, 0, 0, 1, 3, 2 }; /* static char yaccpar_sccsid[] = "@(#)yaccpar 4.1 (Berkeley) 2/11/83"; */ # # define YYFLAG -1000 # define YYERROR goto yyerrlab # define YYACCEPT return(0) # define YYABORT return(1) /* parser for yacc output */ #ifdef YYDEBUG int yydebug = 0; /* 1 for debugging */ #endif YYSTYPE yyv[YYMAXDEPTH]; /* where ; if (c == EOF) return 0; if (c == '.' || isdigit(c)) { /* number */ ungetc(c, stdin); scanf("%lf", &yylval); return NUMBER; } if (c == '\n') lineno++; return c; } yyerror(s) /* called for yacc syntax error */ char *s; { warning(s, (char *) 0); } warning(s, t) /* print warning message */ char *s, *t; { fprintf(stderr, "%s: %s", progname, s); if (t) fprintf(stderr, " %s", t); fprintf(stderr, " near line %d\n", lineno); } } error */ char *s; { warning(s, (char *) 0); } warning(s the values are stored */ int yychar = -1; /* current input token number */ int yynerrs = 0; /* number of errors */ short yyerrflag = 0; /* error recovery flag */ yyparse() { short yys[YYMAXDEPTH]; short yyj, yym; register YYSTYPE *yypvt; register short yystate, *yyps, yyn; register YYSTYPE *yypv; register short *yyxi; yystate = 0; yychar = -1; yynerrs = 0; yyerrflag = 0; yyps= &yys[-1]; yypv= &yyv[-1]; yystack: /* put a state and value onto the stack */ #ifdef YYDEBUG if( yydebug )/  0  y.tab.c. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czc" printf( "state %d, char 0%o\n", yystate, yychar ); #endif if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); } *yyps = yystate; ++yypv; *yypv = yyval; yynewstate: yyn = yypact[yystate]; if( yyn<= YYFLAG ) goto yydefault; /* simple state */ if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0; if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault; if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */ yychar = -1; yyval = yylval; yystate = yyn; if( y#define DING 257 #define DONG 258 #define DELL 259 #define yyclearin yychar = -1 #define yyerrok yyerrflag = 0 extern int yychar; extern short yyerrflag; #ifndef YYMAXDEPTH #define YYMAXDEPTH 150 #endif #ifndef YYSTYPE #define YYSTYPE int #endif YYSTYPE yylval, yyval; # define YYERRCODE 256 short yyexca[] ={ -1, 1, 0, -1, -2, 0, }; # define YYNPROD 4 # define YYLAST 6 short yyact[]={ 5, 6, 3, 4, 2, 1 }; short yypact[]={ -255,-1000,-259,-257,-1000,-1000,-1000 }; short yypgo[]={ 0, 5, yerrflag > 0 ) --yyerrflag; goto yystack; } yydefault: /* default state action */ if( (yyn=yydef[yystate]) == -2 ) { if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0; /* look through exception table */ for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */ while( *(yyxi+=2) >= 0 ){ if( *yyxi == yychar ) break; } if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */ } if( yyn == 0 ){ /* error */ /* error ... attempt to resume parsing */ switch( yyerrflag ){ case 0: /* brand new error */ yyerrlab: yyerror( "syntax error" ); ++yynerrs; case 1: case 2: /* incompletely recovered error ... try again */ yyerrflag = 3; /* find a state where "error" is a legal shift action */ while ( yyps >= yys ) { yyn = yypact[*yyps] + YYERRCODE; if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){ yystate = yyact[yyn]; /* simulate a shift of "error" */ goto yystack; } yyn = yypact[*/  0  y.tabt1.c. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czc"yyps]; /* the current yyps has no shift onn "error", pop stack */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] ); #endif --yyps; --yypv; } /* there is no state on the stack with an error shift ... abort */ yyabort: return(1); case 3: /* no shift yet; clobber input char */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery discards char %d\n", yychar ); #endif if( yychar == 0 ) goto yyabort; /* don'#define DING 257 #define DONG 258 #define DELL 259 #define yyclearin yychar = -1 #define yyerrok yyerrflag = 0 extern int yychar; extern short yyerrflag; #ifndef YYMAXDEPTH #define YYMAXDEPTH 150 #endif #ifndef YYSTYPE #define YYSTYPE int #endif YYSTYPE yylval, yyval; # define YYERRCODE 256 short yyexca[] ={ -1, 1, 0, -1, -2, 0, }; # define YYNPROD 4 # define YYLAST 6 short yyact[]={ 5, 6, 3, 4, 2, 1 }; short yypact[]={ -255,-1000,-259,-257,-1000,-1000,-1000 }; short yypgo[]={ 0, 5, t discard EOF, quit */ yychar = -1; goto yynewstate; /* try again in the same state */ } } /* reduction by production yyn */ #ifdef YYDEBUG if( yydebug ) printf("reduce %d\n",yyn); #endif yyps -= yyr2[yyn]; yypvt = yypv; yypv -= yyr2[yyn]; yyval = yypv[1]; yym=yyn; /* consult goto table to find next state */ yyn = yyr1[yyn]; yyj = yypgo[yyn] + *yyps + 1; if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]]; switch(yym){ } got 4, 3 }; short yyr1[]={ 0, 1, 2, 3 }; short yyr2[]={ 0, 2, 2, 1 }; short yychk[]={ -1000, -1, -2, 257, -3, 259, 258 }; short yydef[]={ 0, -2, 0, 0, 1, 3, 2 }; /* static char yaccpar_sccsid[] = "@(#)yaccpar 4.1 (Berkeley) 2/11/83"; */ # # define YYFLAG -1000 # define YYERROR goto yyerrlab # define YYACCEPT return(0) # define YYABORT return(1) /* parser for yacc output */ #ifdef YYDEBUG int yydebug = 0; /* 1 for debugging */ #endif YYSTYPE yyv[YYMAXDEPTH]; /* whereo yystack; /* stack new state and value */ } 59 #define yyclearin yychar = -1 #define yyerrok yyerrflag = 0 extern int yychar; extern short yyerrflag; #ifndef YYMAXDEPTH #define YYMAXDEPTH 150 #endif #ifndef YYSTYPE #define YYSTYPE int #endif YYSTYPE yylval, yyval; # define YYERRCODE 256 short yyexca[] ={ -1, 1, 0, -1, -2, 0, }; # define YYNPROD 4 # define YYLAST 6 short yyact[]={ 5, 6, 3, 4, 2, 1 }; short yypact[]={ -255,-1000,-259,-257,-1000,-1000,-1000 }; short yypgo[]={ 0, 5,  the values are stored */ int yychar = -1; /* current input token number */ int yynerrs = 0; /* number of errors */ short yyerrflag = 0; /* error recovery flag */ yyparse() { short yys[YYMAXDEPTH]; short yyj, yym; register YYSTYPE *yypvt; register short yystate, *yyps, yyn; register YYSTYPE *yypv; register short *yyxi; yystate = 0; yychar = -1; yynerrs = 0; yyerrflag = 0; yyps= &yys[-1]; yypv= &yyv[-1]; yystack: /* put a state and value onto the stack */ #ifdef YYDEBUG if( yydebug ) printf( "state %d, char 0%o\n", yystate, yychar ); #endif if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); } *yyps = yystate; ++yypv; *yypv = yyval; yynewstate: yyn = yypact[yystate]; if( yyn<= YYFLAG ) goto yydefault; /* simple state */ if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0; if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault; if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */ yychar = -1; yyval = yylval; yystate = yyn; if( yt discard EOF, quit */ yychar = -1; goto yynewstate; /* try again in the same state */ } } /* reduction by production yyn */ #ifdef YYDEBUG if( yydebug ) printf("reduce %d\n",yyn); #endif yyps -= yyr2[yyn]; yypvt = yypv; yypv -= yyr2[yyn]; yyval = yypv[1]; yym=yyn; /* consult goto table to find next state */ yyn = yyr1[yyn]; yyj = yypgo[yyn] + *yyps + 1; if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]]; switch(yym){ } gotyerrflag > 0 ) --yyerrflag; goto yystack; } yydefault: /* default state action */ if( (yyn=yydef[yystate]) == -2 ) { if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0; /* look through exception table */ for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */ while( *(yyxi+=2) >= 0 ){ if( *yyxi == yychar ) break; } if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */ } if( yyn == 0 ){ /* error */ /* error ... attempt to resume parsing */ switch( yo yystack; /* stack new state and value */ } 59 #define yyclearin yychar = -1 #define yyerrok yyerrflag = 0 extern int yychar; extern short yyerrflag; #ifndef YYMAXDEPTH #define YYMAXDEPTH 150 #endif #ifndef YYSTYPE #define YYSTYPE int #endif YYSTYPE yylval, yyval; # define YYERRCODE 256 short yyexca[] ={ -1, 1, 0, -1, -2, 0, }; # define YYNPROD 4 # define YYLAST 6 short yyact[]={ 5, 6, 3, 4, 2, 1 }; short yypact[]={ -255,-1000,-259,-257,-1000,-1000,-1000 }; short yypgo[]={ 0, 5, yerrflag ){ case 0: /* brand new error */ yyerrlab: yyerror( "syntax error" ); ++yynerrs; case 1: case 2: /* incompletely recovered error ... try again */ yyerrflag = 3; /* find a state where "error" is a legal shift action */ while ( yyps >= yys ) { yyn = yypact[*yyps] + YYERRCODE; if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){ yystate = yyact[yyn]; /* simulate a shift of "error" */ goto yystack; } yyn = yypact[*     y.tabt2.c. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czc"yyps]; /* the current yyps has no shift onn "error", pop stack */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] ); #endif --yyps; --yypv; } /* there is no state on the stack with an error shift ... abort */ yyabort: return(1); case 3: /* no shift yet; clobber input char */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery discards char %d\n", yychar ); #endif if( yychar == 0 ) goto yyabort; /* don' # line 2 "t2.y" #define YYSTYPE double /* data type of yacc stack */ #define NUMBER 257 #define yyclearin yychar = -1 #define yyerrok yyerrflag = 0 extern int yychar; extern short yyerrflag; #ifndef YYMAXDEPTH #define YYMAXDEPTH 150 #endif #ifndef YYSTYPE #define YYSTYPE int #endif YYSTYPE yylval, yyval; # define YYERRCODE 256 # line 14 "t2.y" /* end of grammar */ #include #include char *progname; /* for error messages */ int lineno = 1; main(argc, argv) /* hoc1 */ char *argv[]; { progname = argv[0]; yyparse(); } yylex() /* hoc1 */ { int c; while ((c=getchar()) == ' ' || c == '\t') ; if (c == EOF) return 0; if (c == '.' || isdigit(c)) { /* number */ ungetc(c, stdin); scanf("%lf", &yylval); return NUMBER; } if (c == '\n') lineno++; return c; } yyerror(s) /* called for yacc syntax error */ char *s; { warning(s, (char *) 0); } warning(s, t) /* print warning message */ char *s, *t; { fprintf(stderr, "%s: %s", progname, s); if (t) fprintf(stderr, " %s",, 1, 2, 2 }; short yyr2[]={ 0, 0, 2, 3, 1, 3 }; short yychk[]={ -1000, -1, 13, -2, 257, 13, 43, -2 }; short yydef[]={ 1, -2, 2, 0, 4, 3, 0, 5 }; /* static char yaccpar_sccsid[] = "@(#)yaccpar 4.1 (Berkeley) 2/11/83"; */ # # define YYFLAG -1000 # define YYERROR goto yyerrlab # define YYACCEPT return(0) # define YYABORT return(1) /* parser for yacc output */ #ifdef YYDEBUG int yydebug = 0; /* 1 for debugging */ #endif YYSTYPE yyv[YYMAXDEPTH]; /* where the values  t); fprintf(stderr, " near line %d\n", lineno); } short yyexca[] ={ -1, 1, 0, -1, -2, 0, }; # define YYNPROD 6 # define YYLAST 245 short yyact[]={ 2, 4, 5, 3, 1, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, are stored */ int yychar = -1; /* current input token number */ int yynerrs = 0; /* number of errors */ short yyerrflag = 0; /* error recovery flag */ yyparse() { short yys[YYMAXDEPTH]; short yyj, yym; register YYSTYPE *yypvt; register short yystate, *yyps, yyn; register YYSTYPE *yypv; register short *yyxi; yystate = 0; yychar = -1; yynerrs = 0; yyerrflag = 0; yyps= &yys[-1]; yypv= &yyv[-1]; yystack: /* put a state and value onto the stack */ #ifdef YYDEBUG if( yydebug ) printf( "st 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0ate %d, char 0%o\n", yystate, yychar ); #endif if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); } *yyps = yystate; ++yypv; *yypv = yyval; yynewstate: yyn = yypact[yystate]; if( yyn<= YYFLAG ) goto yydefault; /* simple state */ if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0; if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault; if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */ yychar = -1; yyval = yylval; yystate = yyn; if( yyerrflag > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }; short yypact[]={ -1000, -13,-1000, -11,-1000,-1000,-256,-1000 }; short yypgo[]={ 0, 4, 3 }; short yyr1[]={ 0, 1, 1 ) --yyerrflag; goto yystack; } yydefault: /* default state action */ if( (yyn=yydef[yystate]) == -2 ) { if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0; /* look through exception table */ for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */ while( *(yyxi+=2) >= 0 ){ if( *yyxi == yychar ) break; } if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */ } if( yyn == 0 ){ /* error */ /* error ... attempt to resume parsing */ switch( yyerrflag ){  case 0: /* brand new error */ yyerrlab: yyerror( "syntax error" ); ++yynerrs; case 1: case 2: /* incompletely recovered error ... try again */ yyerrflag = 3; /* find a state where "error" is a legal shift action */ while ( yyps >= yys ) { yyn = yypact[*yyps] + YYERRCODE; if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){ yystate = yyact[yyn]; /* simulate a shift of "error" */ goto yystack; } yyn = yypact[*yyps];      y.tabt3.c. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czc" /* the current yyps has no shift onn "error", pop stack */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] ); #endif --yyps; --yypv; } /* there is no state on the stack with an error shift ... abort */ yyabort: return(1); case 3: /* no shift yet; clobber input char */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery discards char %d\n", yychar ); #endif if( yychar == 0 ) goto yyabort; /* don't discard EO # line 2 "t3.y" #define YYSTYPE double /* data type of yacc stack */ #define NUMBER 257 #define yyclearin yychar = -1 #define yyerrok yyerrflag = 0 extern int yychar; extern short yyerrflag; #ifndef YYMAXDEPTH #define YYMAXDEPTH 150 #endif #ifndef YYSTYPE #define YYSTYPE int #endif YYSTYPE yylval, yyval; # define YYERRCODE 256 # line 14 "t3.y" /* end of grammar */ #include #include char *progname; /* for error messages */ int lineno = 1; main(argc, argv) /* hoc1 */ char *argv[]; {F, quit */ yychar = -1; goto yynewstate; /* try again in the same state */ } } /* reduction by production yyn */ #ifdef YYDEBUG if( yydebug ) printf("reduce %d\n",yyn); #endif yyps -= yyr2[yyn]; yypvt = yypv; yypv -= yyr2[yyn]; yyval = yypv[1]; yym=yyn; /* consult goto table to find next state */ yyn = yyr1[yyn]; yyj = yypgo[yyn] + *yyps + 1; if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]]; switch(yym){ case 3: # line 9 "t2. progname = argv[0]; yyparse(); } yylex() /* hoc1 */ { int c; while ((c=getchar()) == ' ' || c == '\t') ; if (c == EOF) return 0; if (c == '.' || isdigit(c)) { /* number */ ungetc(c, stdin); scanf("%lf", &yylval); return NUMBER; } if (c == '\n') lineno++; return c; } yyerror(s) /* called for yacc syntax error */ char *s; { warning(s, (char *) 0); } warning(s, t) /* print warning message */ char *s, *t; { fprintf(stderr, "%s: %s", progname, s); if (t) fprintf(stderr, " %s",y" { printf("\t%.8g\n", yypvt[-1]); } break; case 4: # line 11 "t2.y" { yyval = yypvt[-0]; } break; case 5: # line 12 "t2.y" { yyval = yypvt[-2] + yypvt[-0]; } break; } goto yystack; /* stack new state and value */ } , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }; short yypact[]={ -1000, -13,-1000, -11,-1000,-1000,-256,-1000 }; short yypgo[]={ 0, 4, 3 }; short yyr1[]={ 0, 1, 1 t); fprintf(stderr, " near line %d\n", lineno); } short yyexca[] ={ -1, 1, 0, -1, -2, 0, }; # define YYNPROD 6 # define YYLAST 136 short yyact[]={ 2, 4, 6, 3, 1, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }; short yypact[]={ -1000,-122,-1000, -41,-1000,-1000,-256,-1000 }; short yypgo[]={ 0, 4, 3 }; short yyr1[]={ 0, 1, 1, 1, 2, 2 }; short yyr2[]={ 0, 0ult: /* default state action */ if( (yyn=yydef[yystate]) == -2 ) { if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0; /* look through exception table */ for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */ while( *(yyxi+=2) >= 0 ){ if( *yyxi == yychar ) break; } if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */ } if( yyn == 0 ){ /* error */ /* error ... attempt to resume parsing */ switch( yyerrflag ){ case 0: /* brand new error */ yyerrl, 2, 3, 1, 3 }; short yychk[]={ -1000, -1, 122, -2, 257, 122, 43, -2 }; short yydef[]={ 1, -2, 2, 0, 4, 3, 0, 5 }; /* static char yaccpar_sccsid[] = "@(#)yaccpar 4.1 (Berkeley) 2/11/83"; */ # # define YYFLAG -1000 # define YYERROR goto yyerrlab # define YYACCEPT return(0) # define YYABORT return(1) /* parser for yacc output */ #ifdef YYDEBUG int yydebug = 0; /* 1 for debugging */ #endif YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */ int yychar = -1; /* current inab: yyerror( "syntax error" ); ++yynerrs; case 1: case 2: /* incompletely recovered error ... try again */ yyerrflag = 3; /* find a state where "error" is a legal shift action */ while ( yyps >= yys ) { yyn = yypact[*yyps] + YYERRCODE; if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){ yystate = yyact[yyn]; /* simulate a shift of "error" */ goto yystack; } yyn = yypact[*yyps]; /* the current yyps has no shift onn "erroput token number */ int yynerrs = 0; /* number of errors */ short yyerrflag = 0; /* error recovery flag */ yyparse() { short yys[YYMAXDEPTH]; short yyj, yym; register YYSTYPE *yypvt; register short yystate, *yyps, yyn; register YYSTYPE *yypv; register short *yyxi; yystate = 0; yychar = -1; yynerrs = 0; yyerrflag = 0; yyps= &yys[-1]; yypv= &yyv[-1]; yystack: /* put a state and value onto the stack */ #ifdef YYDEBUG if( yydebug ) printf( "state %d, char 0%o\n", yystate, yychar ); #endr", pop stack */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] ); #endif --yyps; --yypv; } /* there is no state on the stack with an error shift ... abort */ yyabort: return(1); case 3: /* no shift yet; clobber input char */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery discards char %d\n", yychar ); #endif if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */ yychar = -1; goto yynewstatif if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); } *yyps = yystate; ++yypv; *yypv = yyval; yynewstate: yyn = yypact[yystate]; if( yyn<= YYFLAG ) goto yydefault; /* simple state */ if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0; if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault; if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */ yychar = -1; yyval = yylval; yystate = yyn; if( yyerrflag > 0 ) --yyerrflag; goto yystack; } yydefae; /* try again in the same state */ } } /* reduction by production yyn */ #ifdef YYDEBUG if( yydebug ) printf("reduce %d\n",yyn); #endif yyps -= yyr2[yyn]; yypvt = yypv; yypv -= yyr2[yyn]; yyval = yypv[1]; yym=yyn; /* consult goto table to find next state */ yyn = yyr1[yyn]; yyj = yypgo[yyn] + *yyps + 1; if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]]; switch(yym){ case 3: # line 9 "t3.y" { printf("\t%.8g\n", yypvt[-1]); } break; case 4: # line 11 "t3.y" { yyval = yypvt[-0]; } break; case 5: # line 12 "t3.y" { yyval = yypvt[-2] + yypvt[-0]; } break; } goto yystack; /* stack new state and value */ } , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }; short yypact[]={ -1000,-122,-1000, -41,-1000,-1000,-256,-1000 }; short yypgo[]={ 0, 4, 3 }; short yyr1[]={ 0, 1, 1, 1, 2, 2 }; short yyr2[]={ 0, 0tations */ /* * 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 the descriptions of the states */ int tystate[NSTATES]; /* contains type information about the states */ int indgo[NSTATES]; /* index to the stored goto table */ int tstates[ NTERMS ]; /* states generated by terminal gotos */ int ntstates[ NNONTERM ]; /* states generateE E   y1.c. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czc"d by nonterminal gotos */ int mstates[ NSTATES ]; /* chain of overflows 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 /* static char sccsid[] = "@(#)y1.c 4.1 (Berkeley) 2/11/83"; */ /* * Y1.C - yacc * * $Header: y1.c,v 1.2 83/12/23 13:35:38 jimd Exp $ * $Locker: $ * * Modification from Berkeley 4.2 * Copyright (c) Tektronix Inc. * All Rights Reserved. * */ /* * Author: Not Listed. * * Engineer: Jim Dailey - ECS * * Origin: Berkeley 4.2 * * Calling Structure: * * Changes made to version 1.1: * * 1. Standard Changes * * o Added the above and following header information. * o Add errdefs include andnerrors = 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 */ main(argc, argv) int argc; char *argv[]; { /* * initialize and read productions */ setup(argc,argv); tbitset = made register variables. * * Log of Revisions: * * $Log: y1.c,v $ * Revision 1.2 83/12/23 13:35:38 jimd * see * header * , * * */ #include "dextern" /* * variables used locally */ /* * 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 compu NWORDS(ntokens); /* * make table of which productions yield a given nonterminal */ cpres(); /* * make a table of which nonterminals can match the empty string */ cempty(); /* * make a table of firsts of nonterminals */ cpfir(); /* * generate the states */ stagen(); /* * write the states and the tables */ output(); go2out(); hideprod(); summary(); callopt(); others(); exit(NO_ERRS); } /* * put out other arrays, copy the parsers */ others() { register c, i,  j; finput = fopen(PARSER, "r"); if (finput == NULL) error("cannot find parser %s", PARSER); warray("yyr1", levprd, nprod); aryfil(temp1, nprod, 0); PLOOP(1,i)temp1[i] = prdptr[i+1]-prdptr[i]-2; warray("yyr2", temp1, nprod); aryfil(temp1, nstate, -1000); TLOOP(i) { for (j=tstates[i]; j!=0; j=mstates[j]) { temp1[j] = tokset[i].value; } } NTLOOP(i) { for (j=ntstates[i]; j!=0; j=mstates[j]) { temp1[j] = -i; } } warray("yychk", temp1, nstate); warray("yydef", defact, nstate); /* * output the summary on the tty */ summary() { if (foutput!=NULL) { fprintf(foutput, "\n%d/%d terminals, %d/%d nonterminals\n", ntokens, NTERMS, nnonter, NNONTERM); fprintf (foutput, "%d/%d grammar rules, %d/%d states\n", nprod, NPROD, nstate, NSTATES); fprintf(foutput, "%d shift/reduce, %d reduce/reduce conflicts reported\n", zzsrconf, zzrrconf); fprintf(foutput, "%d/%d working sets used\n", zzcwp-wsets, WSETSIZE); fprintf(foutput, "memory: states,etc. %d/%d, parser %d/%d\n" /* * copy parser text */ while ((c=getc(finput) ) != EOF) { if (c == '$') { if ((c=getc(finput)) != 'A') putc('$', ftable); else { /* copy actions */ faction = fopen(ACTNAME, "r"); if (faction == NULL) error("cannot reopen action tempfile"); while ((c=getc(faction)) != EOF) putc(c, ftable); fclose(faction); ZAPFILE(ACTNAME); c = getc(finput); } } putc(c, ftable); } fclose(ftable); } /* * copies string q into p, returning next free char, zzmemsz-mem0, MEMSIZE, memp-amem, ACTSIZE); fprintf(foutput, "%d/%d distinct lookahead sets\n", nlset, LSETSIZE); fprintf(foutput, "%d extra closures\n", zzclose - 2*nstate); fprintf(foutput, "%d shift entries, %d exceptions\n", zzacent, zzexcp); fprintf(foutput, "%d goto entries\n", zzgoent); fprintf(foutput, "%d entries saved by goto default\n", zzgobest); } if (zzsrconf!=0 || zzrrconf!=0) { fprintf(stdout,"\nconflicts: "); if (zzsrconf) fprintf(stdout, "%d shif ptr */ char *chcopy(p, q) char *p, *q; { while (*p = *q++) ++p; return (p); } /* * creates output string for item pointed to by pp */ # define ISIZE 400 char *writem(pp) int *pp; { int i,*p; static char sarr[ISIZE]; char *q; for (p=pp; *p>0 ; ++p) ; p = prdptr[-*p]; q = chcopy(sarr, nontrst[*p-NTBASE].name); q = chcopy(q, " : "); for (;;) { *q++ = ++p==pp ? '_' : ' '; *q = '\0'; if ((i = *p) <= 0) break; q = chcopy(q, symnam(i)); if (q> &sarr[ISIZE-30]) error("item tt/reduce", zzsrconf); if (zzsrconf && zzrrconf) fprintf(stdout, ", "); if (zzrrconf) fprintf(stdout, "%d reduce/reduce", zzrrconf); fprintf(stdout, "\n"); } fclose(ftemp); if (fdefine != NULL) fclose(fdefine); } /* VARARGS1 */ /* * write out error comment */ error(s, a1) char *s; { ++nerrors; fprintf(stderr, "\nfatal error : "); fprintf(stderr, s,a1); fprintf(stderr, ", line %d\n", lineno ); if (!fatfl) return; summary(); exit(NP_ERR); } /* * set elements 0 throuoo big"); } /* * an item calling for a reduction */ if ((i = *pp) < 0) { q = chcopy(q, " ("); sprintf(q, "%d)", -i); } return (sarr); } /* * return a pointer to the name of symbol i */ char *symnam(i) { char *cp; cp = (i>=NTBASE) ? nontrst[i-NTBASE].name : tokset[i].name ; if (*cp == ' ') ++cp; return (cp); } 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;gh n-1 to c */ aryfil(v, n, c) int *v,n,c; { int i; for (i=0; ilset; if (pp == 0) fprintf(foutput, "\tNULL"); else { fprintf(foutput, " { "); TLOOP(j) { if (BIT(pp, j)) fprintf(foutput, "%s ", symnam(j)); } fprintf(foutput, "}"); } } /* * compute an array with the beginnings of productions * yielding given nonterminals The array pres points * to these lists * * the array pyield has the lists: the total size is only NPROD+1 */ cpres() { register **pmem; register c, j, i; static int * pyield[NPROD]; pmem = pyield; NTLOOP(i) { c = i+NTBASE; pres[i] = pmem; fatfl = 0; /* make undefined symbols nonfatal */ PLOOP(0,j) { if (*prdptr[j] if (p1 == p2) return(0); /* null state */ /* * sort the items */ for (k=p2-1; k>p1; k--) { /* make k the biggest */ for (l=k-1; l>=p1; --l) if (l->pitem > k->pitem) { int *s; struct looksets *ss; s = k->pitem; k->pitem = l->pitem; l->pitem = s; ss = k->look; k->look = l->look; l->look = ss; } } size1 = p2 - p1; /* size of state */ for (i=(c>=NTBASE)?ntstates[c-NTBASE]:tstates[c];i!=0;i=mstates[i]) { /* * get ith state */ q1 = pstate[i== c) *pmem++ = prdptr[j]+1; } if (pres[i] == pmem) { error("nonterminal %s not defined!", nontrst[i].name); } } pres[i] = pmem; fatfl = 1; if (nerrors) { summary(); exit(NP_ERR); } if (pmem != &pyield[nprod]) error("internal yacc error : pyield %d", pmem-&pyield[nprod]); } int indebug = 0; /* * compute an array with the first of nonterminals */ cpfir() { register *p, **s, i, **t, ch, changes; zzcwp = &wsets[nnonter]; NTLOOP(i) { aryfil(wsets[i].ws.lset, tbitset, 0); ]; q2 = pstate[i+1]; size2 = q2 - q1; if (size1 != size2) continue; k=p1; for (l=q1;lpitem != k->pitem) break; ++k; } if (l != q2) continue; /* * found it */ pstate[nstate+1] = pstate[nstate]; /* delete last state */ /* * fix up lookaheads */ if (nolook) return(i); for (l=q1,k=p1; llook->lset[s]; if (setunion(clset.lset, k->look->lset)) { tystate[i] = MUSTDO;  t = pres[i+1]; for (s=pres[i]; s 0 ; ++p) { if (ch < NTBASE) { SETBIT(wsets[i].ws.lset, ch); break; } else if (!pempty[ch-NTBASE]) break; } } } /* * now, reflect transitivity */ changes = 1; while (changes) { changes = 0; NTLOOP(i) { t = pres[i+1]; for (s=pres[i]; s= 0; ++p) { changes |= setunion(wsets[i].ws.lset, wsets[ch].ws./* * register the new set */ l->look = flset(&clset); } } return (i); } /* * state is new */ if (nolook) error("yacc state/nolook error"); pstate[nstate+2] = p2; if (nstate+1 >= NSTATES) error("too many states"); if (c >= NTBASE) { mstates[nstate] = ntstates[ c-NTBASE ]; ntstates[ c-NTBASE ] = nstate; } else { mstates[ nstate ] = tstates[ c ]; tstates[ c ] = nstate; } tystate[nstate]=MUSTDO; return(nstate++); } int pidebug = 0; /* debugging flag for plset); if(!pempty[ch]) break; } } } } NTLOOP(i) pfirst[i] = flset(&wsets[i].ws); if (!indebug) return; if ((foutput!=NULL)) { NTLOOP(i) { fprintf(foutput, "\n%s: ", nontrst[i].name); prlook(pfirst[i]); fprintf(foutput, " %d\n", pempty[i]); } } } /* * sorts last state,and sees if it equals * earlier ones. returns state number */ state(c) { int size1,size2; register i; struct item *p1, *p2, *k, *l, *q1, *q2; p1 = pstate[nstate]; p2 = pstate[nstate+1]; utitem */ putitem(ptr, lptr) int *ptr; struct looksets *lptr; { register struct item *j; if (pidebug && (foutput!=NULL)) { fprintf(foutput,"putitem(%s), state %d\n",writem(ptr),nstate); } j = pstate[nstate+1]; j->pitem = ptr; if (!nolook) j->look = flset( lptr ); pstate[nstate+1] = ++j; if ((int *)j > zzmemsz) { zzmemsz = (int *)j; if (zzmemsz >= &mem0[MEMSIZE]) error("out of state space"); } } /* * mark nonterminals which derive the empty string * * also, look for nonterminals whi ch don't derive any token strings */ cempty() { # define EMPTY 1 # define WHOKNOWS 0 # define OK 1 register i, *p; /* * first, use the array pempty to detect * productions that can never be reduced */ /* * set pempty to WHONOWS */ aryfil(pempty, nnonter+1, WHOKNOWS); /* * now, look at productions, marking nonterminals * which derive something */ more: PLOOP(0,i) { if (pempty[ *prdptr[i] - NTBASE ]) continue; for (p=prdptr[i]+1; *p>=0; ++p) { if (*p>=NTBASE && pemptlocate all this * stuff... for now, we accept that if pointers don't * fit in integers, there is a problem... */ pstate[0] = pstate[1] = (struct item *)mem; aryfil(clset.lset, tbitset, 0); putitem(prdptr[0]+1, &clset); tystate[0] = MUSTDO; nstate = 1; pstate[2] = pstate[1]; aryfil(amem, ACTSIZE, 0); /* * now, the main state generation loop */ more: SLOOP(i) { if (tystate[i] != MUSTDO) continue; tystate[i] = DONE; aryfil(temp1, nnonter+1, 0); /* * take state i, close ity[ *p-NTBASE ] == WHOKNOWS) break; } if (*p < 0) { /* production can be derived */ pempty[ *prdptr[i]-NTBASE ] = OK; goto more; } } /* * now, look at the nonterminals, to see if they are all OK */ /* * the added production rises or falls as the start symbol ... */ NTLOOP(i) { if (i == 0) continue; if (pempty[ i ] != OK) { fatfl = 0; error("nonterminal %s never derives any token string", nontrst[i].name); } } if (nerrors) { summary(); exit(NP_ERR); , and do gotos */ closure(i); WSLOOP(wsets,p) { /* generate goto's */ if (p->flag) continue; p->flag = 1; c = *(p->pitem); if (c <= 1) { if(pstate[i+1]-pstate[i] <= p-wsets) tystate[i] = MUSTLOOKAHEAD; continue; } /* * do a goto on c */ WSLOOP(p,q) { /* * this item contributes to the goto */ if (c == *(q->pitem)) { putitem(q->pitem + 1, &q->ws); q->flag = 1; } } if (c < NTBASE) { state(c); /* register new s } /* * now, compute the pempty array, to see * which nonterminals derive the empty string */ /* * set pempty to WHOKNOWS */ aryfil(pempty, nnonter+1, WHOKNOWS); /* * loop as long as we keep finding empty nonterminals */ again: PLOOP(1,i) { /* * not known to be empty */ if (pempty[ *prdptr[i]-NTBASE ]==WHOKNOWS) { for (p=prdptr[i]+1; *p>=NTBASE && pempty[*p-NTBASE]==EMPTY ; ++p) ; /* * we have a nontrivially empty nonterminal */ if (*p < 0) { ptate */ } else { temp1[c-NTBASE] = state(c); } } if (gsdebug && (foutput!=NULL)) { fprintf(foutput, "%d: ", i); NTLOOP(j) { if (temp1[j]) fprintf(foutput,"%s %d, ", nontrst[j].name, temp1[j]); } fprintf(foutput, "\n"); } indgo[i] = apack( &temp1[1], nnonter-1 ) - 1; goto more; /* we have done one goto; do some more */ } } int cldebug = 0; /* debugging flag for closure */ closure(i) { int c, ch, work, k; register struct wset *u, *v; int *pi; int **s, empty[*prdptr[i]-NTBASE] = EMPTY; goto again; /* got one ... try for another */ } } } } int gsdebug = 0; /* * generate the states */ stagen() { int i, j; register c; register struct wset *p, *q; /* * initialize */ nstate = 0; /* * THIS IS FUNNY from the standpoint of portability * it represents the magic moment when the mem0 array, * which has been holding the productions, starts to * hold item pointers, of a different type... * * someday, alloc should be used to al**t; struct item *q; register struct item *p; ++zzclose; /* * first, copy kernel of state i to wsets */ cwp = wsets; ITMLOOP(i,p,q) { cwp->pitem = p->pitem; cwp->flag = 1; /* this item must get closed */ SETLOOP(k) cwp->ws.lset[k] = p->look->lset[k]; WSBUMP(cwp); } /* * now, go through the loop, closing each item */ work = 1; while (work) { work = 0; WSLOOP(wsets,u) { if (u->flag == 0) continue; c = *(u->pitem); /* dot is before c */ if (c < NTBASE) { u ->flag = 0; /* * only interesting case is where . is * before nonterminal */ continue; } /* * compute the lookahead */ aryfil(clset.lset, tbitset, 0); /* * find items involving c */ WSLOOP(u,v) { if (v->flag == 1 && *(pi=v->pitem) == c) { v->flag = 0; if (nolook) continue; while ((ch= *++pi)>0) { /* * terminal symbol */ if (ch < NTBASE) { SETBIT(clset.lset, ch); break; } looksets *p; { register struct looksets *q; int j, *w; register *u, *v; for (q = &lkst[nlset]; q-- > lkst;) { u = p->lset; v = q->lset; w = & v[tbitset]; while (v= LSETSIZE) error("too many lookahead sets"); SETLOOP(j) { q->lset[j] = p->lset[j]; } return (q); } NE; aryfil(temp1, nnonter+1, 0); /* * take state i, close it /* * nonterminal symbol */ setunion(clset.lset, pfirst[ch-NTBASE]->lset); if (!pempty[ch-NTBASE]) break; } if (ch<=0) setunion(clset.lset,v->ws.lset); } } /* * now loop over productions derived from c */ c -= NTBASE; /* c is now nonterminal number */ t = pres[c+1]; for (s=pres[c]; spitem == *s) { if (nolook) goto nexts; if (setunion(v->ws.lset, clset.lset)) v->flag = work = 1; goto nexts; } } /* * not there; make a new entry */ if (cwp-wsets+1 >= WSETSIZE) error("working set overflow"); cwp->pitem = *s; cwp->flag = 1; if (!nolook) { work = 1; SETLOOP(k)cwp->ws.lset[k]=clset.lset[k]; } WSBUMP(cwp); nexts: ; } } } /* * have computed/* static char sccsid[] = "@(#)y2.c 4.1 (Berkeley) 2/11/83"; */ /* * Y2.C - yacc * * $Header: y2.c,v 1.6 84/06/22 11:06:26 jimd Exp $ * $Locker: $ * * Modification from Berkeley 4.2 * Copyright (c) Tektronix Inc. * All Rights Reserved. * */ /* * Author: Not Listed. * * Engineer: Jim Dailey - ECS * * Origin: Berkeley 4.2 * * Calling Structure: * * Changes made to version 1.1: * * 1. Standard Changes * * o Added the above and following header information. * o Added errdefs include a closure; flags are reset; return */ if (cwp > zzcwp) zzcwp = cwp; if (cldebug && (foutput!=NULL)) { fprintf(foutput, "\nState %d, nolook = %d\n", i, nolook); WSLOOP(wsets,u) { if (u->flag) fprintf(foutput, "flag set!\n"); u->flag = 0; fprintf(foutput, "\t%s", writem(u->pitem)); prlook(&u->ws); fprintf(foutput, "\n"); } } } /* * decide if the lookahead set pointed to by p is known * return pointer to a perminent location for the set */ struct looksets *flset(p) struct nd register variables. * * Log of Revisions: * * $Log: y2.c,v $ * Revision 1.6 84/06/22 11:06:26 jimd * fixed error messages so that system type messages would use ERROR. * * Revision 1.5 84/04/10 15:02:55 jimd * removed yacc1 tag. * * Revision 1.4 84/02/29 13:38:14 jimd * fixed ERROR tag fields. * * Revision 1.3 84/01/25 13:10:50 jimd * Changed format of ERROR calls * * Revision 1.2 83/12/23 13:36:29 jimd * see * header * , * * */ #include "dextern" #define IDEN TIFIER 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 */ char *infile; /* input file name */ int numbval; /* value of an input number */ char tokname[NAMESIZE]; /* input token name */ /* *: case 'V': foutput = fopen(FILEU, "w"); if (foutput == NULL) ERROR(P_ERR,"",O_ERR,"Cannot open file y.output"); continue; case 'D': case 'd': fdefine = fopen(FILED, "w"); if (fdefine==NULL) ERROR(NP_WARN,"",O_ERR,"Cannot open file y.tab.h"); continue; case 'o': case 'O': ERROR(NP_WARN, "",O_ERR,"`o' flag now default in yacc"); continue; case 'r': case 'R': ERROR(NP_ERR,"",O_ERR,"Ratfor Yacc is dead: sorry..."); default: ERROR(NP_ storage of names */ char cnames[CNAMSZ]; /* place where token and nonterminal names are stored */ 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 tokseERR,"",O_ERR,"illegal option: %c", *argv[1]); } } argv++; argc--; } ftable = fopen(OFILE, "w"); if (ftable == NULL) ERROR(P_ERR,"",O_ERR,"Cannot open file y.tab.c"); ftemp = fopen(TEMPNAME, "w"); faction = fopen(ACTNAME, "w"); if (ftemp==NULL) ERROR(P_ERR,"",O_ERR,"Cannot open file yacc.tmp"); if (faction==NULL) ERROR(P_ERR,"",O_ERR,"Cannot open file yacc.acts"); if (argc < 2 || ((finput=fopen(infile=argv[1], "r")) == NULL)) { ERROR(P_ERR,"",O_ERR,"Cannot open input file"); }t[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 mem cnamp = cnames; defin(0,"$end"); extval = 0400; defin(0,"error"); defin(1,"$accept"); mem=mem0; lev = 0; ty = 0; i=0; /* * sorry -- no yacc parser here..... * we must bootstrap somehow... */ for (t=gettok(); t!=MARK && t!= ENDFILE;) { switch (t) { case ';': t = gettok(); break; case START: if ((t=gettok()) != IDENTIFIER) { error("bad %%start construction"); } start = chfind(1,tokname); t = gettok(); continue; case TYPEDEF: if ((t=gettok()) != TYP0[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 */ setup(argc,argv) register int argc; char *argv[]; { int i,j,lev,t, ty; int c; int *p; char actname[8]; foutput = NULL; fdefine = NULL; i = 1; while (argc >= 2 && argv[1][0] == '-') { while (*++(argv[1])) { switch (*argv[1]) { case 'v'ENAME) error("bad syntax in %%type"); ty = numbval; for (;;) { t = gettok(); switch (t) { case IDENTIFIER: if ((t=chfind(1, tokname)) < NTBASE) { j = TYPE(toklev[t]); if (j!= 0 && j != ty) { error("type redeclaration of token %s", tokset[t].name ); } else SETTYPE( toklev[t],ty); } else { j = nontrst[t-NTBASE].tvalue; if (j != 0 && j != ty) { error("type redeclaration of nonterminal %s", nontrst[t-NTBASE].name ); } else  nontrst[t-NTBASE].tvalue = ty; } case ',': continue; case ';': t = gettok(); break; default: break; } break; } continue; case UNION: /* * copy the union declaration to the output */ cpyunion(); t = gettok(); continue; case LEFT: case BINARY: case RIGHT: ++i; case TERM: /* * nonzero means new prec. and assoc. */ lev = t-TERM; ty = 0; /* * get identifiers so defined */ t = gel overwrite with * the lhs of the first rule */ *mem++ = start; *mem++ = 1; *mem++ = 0; prdptr[1]=mem; while ((t=gettok()) == LCURLY) cpycode(); if (t != C_IDENTIFIER) error("bad syntax on first rule"); if (!start) prdptr[0][1] = chfind(1,tokname); /* * read rules */ while (t!=MARK && t!=ENDFILE) { /* * process a rule */ if (t == '|') { *mem++ = *prdptr[nprod-1]; } else if (t == C_IDENTIFIER) { *mem = chfind(1,tokname); if (*mem < NTBASE) error("tottok(); if (t == TYPENAME) { /* there is a type defined */ ty = numbval; t = gettok(); } for (;;) { switch (t) { case ',': t = gettok(); continue; case ';': break; case IDENTIFIER: j = chfind(0,tokname); if (lev) { if (ASSOC(toklev[j])) error("redeclaration of precedence of %s", tokname); SETASC(toklev[j],lev); SETPLEV(toklev[j],i); } if (ty) { if (TYPE(toklev[j])) error("redeclaration of type of %sken illegal on LHS of grammar rule"); ++mem; } else error("illegal rule: missing semicolon or | ?"); /* * read rule body */ t = gettok(); more_rule: while (t == IDENTIFIER) { *mem = chfind(1,tokname); if (*mem=NTBASE) error("nonterminal %s illegal after %%prec", nontrst[j-NTBASE].name", tokname ); SETTYPE(toklev[j],ty); } if ((t=gettok()) == NUMBER) { tokset[j].value = numbval; if (j < ndefout && j>2) { error("please define type number of %s earlier", tokset[j].name ); } t=gettok(); } continue; } break; } continue; case LCURLY: defout(); cpycode(); t = gettok(); continue; default: error("syntax error"); } } if (t == ENDFILE) { error("unexpected EOF before %%"); } /* * t is MARK ); levprd[nprod]=toklev[j]; t = gettok(); } if (t == '=') { levprd[nprod] |= ACTFLAG; fprintf( faction, "\ncase %d:", nprod ); cpyact( mem-prdptr[nprod]-1 ); fprintf( faction, " break;" ); if ((t=gettok()) == IDENTIFIER) { /* * action within rule... */ sprintf( actname, "$$%d", nprod ); j = chfind(1,actname); /* * the current rule will become rule * number nprod+1 * * move the contents down, and make * room for the null */ defout(); fprintf( ftable, "#define yyclearin yychar = -1\n" ); fprintf( ftable, "#define yyerrok yyerrflag = 0\n" ); fprintf( ftable, "extern int yychar;\nextern short yyerrflag;\n" ); fprintf( ftable, "#ifndef YYMAXDEPTH\n#define YYMAXDEPTH 150\n#endif\n" ); if( !ntypes ) fprintf( ftable, "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n" ); fprintf( ftable, "YYSTYPE yylval, yyval;\n" ); prdptr[0]=mem; /* * added production */ *mem++ = NTBASE; /* * if start is 0, we wil*/ for (p=mem; p>=prdptr[nprod]; --p) p[2] = *p; mem += 2; /* * enter null production for action */ p = prdptr[nprod]; *p++ = j; *p++ = -nprod; /* * update the production information */ levprd[nprod+1] = levprd[nprod] & ~ACTFLAG; levprd[nprod] = ACTFLAG; if (++nprod >= NPROD) error("more than %d rules", NPROD); prdptr[nprod] = p; /* * make the action appear in the original rule */ *mem++ = j; /* *  get some more of the rule */ goto more_rule; } } while (t == ';') t = gettok(); *mem++ = -nprod; /* * check that default action is reasonable */ if (ntypes && !(levprd[nprod]&ACTFLAG) && nontrst[*prdptr[nprod]-NTBASE].tvalue) { /* * no explicit action, LHS has value */ register tempty; tempty = prdptr[nprod][1]; if (tempty < 0) error("must return a value, since LHS has a type" ); else if (tempty >= NTBASE) tempty = nontrst[tempty-NTBASE].tv '\f'; break; case '\'': val = '\''; break; case '"': val = '"'; break; case '\\': val = '\\'; break; default: error("invalid escape"); } } else if (s[2] <= '7' && s[2]>='0') { /* \nnn sequence */ if (s[3]<'0' || s[3] > '7' || s[4]<'0' || s[4]>'7' || s[5] != '\0') error("illegal \\nnn construction"); val = 64*s[2] + 8*s[3] + s[4] - 73*'0'; if (val == 0) error("'\\000' is illegal"); } } else { val = extval++; } tokset[nalue; else tempty = TYPE( toklev[tempty] ); if (tempty != nontrst[*prdptr[nprod]-NTBASE].tvalue) { error("default action causes potential type clash" ); } } if (++nprod >= NPROD) error("more than %d rules", NPROD); prdptr[nprod] = mem; levprd[nprod]=0; } /* * end of all rules */ finact(); if (t == MARK) { fprintf(ftable, "\n# line %d \"%s\"\n", lineno, infile); while ((c=getc(finput)) != EOF) putc(c, ftable); } fclose(finput); } /* * finish action routine */tokens].value = val; toklev[ntokens] = 0; return( ntokens ); } /* * write out the defines (at the end of the declaration section) */ defout() { register int i, c; register char *cp; for (i=ndefout; i<=ntokens; ++i) { cp = tokset[i].name; if (*cp == ' ') ++cp; /* literals */ for (;(c= *cp)!='\0'; ++cp) { if (islower(c) || isupper(c) || isdigit(c) || c=='_' ); /* VOID */ else goto nodef; } fprintf(ftable,"#define %s %d\n",tokset[i].name,tokset[i].value); if (fdefine != finact() { fclose(faction); fprintf( ftable, "# define YYERRCODE %d\n", tokset[2].value ); } /* * define s to be a terminal if t=0 or a nonterminal if t=1 */ defin(t, s) register char *s; { register val; if (t) { if (++nnonter >= NNONTERM) error("too many nonterminals, limit %d",NNONTERM); nontrst[nnonter].name = cstash(s); return( NTBASE + nnonter ); } /* * must be a token */ if (++ntokens >= NTERMS) error("too many terminals, limit %d",NTERMS); tokset[ntokens].name = csta NULL) fprintf(fdefine,"#define %s %d\n",tokset[i].name,tokset[i].value); nodef: ; } ndefout = ntokens+1; } char * cstash(s) register char *s; { char *temp; temp = cnamp; do { if (cnamp >= &cnames[cnamsz]) error("too many characters in id's and literals"); else *cnamp++ = *s; } while (*s++); return (temp); } gettok() { register i, base; static int peekline; /* number of '\n' seen in lookahead */ register c, match, reserve; begin: reserve = 0; lineno += peekline; peekline = sh(s); /* * establish value for token */ if (s[0]==' ' && s[2]=='\0') /* single character literal */ val = s[1]; else if (s[0]==' ' && s[1]=='\\') { /* escape sequence */ if (s[3] == '\0') { /* single character escape sequence */ switch (s[2]) { /* * character which is escaped */ case 'n': val = '\n'; break; case 'r': val = '\r'; break; case 'b': val = '\b'; break; case 't': val = '\t'; break; case 'f': val =0; c = getc(finput); while (c==' ' || c=='\n' || c=='\t' || c=='\f') { if (c == '\n') ++lineno; c=getc(finput); } if (c == '/') { /* skip comment */ lineno += skipcom(); goto begin; } switch (c) { case EOF: return(ENDFILE); case '{': ungetc( c, finput ); return( '=' ); /* action ... */ case '<': /* get, and look up, a type name (union member name) */ i = 0; while( (c=getc(finput)) != '>' && c>=0 && c!= '\n' ){ tokname[i] = c; if( ++i >= NAMESIZE ) --i; } if(  c != '>' ) error( "unterminated < ... > clause" ); tokname[i] = '\0'; for( i=1; i<=ntypes; ++i ){ if( !strcmp( typeset[i], tokname ) ){ numbval = i; return( TYPENAME ); } } typeset[numbval = ++ntypes] = cstash( tokname ); return( TYPENAME ); case '"': case '\'': match = c; tokname[0] = ' '; i = 1; for (;;) { c = getc(finput); if( c == '\n' || c == EOF ) error("illegal or missing ' or \"" ); if( c == '\\' ){ c = getc(finput); tokname[i] = '\\'; if(on")) return( UNION ); error("invalid escape, or illegal reserved word: %s", tokname ); } /* * look ahead to distinguish IDENTIFIER from C_IDENTIFIER */ c = getc(finput); while (c==' ' || c=='\t'|| c=='\n' || c=='\f' || c== '/') { if (c == '\n') ++peekline; else if (c == '/') { /* look for comments */ peekline += skipcom(); } c = getc(finput); } if (c == ':') return( C_IDENTIFIER ); ungetc( c, finput ); return( IDENTIFIER ); } /* * determine the type of a symbol */ fdt ++i >= NAMESIZE ) --i; } else if( c == match ) break; tokname[i] = c; if( ++i >= NAMESIZE ) --i; } break; case '%': case '\\': switch (c=getc(finput)) { case '0': return(TERM); case '<': return(LEFT); case '2': return(BINARY); case '>': return(RIGHT); case '%': case '\\': return(MARK); case '=': return(PREC); case '{': return(LCURLY); default: reserve = 1; } default: if (isdigit(c)) { /* number */ numbval = c-'0' ; base = (c=='0') ? 8 : 10 ; ype( t ) { register v; if (t >= NTBASE) v = nontrst[t-NTBASE].tvalue; else v = TYPE( toklev[t] ); if (v <= 0) error("must specify type for %s",(t>=NTBASE)?nontrst[t-NTBASE].name: tokset[t].name); return( v ); } chfind( t, s ) register char *s; { int i; if (s[0]==' ') t=0; TLOOP(i) { if (!strcmp(s,tokset[i].name)) { return( i ); } } NTLOOP(i) { if (!strcmp(s,nontrst[i].name)) { return( i+NTBASE ); } } /* * cannot find name */ if (t>1) error("%s should have been for( c=getc(finput); isdigit(c) ; c=getc(finput) ){ numbval = numbval*base + c - '0'; } ungetc( c, finput ); return(NUMBER); } else if( islower(c) || isupper(c) || c=='_' || c=='.' || c=='$' ){ i = 0; while( islower(c) || isupper(c) || isdigit(c) || c=='_' || c=='.' || c=='$' ){ tokname[i] = c; if( reserve && isupper(c) ) tokname[i] += 'a'-'A'; if( ++i >= NAMESIZE ) --i; c = getc(finput); } } else return(c); ungetc( c, finput ); } tokname[i] = '\0'; i defined earlier", s); return(defin(t, s)); } /* * copy the union declaration to the output, * and the define file if present */ cpyunion() { int level, c; fprintf( ftable, "\n# line %d \"%s\"\n", lineno, infile ); fprintf( ftable, "typedef union " ); if (fdefine) fprintf( fdefine, "\ntypedef union " ); level = 0; for (;;) { if ((c=getc(finput)) < 0 ) error( "EOF encountered while processing %%union"); putc(c, ftable); if (fdefine) putc( c, fdefine ); switch (c) { case '\f (reserve) { /* find a reserved word */ if( !strcmp(tokname,"term")) return( TERM ); if( !strcmp(tokname,"token")) return( TERM ); if( !strcmp(tokname,"left")) return( LEFT ); if( !strcmp(tokname,"nonassoc")) return( BINARY ); if( !strcmp(tokname,"binary")) return( BINARY ); if( !strcmp(tokname,"right")) return( RIGHT ); if( !strcmp(tokname,"prec")) return( PREC ); if( !strcmp(tokname,"start")) return( START ); if( !strcmp(tokname,"type")) return( TYPEDEF ); if( !strcmp(tokname,"unin': ++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; } } } } /* * copies code between \{ and \} */ cpycode() { int c; c = getc(finput); if (c == '\n') { c = getc(finput); lineno++; } fprintf( ftable, "\n# line %d \"%s\"\n", lineno, infile ); while (c>=0) { if (c=='\\')  if ((c=getc(finput)) == '}') return; else putc('\\', ftable ); if (c=='%') if ((c=getc(finput)) == '}') return; else putc('%', ftable ); putc(c , ftable); if (c == '\n') ++lineno; c = getc(finput); } error("eof before %%}" ); } /* * skip over comments */ skipcom() { register c, i=0; /* i is the number of lines skipped */ /* * skipcom is called after reading a / */ if (getc(finput) != '*') error("illegal comment"); c = getc(finput); while (c != EOF) { faction ); if (s<0) putc('-', faction ); goto swt; case '}': if (--brac) goto lcopy; putc( c, faction ); return; case '/': /* look for comments */ putc( c , faction ); c = getc(finput); if (c != '*') goto swt; /* * it really is a comment */ putc( c , faction ); c = getc(finput); while (c != EOF) { while (c=='*') { putc( c , faction ); if ((c=getc(finput)) == '/') goto lcopy; } putc( c , faction ); if (c == '\n') ++lineno; c = get while (c == '*') { if ((c=getc(finput)) == '/') return( i ); } if (c == '\n') ++i; c = getc(finput); } error( "EOF inside comment" ); /* NOTREACHED */ } /* * copy C action to the next ; or closing } */ cpyact(offset) { int brac, c, match, j, s, tok; fprintf( faction, "\n# line %d \"%s\"\n", lineno, infile ); brac = 0; loop: c = getc(finput); swt: switch (c) { case ';': if (brac == 0) { putc( c , faction ); return; } goto lcopy; case '{': brac++; goto lcoc(finput); } error( "EOF inside comment" ); case '\'': /* character constant */ match = '\''; goto string; case '"': /* character string */ match = '"'; string: putc( c , faction ); while (c=getc(finput)) { if (c=='\\') { putc( c , faction ); c=getc(finput); if (c == '\n') ++lineno; } else if (c==match) goto lcopy; else if (c=='\n') error("newline in string or char. const."); putc( c , faction ); } error( "EOF in string or character constapy; case '$': s = 1; tok = -1; c = getc(finput); if (c == '<') { /* type description */ ungetc( c, finput ); if (gettok() != TYPENAME) error( "bad syntax on $ clause" ); tok = numbval; c = getc(finput); } if (c == '$') { fprintf( faction, "yyval"); if (ntypes) { /* put out the proper tag... */ if (tok < 0) tok = fdtype( *prdptr[nprod] ); fprintf( faction, ".%s", typeset[tok] ); } goto loop; } if (c == '-') { s = -s; c = getc(finpunt" ); case EOF: error("action does not terminate" ); case '\n': ++lineno; goto lcopy; } lcopy: putc( c , faction ); goto loop; } () { int level, c; fprintf( ftable, "\n# line %d \"%s\"\n", lineno, infile ); fprintf( ftable, "typedef union " ); if (fdefine) fprintf( fdefine, "\ntypedef union " ); level = 0; for (;;) { if ((c=getc(finput)) < 0 ) error( "EOF encountered while processing %%union"); putc(c, ftable); if (fdefine) putc( c, fdefine ); switch (c) { case '\t); } if (isdigit(c)) { j=0; while (isdigit(c)) { j= j*10+c-'0'; c = getc(finput); } j = j*s - offset; if (j > 0) { error( "Illegal use of $%d", j+offset ); } fprintf( faction, "yypvt[-%d]", -j ); if (ntypes) { /* put out the proper tag */ if (j+offset <= 0 && tok < 0) error("must specify type of $%d",j+offset); if (tok < 0) tok = fdtype( prdptr[nprod][j+offset] ); fprintf( faction, ".%s", typeset[tok] ); } goto swt; } putc( '$' , & &  y3.c. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czc" /* static char sccsid[] = "@(#)y3.c 4.1 (Berkeley) 2/11/83"; */ /* * Y3.C - yacc * * $Header: y3.c,v 1.2 83/12/23 13:37:39 jimd Exp $ * $Locker: $ * * Modification from Berkeley 4.2 * Copyright (c) Tektronix Inc. * All Rights Reserved. * */ /* * Author: Not Listed. * * Engineer: Jim Dailey - ECS * * Origin: Berkeley 4.2 * * Calling Structure: * * Changes made to version 1.1: * * 1. Standard Changes * * o Added the above and following header information. * * Log of Revisions: * ] = -lastred; ++zzrrconf; } else { /* potential shift/reduce conflict */ precftn( lastred, k, i ); } } } } } wract(i); } fprintf( ftable, "\t};\n" ); wdef( "YYNPROD", nprod ); } int pkdebug = 0; /* * pack state i from temp1 into amem */ apack(p, n) int *p; { 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 tr* $Log: y3.c,v $ * Revision 1.2 83/12/23 13:37:39 jimd * see * header * , * * */ #include "dextern" /* * important local variables */ int lastred; /* the number of the last reduction of a state*/ int defact[NSTATES]; /* the default actions of states */ /* * print the output for the states */ output() { int i, k, c; register struct wset *u, *v; fprintf( ftable, "short yyexca[] ={\n" ); SLOOP(i) { /* output the stuff for state i */ nolook = !(tystate[i]==MUSTLOOKAHEAD); ailing 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 */ if( pkdebug && foutput!=NULL ) fprintf( foutput, "off = %d, k = %d\n", offclosure(i); /* * output actions */ nolook = 1; aryfil( temp1, ntokens+nnonter+1, 0 ); WSLOOP(wsets,u) { c = *( u->pitem ); if (c>1 && cpitem)) putitem(v->pitem+1,(struct looksets *)0); } temp1[c] = state(c); } else if (c>NTBASE && temp1[(c -= NTBASE)+ntokens]==0) { temp1[ c+ntokens ] = amem[indgo[i]+c]; } } if (i == 1) temp1[1] = ACCEPTCODE; /* * now, we have the shifts; look at the , rr-amem ); 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; } } if( pkdebug && 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"); } } return( off ); nextk: ; } error("no space in action table" ); /* NOTREACHED */ } go2out(){ /* output the gotos for the nonreductions */ lastred = 0; WSLOOP(wsets,u) { c = *( u->pitem ); if (c<=0) { /* reduction */ lastred = -c; TLOOP(k) { if (BIT(u->ws.lset,k)) { if (temp1[k] == 0) temp1[k] = c; /* * reduce/reduce conflict */ else if (temp1[k]<0) { if (foutput!=NULL) fprintf( foutput, "\n%d: reduce/reduce conflict (red'ns %d and %d ) on %s", i, -temp1[k], lastred, symnam(k) ); if (-temp1[k] > lastred) temp1[ktermninals */ int i, j, k, best, count, cbest, times; fprintf( ftemp, "$\n" ); /* mark begining of gotos */ for( i=1; i<=nnonter; ++i ) { go2gen(i); /* find the best one to make default */ best = -1; times = 0; for( j=0; j<=nstate; ++j ){ /* is j the most frequent */ if( tystate[j] == 0 ) continue; if( tystate[j] == best ) continue; /* is tystate[j] the most frequent */ count = 0; cbest = tystate[j]; for( k=j; k<=nstate; ++k ) if( tystate[k]==cbest ) ++count; if( count > times ){ best = cbest; times = count; } } /* best is now the default entry */ zzgobest += (times-1); for( j=0; j<=nstate; ++j ){ if( tystate[j] != 0 && tystate[j]!=best ){ fprintf( ftemp, "%d,%d,", j, tystate[j] ); zzgoent += 1; } } /* now, the default */ zzgoent += 1; fprintf( ftemp, "%d\n", best ); } } int g2debug = 0; go2gen(c){ /* output the gotos for nonterminal c */ int i, work, cc; struct item *p, *q; /* first, find nonterminals wift */ else action = LASC; /* reduce */ switch( action ){ case BASC: /* error action */ temp1[t] = ERRCODE; return; case LASC: /* reduce */ temp1[t] = -r; return; } } wract(i){ /* output state i */ /* temp1 has the actions, lastred the default */ int p, p0, p1; int ntimes, tred, count, j; int flag; /* find the best choice for lastred */ lastred = 0; ntimes = 0; TLOOP(j){ if( temp1[j] >= 0 ) continue; if( temp1[j]+lastred == 0 ) continue; /* count the number of appearanith gotos on c */ aryfil( temp1, nnonter+1, 0 ); temp1[c] = 1; work = 1; while( work ){ work = 0; PLOOP(0,i){ if( (cc=prdptr[i][1]-NTBASE) >= 0 ){ /* cc is a nonterminal */ if( temp1[cc] != 0 ){ /* cc has a goto on c */ cc = *prdptr[i]-NTBASE; /* thus, the left side of production i does too */ if( temp1[cc] == 0 ){ work = 1; temp1[cc] = 1; } } } } } /* now, we have temp1[c] = 1 if a goto on c in closure of cc */ if( g2debug && foutput!=NULces of temp1[j] */ count = 0; tred = -temp1[j]; levprd[tred] |= REDFLAG; TLOOP(p){ if( temp1[p]+tred == 0 ) ++count; } if( count >ntimes ){ lastred = tred; ntimes = count; } } /* for error recovery, arrange that, if there is a shift on the /* error recovery token, `error', that the default be the error action */ if( temp1[1] > 0 ) lastred = 0; /* clear out entries in temp1 which equal lastred */ TLOOP(p) if( temp1[p]+lastred == 0 )temp1[p]=0; wrstate(i); defact[i] = lastL ){ fprintf( foutput, "%s: gotos on ", nontrst[c].name ); NTLOOP(i) if( temp1[i] ) fprintf( foutput, "%s ", nontrst[i].name); fprintf( foutput, "\n"); } /* now, go through and put gotos into tystate */ aryfil( tystate, nstate, 0 ); SLOOP(i){ ITMLOOP(i,p,q){ if( (cc= *p->pitem) >= NTBASE ){ if( temp1[cc -= NTBASE] ){ /* goto on c is possible */ tystate[i] = amem[indgo[i]+c]; break; } } } } } precftn(r,t,s){ /* decide a shift/reduce conflict by precedence. /* red; flag = 0; TLOOP(p0){ if( (p1=temp1[p0])!=0 ) { if( p1 < 0 ){ p1 = -p1; goto exc; } else if( p1 == ACCEPTCODE ) { p1 = -1; goto exc; } else if( p1 == ERRCODE ) { p1 = 0; goto exc; exc: if( flag++ == 0 ) fprintf( ftable, "-1, %d,\n", i ); fprintf( ftable, "\t%d, %d,\n", tokset[p0].value, p1 ); ++zzexcp; } else { fprintf( ftemp, "%d,%d,", tokset[p0].value, p1 ); ++zzacent; } } } if( flag ) { defact[i] = -2; fprintf( r is a rule number, t a token number */ /* the conflict is in state s */ /* temp1[t] is changed to reflect the action */ int lp,lt, action; lp = levprd[r]; lt = toklev[t]; if( PLEVEL(lt) == 0 || PLEVEL(lp) == 0 ) { /* conflict */ if( foutput != NULL ) fprintf( foutput, "\n%d: shift/reduce conflict (shift %d, red'n %d) on %s", s, temp1[t], r, symnam(t) ); ++zzsrconf; return; } if( PLEVEL(lt) == PLEVEL(lp) ) action = ASSOC(lt); else if( PLEVEL(lt) > PLEVEL(lp) ) action = RASC; /* shftable, "\t-2, %d,\n", lastred ); } fprintf( ftemp, "\n" ); return; } wrstate(i){ /* writes state i */ register j0,j1; register struct item *pp, *qq; register struct wset *u; if( foutput == NULL ) return; fprintf( foutput, "\nstate %d\n",i); ITMLOOP(i,pp,qq) fprintf( foutput, "\t%s\n", writem(pp->pitem)); if( tystate[i] == MUSTLOOKAHEAD ){ /* print out empty productions in closure */ WSLOOP( wsets+(pstate[i+1]-pstate[i]), u ){ if( *(u->pitem) < 0 ) fprintf( foutput, "\t%s\n", writem(u->pitem) ); } } /* check for state equal to another */ TLOOP(j0) if( (j1=temp1[j0]) != 0 ){ fprintf( foutput, "\n\t%s ", symnam(j0) ); if( j1>0 ){ /* shift, error, or accept */ if( j1 == ACCEPTCODE ) fprintf( foutput, "accept" ); else if( j1 == ERRCODE ) fprintf( foutput, "error" ); else fprintf( foutput, "shift %d", j1 ); } else fprintf( foutput, "reduce %d",-j1 ); } /* output the final production */ if( lastred ) fprintf( foutput, "\n\t. reduce %d\n\n", lastred ); else    y4.c. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czc"fprintf( foutput, "\n\t. error\n\n" ); /* now, output nonterminal actions */ j1 = ntokens; for( j0 = 1; j0 <= nnonter; ++j0 ){ if( temp1[++j1] ) fprintf( foutput, "\t%s goto %d\n", symnam( j0+NTBASE), temp1[j1] ); } } wdef( s, n ) char *s; { /* output a definition of s to the value n */ fprintf( ftable, "# define %s %d\n", s, n ); } warray( s, v, n ) char *s; int *v, n; { register i; fprintf( ftable, "short %s[]={\n", s ); for( i=0; i PLEVEL(lp) ) action = RASC; /* shk, *q; /* read the arrays from tempfile and set parameters */ if( (finput=fopen(TEMPNAME,"r")) == NULL ) error( "optimizer cannot open tempfile" ); pgo[0] = 0; yypact[0] = 0; nstate = 0; nnonter = 0; for(;;){ switch( gtnm() ){ case '\n': yypact[++nstate] = (--pmem) - mem; case ',': continue; case '$': break; default: error( "bad tempfile" ); } break; } yypact[nstate] = yypgo[0] = (--pmem) - mem; for(;;){ switch( gtnm() ){ case '\n': yypgo[++nnonter]= pmem-mem; case ',': continue; case EOF: break; default: error( "bad tempfile" ); } break; } yypgo[nnonter--] = (--pmem) - mem; for( i=0; i j ) j = *p; if( *p < k ) k = *p; } if( k <= j ){ /* nontrivial situation */ /* temporarily, kill this for compatibility j -= k; /* j is now the range */ if( k > maxoff ) maxoff = k; } greed[i] = (yypact[i( r=q1; r1 ) fprintf( ftable, "Nonterminal %d, entry at %d\n" , i, pgo[i] ); goto nextgi; nextgp: ; } error( "cannot place goto %d\n", i ); nextgi: ; } stin(i){ register *r, *s, n, flag, j, *q1, *q2; greed[i] = 0; /* enter state i into the a array */ q2 = mem+yypact[i+1]; q1 = mem+yypact[i]; /* find an acceptable place */ for( n= -maxoff; n maxspr ) maxspr = j; } /* initialize ggreed table */ for( i=1; i<=nnonter; ++i ){ ggreed[i] = 1; j = 0; /* minimum entry index is always 0 */ q = mem + yypgo[i+1] -1; for( p = mem+yypgo[i]; p j ) j = *p; } ggreed[i] = ggreed[i] + 2*j; if( j > maxoff ) maxoff = j; } /* now, prepare to put the shift actions into the a array */ for( i=0; i1 ) fprintf( ftable, "State %d: entry at %d equals state %d\n", i, n, j ); return; if( greed[i]==0 && adb>1 ) fprintf( ftable, "State %d: null\n", i ); pa[i] = YYFLAG1; } while( (i = nxti()) != NOMORE ) { if( i >= 0 ) stin(i); else gin(-i); } if( adb>2 ){ /* print a array */ for( p=a; p <= maxa; p += 10){ fprintf( ftable, "%4d ", p-a ); for( i=0; i<10; ++i ) fprintf( ftable, "%4d ", p[i] ); fprintf( ftable, "\n" ); } } /* write out the output appropriate to the language */ aoutput(); osummary(); ZAPFILE(TEMPNAME); } gin(i){ register *p, *r, *s } goto nextn; /* we have some disagreement */ } } for( r = q1; r < q2; r += 2 ){ if( (s = *r + n + a ) >= &a[ACTSIZE] ) error( "out of space in optimizer a array" ); if( s > maxa ) maxa = s; if( *s != 0 && *s != r[1] ) error( "clobber of a array, pos'n %d, by %d", s-a, r[1] ); *s = r[1]; } pa[i] = n; if( adb>1 ) fprintf( ftable, "State %d: entry at %d\n", i, pa[i] ); return; nextn: ; } error( "Error; failure to place state %d\n", i ); } nxti(){ /* finds t, *q1, *q2; /* enter gotos on nonterminal i into array a */ ggreed[i] = 0; q2 = mem+ yypgo[i+1] - 1; q1 = mem + yypgo[i]; /* now, find a place for it */ for( p=a; p < &a[ACTSIZE]; ++p ){ if( *p ) continue; for( r=q1; r maxa ){ if( (maxa=s) > &a[ACTSIZE] ) error( "a array overflow" ); } } /* we have found a spot */ *p = *q2; if( p > maxa ){ if( (maxa=p) > &a[ACTSIZE] ) error( "a array overflow" ); } forhe next i */ register i, max, maxi; max = 0; for( i=1; i<= nnonter; ++i ) if( ggreed[i] >= max ){ max = ggreed[i]; maxi = -i; } for( i=0; i= max ){ max = greed[i]; maxi = i; } if( nxdb ) fprintf( ftable, "nxti = %d, max = %d\n", maxi, max ); if( max==0 ) return( NOMORE ); else return( maxi ); } osummary(){ /* write summary */ register i, *p; if( foutput == NULL ) return; i=0; for( p=maxa; p>=a; --p ) { if( *p == 0 ) ++i; } fprintf( foutput, "Optimizer space used: input %d/%d, output %d/%d\n", pmem-mem+1, MEMSIZE, maxa-a+1, ACTSIZE ); fprintf( foutput, "%d table entries, %d zero\n", (maxa-a)+1, i ); fprintf( foutput, "maximum spread: %d, maximum offset: %d\n", maxspr, maxoff ); } aoutput(){ /* this version is for C */ /* write out the optimized parser */ fprintf( ftable, "# define YYLAST %d\n", maxa-a+1 ); arout( "yyact", a, (maxa-a)+1 ); arout( "yypact", pa, nstate ); arout( "yypgo", pgo, nnonter+1 ); } arout( s, v, n ) chary0@1g# TЏ#/Ho//N8OBN[pNV. /.NX$9h JlDD`#a6aFa :aN9$N=NGa"NHat.N[pN^NuNVH./<Ne|X#_fJ_ff./<aRX.x/<$^/<&NGNPt./9x/< xaP|`>$R |""|$0(JlDD`U" | x!Rxm.x/< x/<+NGNP./9/< xaP|`>$ |9*0(`($ |J""| x#( *s; int *v, n; { register i; fprintf( ftable, "short %s[]={\n", s ); for( i=0; i &mem[MEMSIZE] ) error( "out of space" ); return( c ); } i); } if( adb>2 ){ /* print a array */ for( p=a; p <= maxa; p += 10){ fprintf( ftable, "%4d ", p-a ); for( i=0; i<10; ++i ) fprintf( ftable, "%4d ", p[i] ); fprintf( ftable, "\n" ); } } /* write out the output appropriate to the language */ aoutput(); osummary(); ZAPFILE(TEMPNAME); } gin(i){ register *p, *r, *sp/.a|X-@X$.fp_`p n-HB n-Po*.af./.a ??  -yacc. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czc"/9_zNcO.X/9/<L/9_zNcO $9ԂDԹ./<k/9_zNcP./9/<~/9_zNcO ./</9_zNcP./</9_zNcPJf Jg./<NcX$9g./</<NcP$9g$9g./<NcX$9g./</<NcP./<NcX._vNdJ_ng ._nNdN^NuNVR./<8NcX. /./<8NcP./</<8NcP$9f`a$t{.N[pN^NuNVt-B` n!(R$. mN^NuNVH0*n(n z~`,$*$gzRm L0N^NuNVH n*H f. /9_zNcX`j.&/9_zNcX~`6$r$µ(g.a./<*/9_zNcPRho../9_zNcXL N^NuNVH *|+z`z$.$ |8!(t#|` $ |"p(f $$0(X*Rxm$ |8(f$ |V.(/<0aXRlo$ |8!(t#$9gaXt{.N[p$9x+촍g.$9x+" JlDD`./<LaXL N^NuNVH8 9lt.$9lR//<%aP~`$ |"p($ |%"0(fd$ |$0(X*B` m$ |%J(gXJlJl($ |"p($ |%r!(`tRxmn~`X//</9_zNcO $9R |d*p(*$9f . an+@$9R |dP!(o#$9 m .aL N^NuNVH nA./<ߐaX(`m4$.R |8-p($.-p(`(|߰`<$ n贐f,$9f.ߐHlaXJg t-B)B`(`m$9`߰r(./NYXR ^m .a y`"n y`t!B$9f8t-Bt-B` |ߐ"y`".#(R$.m(`X$.贮m(`m$.f$9`o #`$9gJ_zg././</9_zNcO *|߰``$-g.3/9_zNcXt+B.a./<>/9_zNcPA.aZ.B/9_zNcX(`mL8N^NuNVH8$9*B`( n(H&M$9ԋ-B`$f m `h$ n$9R*B Xm .Dat-B` n".+(R$.m L8N^NuNVH..t#_z#_nt-B``t n "hHH ` ./<|Ne|X#_zJ_zf".t////<t}/NSO`./<Ne|X#_nJ_nf".t////<tz/NSO`\.t////<tz/NSO`6.t////<t{/NSO n "hHH./<t//N4ah./9_rNcX./9_rNcX./9_rNcX./9_rNcX$9If.P/9_rNcX.|/9_rNcX#t yt #t yt _b#tt #tt #t#t`aa-@ g  g .N4$9_bf.5Tt/aX y!@`n |f$$9xS |"p( yt #t`P  f:.5Tt/alX yt yt l .N4Xt` .N4a-@`P.5Tt/aX yt yt l |R$9x"|$^#(Xta//<t{/NSO`T vg Vg Dg dg ogT OgJ rgf Rg\`z n R hf~X S m n "h -g\./<Ne|X#_rJ_rf"."t////<!t}/NSO.D/<;Ne|X#_v.P/<FNe|X#_jJ_vf".St////<Rt}/NSOJ_jf".nt////<mt}/NSO m(. n #5L/95LNe|X#_ff".t////<t}/NSO#5`.t/a |X#p.t/a bX.t/a RX#-@ g fa g .N4.5Tt/aX-@ m  |V./<N4X$. |R"9x"|$^#(a0-@ =f$9x |$^(.x/<3/9_jNcP$9x |"9t(JlDD`S.af.=/9_jNcXa-@ f.x/<EHnNkPA.t/a X-@-yt` n"n!QY$9x |".䲰(lPt$9x |-p( n -H$9xD n -H$9x |$^$0("9xR!$9xr!(Rx X_~tt-B-B-Ba -@` .`da -@`a -@ g .N4.5Tt/a~X#_ba X-@`ra L-@  g .N4-y5Pa &-@ .`.5Tt/a&X-@ l` |Rt "0?-AJg&g $. |J.(/<N4X`t ".$. |R(`f$. |V-p(Jg0$.g&$. |V.(/<N4X`$. |V!(`*a 0-@`` g ,g ;g````$aa -@`R$.-Bt-Ba -@  f-yxm.X/<JN4X$9x |!( yt #t`v`a-@ ;g$9xD yt #t$9Ig$9x |$^0(f$9x |"p($ |V"0(g$9x |"p(,)Jl.]N4`8 m$ |V,0(`$ |Rr $0(?,$9x |"p($ |V(g .N4Rx Xxm.X/<N4X$9x |!t($9x |$^r!( gJfap fP.5L/9/</9_rNcO `._r/.N\X._fN]-@ 5Pa -@ .`0a -@`D`>.5Tt/aX-@$.gR |R$0g.5T/<(N4X$. |R".($.". |R$.gH$. |Rr $0(?g.5T/<JN4Xt ".$. |R(a -@  fP$. |J!5P($.dl( o$. |J.(/<fN4Xa -@` ,g ;g g```|a aHa N-@`h.N4`Z ;g  g  g g g g g g g` gJf,Jf .f._fNdLN^NuNV._jNd.J"/</9_rNcPN^NuNVH *n $.gXRl ,lm.,/<N4X$9l |VA(.HUaX W $9l `Rh hm./< N4X$9h |JA(.HUavX W  fJ-f-HH.`(  f -\fJ-f-HH `.~ `l~ `h~`d~ ``~ `\~'`X~"`T~\`P.*N4`B ng rg bg tg fg 'g "g \g``~ -7nt -0mj -0m -7n -0m -7nJ-g .9N4-HH-HHԁ-HH҂ .Jf .SN4`$9pRp.$9h |J!($9h |Rr!( 9hL N^NuNVH .9d`$ |J*p(  fR`> |Z0hHHf$0hHHf0hHHf _fp``lRHH,f$ |J.($/0(/<e/9_rNcO J_ng,$ |J.($/0(/<t/9_nNcO Rho6$9hR#dL N^NuNVH *n-y`$<5Թ\`n.N4` y`#`f .L N^NuNVHv$9-չt#-._fN]* g -._fN]*` :f < `._f/NkX <LN^NuNVH m$. |V.0(`$. |Rr $0(?.JnB m$. |V p(`$. |J p(./<KN4X LN^NuNVH *n  ft-Bt-B`& |J.(HUN\XJf .`xR$.hot-B`, |V.(HUN\XJf$. `6R$.lo o./<dN4X./.aXL N^NuNV.5L/9/</9_rNcO ./9_rNcXJ_ng./9_nNcXt-B.g g f fR._fN]*` /f a ѹ` `p`._f/NkXp=`~` |5TxR 2mS._fN]* >g Jm f >g .N4 |5TB0x~`2.5T$ |I/0(N\XJf#5P < `HRIoRI#I5P$95P |IA(./<5TaBX W < `(t 5T~._fN]* g f .N4 \f(._fN]* |5Tt\xR 2mS`g |5TxR 2mS``t._fN]* `J <`^ <`T <`J <`@ <_fN]-@l .N4._r/.N\XJ_ng._n/.N\X .`LR`\R`VSJf2./9_rNcXJ_ng./9_nNcX`` g {g }g`JN^NuNV._fN]-@ f._fN]-@R.5L/9/</9_rNcO ` \f0._fN]-@ }f`._rt\/N\X %f.._fN]-@ }f`X._rt%/N\X._r/.N\X fR._fN]-@JlV.N4N^NuNVH|._fN] *g ..N4.`6 <`, <`"v`B 0g g %g \g =g {g` |Z0XHHg$0#5P 0fp`p ,._fN]*`,./95PNY0XЅ0#5P._fN]* |Z0XHHf._f/NkX < `> |Z0XHHf(0XHHf _g .g $f~ |Z0XHHf40XHHf&0XHHf _g .g $fL |5Tx$g |Z0XHHg |5T0 xR 2mS._fN]*`n` `d._f/NkX`J gX {gT _fN].`<`._fN]. /f `4 *g fR._fN]. f.>N4LN^NuNV.5L/9/<Q/9_jNcO t-B._fN]-@ .`LJf._j/.N\X``R`zt-Bt-B._fN]-@ $. | x"R"| x"1Ұ($.R  1а(f>$. |-!( Nu*jD.gR$.Ԕ-Blt-B.f `.t /N\XR$.SJfJgL$.g.t-/N\XR`2.g.t+/N\XR`.g.t /N\XR.g.HH ``.t0/N\XR`d.t0/N\XR.tx/N\XR`>.t0/N\XR.tX/N\XR` og xg XgJo`.t0/N\XR$SJfJo`./N\XRHH(f.g `.t /N\XR$.SJf`.g-SX.g-SX(X o $.S `p,Jo".f`.t /N\XR$SJf./N\XR.g`.DJjDDop`ⶁf(BDHD$4HB4HB`(&( dt4"HAHA؁lSJjD ` `H|"/g /`H|"/g~ /g6Höfi H@HL>NuJjDD*jDo$`Bf(BDHD$4BBHB`*&( dt4"HAHAԁ$lԄJjD ` `0 HHHHHHHHHH BBBBBB DDDDDD NVNO NO !NO,` /NO+eNuKJ g HUNdXKf /NOeVNu/// / ?< ONO\ _e:BNuNO,t /N\XR$SJf`.g-SX.g-SX*SX.Nm&Jl `o .` ,o ` .*&o".f`.t /N\XR$SJf g `.HH/N\XR$SJfJo`.t /N\XR$SJf`4.g-SX.g-SX.t%/N\XR``.g-SX.g-SX-KA.Hn/.NqPހ&n`*n$.Д,`.HH/N\XR$SJf`` dgZ ugd ogj xg| Xg| cg sgZ %g g4 eg. Eg$ fg gge0BNuNVH@NOe"/gÈY LN^Nu#p`#pNu/// // ?< ONOO _eBNu///////?< ONOO _e\BNu///////?< ONOO _e8BNu///?< ONO\ _eBNu///?< ONO\ _eBNu#pNuNV/ L$HfJfp` !HH$_N^NuNVH . *n $- ft#p`-g0-g $- fp`pft#p`x-fJg+|*SmR UG(HH `.HH/NnX, f-g.Nd f| L N^NuNVH *n$- Gg`>(nHH(f n(gp` L8N^NuNVA ./.aFXN^NuNVH *n|-g-fJg l-g-g,.Ny.HH `t0`,t0tx`"t0tX` og xg XgJo`t0$SJfJo`HH*f.g`t $.SJf`.g-RX.g-RX*X o $.S `p.Jo.f`t $SJf.g`P f~ gTJo -`pD../-/-Nl@Pg~`"+|*R Un . .`"+|*R Un . . L N^NuNVH0*n-g $- 0gt#p` -f:Jf4.NxJg.Ns+@f`-g.(|`,g,g.Ndm-g@t.Hn/-NqP. f. `^Jfp`p p`L`J*.//-NqP+@SmR U( ` fp`p pL0N^Nu/ /////?< ONOO _eNu#t $SJf`.g-RX.g-RX(RX.Nm(Jl `o .` .o ` .,(o.f`t $SJf g `$SJfJo`t $SJf`.g-RX.g-RXt%``.g-RX.g-RX-JA.HnHUNqP*@$n`(n$.Д.`$SJf`` dg ug og xg Xg cgR sg %g4 gJ egD Eg: fg0 gg& Gg`R&nHH*fB$  L`*4H.HSHUNxPJf 3=pf 4HԋR `&\ fpL8N^Nu/ /////?< ONOO _eNu#pNu /NOehBNu/// // ?< ONOO _eFNu/////////?<= ONOO _e Nu/// // ?< ONOO _eNu#pNu/// // ?< ONOO _eBNu /NOeHNu/ o /NO _eNu/ /// ?< ONO\ _eBNu/// / ?</ ONO\ _evBNu/ /////?< ONOO _ePNu/// // ?< ONOO _e0BNuNV .NO7NVH0$.PSR.(y f(|9##9t#9*Tb4f(`$-ԍ*B+G# g$ P B` M `f.a*@ fp`(M*U`L0N^NuNVH0..t.NX,g D,$9*cSԇ./NuRX./NuX܀$.NX*@fp`"(M)F g$ P B` L.NvP 9L0N^NuHpLt4f4fLNu$&HCHA@HCBCԃ LNuHx"/gt$/`Hx"/gd$/cp`p0f$i 0JLNu(BDHD 0H@0H@`&( dp0"HAHA؁lSJ`d #p`pN^Nu /NO0eBNu#pNuNV nJf SN^NuNVH *n -ft#p`(-g~~-g4-f,.Ny+|*R Un .NxJgp@`p . .`~-g-g,.Ny clauseillegal or missing ' or "termtokenleftnonassocbinaryrightprecstarttypeunioninvalid escape, or illegal reserved word: %smust specify type for %s%s should have been defined earlier # line %d "%s" typedef union typedef union EOF encountered while processing %%union YYSTYPE; YYSTYPE; extern YYSTYPE yylval; # line %d "%s" eof before %%}illegal commentEOF inside comment # line %d "%s" bad syntax on $ clauseyyval.%sIllegal use of $%dyypvt[-%d]must specify type of $%d.%sEOF inside commentnewline in string or char. const.EOF in string or character constantaction does not terminateshort yyexca[] ={ %d: reduce/reduce conflict (red'ns %d and %d ) on %s }; YYNPRODoff = %d, k = %d action table overflow %d no space in action table$ %d,%d,%d %s: gotos on %s %d: shift/reduce conflict (shift %ortl _access[b _alarmQ _aoutput<. _apackR _arout _aryfilX _brkH _calloptX _cdata _cemptyD _chcopy0 _chfindll _close. _closure _cpfir _cpres4& _cpyact2z _cpycode1b _cpyunionl| _creatl _create_contiguous), _cstash& _defin(4 _defoutm _dupm _dup24 _errory _etext[p _exitd _fclosed, red'n %d) on %s-1, %d, %d, %d, %d,%d, -2, %d, state %d %s %s %s accepterrorshift %dreduce %d . reduce %d . error %s goto %d # define %s %d short %s[]={ %4d }; ,Rule not reduced: %s %d rules never reduced ߸V_~yacc.tmproptimizer cannot open tempfilebad tempfilebad tempfileState %d: null %4d %4d yacc.tmpa array overflowa array overflowNonterminal %d, entry at %d cannot place goto %d State %d: entry at %d equals state %0 _fdtyped _fflush] _fgetc% _finact _flsete| _fopenc _fprintf\ _fputcvP _freem0 _fstatk _getenv) _gettokL _gin?6 _go2gen= _go2outS@ _gtnmG _hideprody< _isatty[ _kill[ _linkmP _lrecmp _lseek8 _mains _malloc\ _mknod\B _mountPn _nxtil _openQ _osummary _others9$ _output[ d out of space in optimizer a arrayclobber of a array, pos'n %d, by %dState %d: entry at %d Error; failure to place state %d nxti = %d, max = %d Optimizer space used: input %d/%d, output %d/%d %d table entries, %d zero maximum spread: %d, maximum offset: %d # define YYLAST %d yyactyypactyypgoshort %s[]={ %4d }; ,out of space (%s) At line %d in Source file %s %s : PRLINENOTAGS : %s : Unknown error number %d (sys%d) %s : usage : %s %s : INTERNAL ERROR : _doprint: %s 9_pauseAR _precftn _prlook _putitemq _readX _sbrk _setunion _setup3 _skipcomk _sprintf _stagenm _stat _stateN\ _stin\ _strcmpm _strlenx _strncmpw _strtol _summaryf _symnamm _truncf\f _umountk _ungetc\ _unlinkm _urec[ _waitGN _warrayG( _wdefB _wractl@ _writeh _writemD0123456789abcdef0123456789ABCDEF01234567890123456789abcdef0123456789ABCDEF0123456789NO $$syscally ETEXT StartS _ERRORs< __allocfpZ __chcodesX __doprnt[ __exitpX __fillbufn __flushbufq __fmtout^P __fprtfq __fprtfpq __fscnfpw __itostrv __ltostrs __setupfpg$ __sprtfq __sprtfpq __sscnfpv __strtoix __termorpipe[L _ab _wrstateY ldivZ8 lmodY0 lmulY lrdivZ& lrmoduR uldivu ulmodu ulmuluB ulrdivu ulrmod EDATA ___msz __allocp __iob __ioblst< _adb _cldebug` _cnamp\ _cnamsz _edata _environ _errnop _extval _fatfl< _g2debug _ggreed _gsdebug _indebug _lineno0 _maxoff, _maxsprt _mem _mempd _ndefout _nerrors _nlsetl _nnonter _nolookx _nprod _nstateh _ntokens8 _nxdb$ _pgo _pidebug8 _pkdebug4 _pmem( _yypgo _zzacent _zzclose _zzcwp _zzexcp _zzgobest _zzgoent _zzmemsz _zzrrconf _zzsrconf end_adr euid pid8 stderr stdin s Yacc Differences This document gives a short list of differences between the new Yacc and earlier Yaccs. _B_u_g_s _F_i_x_e_d 1. There was a bug which caused Yacc to silently steal away in the night if an action had mismatched '' in it; this is fixed. 2. A number of table size overflow conditions used to be checked incorrectly or not at all; this is now better. 3. A bug which suppressed the printing of some rules with empty RHtdout uid9 END9 __base9 __last_err9 __pgmnameM _amemߐ _clset5 _cnames` _cwp- _defact9 _end_j _faction_n _fdefine_f _finput_z _foutput_r _ftable_v _ftemp- _indgo5L _infile- _lastred$^ _levprd _lkst9 _maxa_~ _mem0B@ _mstatesV _nontrst= _ntstatesI _ntypes5P _numbval% _pempty S's on the y.output file has been fixed. _S_p_e_e_d_u_p_s, _S_h_r_i_n_k_s, _a_n_d _D_i_d_d_l_e_s 1. The old optimizer (-o) flag is now the default in Yacc. At the same time, the Yacc process itself has been sped up; the result is that Yacc takes about the same or slightly longer on short inputs, but is much faster on long inputs. 2. The optimized parsers produced by Yacc are likely to be 2-3 times faster and 1-2k bytes smaller than the old _pfirst _prdptr8 _presd _pstate_b _start9 _sys_errlist9 _sys_nerr _tbitset x _temp1R _toklev5T _toknameJ _tokset9 _tstatesI _typeset"$ _tystate߰ _wsetswrapper.a,v 2.0 86/09/10 12:02:06 rich Released %4d }; ,out of space (%s) At line %d in Source file %s %s : PRLINENOTAGS : %s : Unknown error number %d (sys%d) %s : usage : %s %s : INTERNAL ERROR : _doprint: %s 9 ones, for medium/large grammars. The time to parse is now essentially independent of the grammar size; it used to grow as the size of the grammar did. 3. The y.output file has been considerably reformatted, to make it easier to read. The old "goto" table is gone; the goto's for nonterminal symbols are now printed in the states where they occur. Rules which can be reduced in a state have their rule number printed after them, in (). This makes it m   yaccdiffs. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czs"uch easier to interpret the "reduce n" actions. The message "same as n" has been removed; duplicate states are in fact duplicated, saving shuffling and cross-referencing. 4. Various table sizes are somewhat bigger. 5. The form feed character, and the construction '\f', are now recognized; form feed is ignored (=whitespace) on input. January 14, 1977 - 2 - 6. The arrays "yysterm" and "yysnter" are no longer  pro- duced on output; they were little used, and took up a surprising amount of space in the parser. 7. Rules in the input which are not reduced are now com- plained about; they may represent unreachable parts of the grammar, botched precedence, or duplicate rules. As with conflicts, a summary complaint, "n rules not reduced", appears at the terminal; more information is on the y.output file. _N_e_w _F_e_a_t_u_r_e_s 1. The actions are now coin rules are assumed to be distinct. If some actions are the same, Yacc might report reduce/reduce conflicts which could be resolved by explicitly identifying identical actions; does anyone have a good idea for a syntax to do this? The = sign may now be omitted in action constructions of the form ={ ... }. January 14, 1977 - 3 - 4. As a result of the rearrangement of rules, people whpied into the middle of the parser, rather than being gathered into a separate rou- tine. It's faster. Also, you can return a value from yyparse (and stop parsing...) by saying `return(x);' in an action. There are macros which simulate various interesting parsing actions: YYERROR causes the parser to behave as if a syntax error had been encountered (i.e., do error recovery) YYACCEPT causes a return from yyparse with a value of 0 YYABORT causes a ro thought they knew what $1 really turned into, and wrote programs which referred to yypv[1], etc., are in trou- ble. See Steve Johnson if you are really suffering. January 14, 1977 acc takes about the same or slightly longer on short inputs, but is much faster on long inputs. 2. The optimized parsers produced by Yacc are likely to be 2-3 times faster and 1-2k bytes smaller than the old eturn from yyparse with a value of 1 2. The repositioning of the actions may cause scope prob- lems for some people who include lexical analyzers in funny places. This can probably be avoided by using another new feature: the `-d' option. Invoking Yacc with the -d option causes the #defines generated by Yacc to be written out onto a file called "y.tab.h", (as well as on the "y.tab.c" file). This can then be included as desired in lexical analyzers,   yaccnews. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czs" etc. 3. Actions are now permitted within rules; for such actions, $$, $1, $2, etc. continue to have their usual meanings. An error message is returned if any $n refers to a value lying to the right of the action in the rule. These internal actions are assumed to return a value, which is accessed through the $n mechanism. In the y.output file, the actions are referred to by created nonterminal names of the form $$nnn. All actions with5/18/78 A new version of Yacc has been installed which contains some new features relating to error recovery, detection of funny conditions in the grammar, and strong typing. Existing grammars should continue to work, with the possible exception of somewhat better error recovery behavior. More details follow: *** Ratfor and EFL Yacc are dead. Long live C! *** The y.tab.c file now uses the # line feature to reflect most error conditions in actions, etc., back to the yacc source file, rather than the y.tab.c file. As always with such features, lookahead may cause the line number to be one too large occasionally. *** The error recovery algorithm has been changed to cause the parser never to reduce on a state where there is a shift on the special token `error'. This has the effect of causing the error recovery action to take place somewhat closer to the location of the error than previously. It does not affect the behavior of the parser in the absence of errors. The parse tables may be 1-2% larlare the type of all the terminal and nonterminal symbols which will have values. If the type declaration feature is used at all, it must be used correctly; if it is not used, the default values are integers, as at present. The new type declaration features are described below: *** There is a new keyword, %union. A construction such as %union { int inttag; float floattag; struct mumble *ptrtag; } can be used, in the declarations section, to declare the type of the yacc stack. The decger as a result of this change. *** Yacc now detects the existence of nonterminals in the grammar which can never derive any strings of tokens (even the empty string). The simplest example is the grammar: %% s : s 'a' ; Here, one must reduce `s' in order to reduce `s': the parser would always report error. If such nonterminals are present, Yacc reports all such, then terminates. *** There is a new reserved word, %start. When used in the declarations section, it may be used to declare the startlaration is effectively copied to the y.tab.c file, and, if the -d option is present, to the y.tab.h file as well. The declaration is used to declare the typedef YYSTYPE, which is the type of the value stack. If the -d option is present, the declaration extern YYSTYPE yylval; is also placed onto the y.tab.h file. Note that the lexical analyzer must be changed to use the appropriate union tag when assigning values. It is not necessary that the %union mechanism be used, as long as there is a un symbol of the grammar. If %start does not appear, the start symbol is, as at present, the first nonterminal symbol encountered. *** Yacc produced parsers are notorious for producing many many comments from lint. The problem is the value stack of the parser, which typically may contain integers, pointers, and possibly even floating point, etc., values. The lack of tight specification of this stack leads to potential nonportability, and considerable loss of the diagnostic power of lint. Thus, somion type YYSTYPE defined in the declarations section. *** The %token, %left, %right, and %nonassoc declarations now accept a union tag, enclosed in angle brackets (<...>), immediately after the keyword. All tokens mentioned in that declaration are taken to have the appropriate type. *** There is a new keyword, %type, also followed by a union tag in angle brackets, which may be used in the declarations section to declare nonterminal symbols to have a particular type. In both cases, whenever a $$ oe new features have been added which make use of the new structure and union facilities of C. In effect, the user of Yacc may `honestly' declare the value stack, as well as the lexical interface variable, yylval, to be unions of all the types desired. Yacc will keep track of the types declared for all terminals and nonterminals, and automatically insert the appropriate union tag for all constructions such as $1, $$, etc. It is up to the user to supply the appropriate union declaration, and to decr $n is encountered in an action, the appropriate union tag is supplied by Yacc. Once any type is declared, it is an error to use a $$ or $n whose type is unknown. It is also illegal to have a grammar rule whose LHS has a type, but the rule has no action and the default action { $$ = $1; } would be inapplicable because $1 had a different type. *** There are occasional times when the type of something is not known (for example, when an action within a rule returns a value). In this case, the $$ and $n syntax is extended to permit the declaration of the type: the syntax is $$ and $n respectively. This rather strange syntax is necessitated by the need to distinguish the <> surrounding the tag from the < and > operators of C in the action. It is anticipated that the usage will be rare. *** As always, report gripes, bugs, suggestions to SCJ *** 12/01/76 A newer version of Yacc has been installed which copies the actions directly into the parser, rather than gathering them into a anyone have a good idea for a syntax to do this? In the new Yacc, the = sign may now be omitted in action constructions of the form ={ ... } correctly; if it is not used, the default values are integers, as at present. The new type declaration features are described below: *** There is a new keyword, %union. A construction such as %union { int inttag; float floattag; struct mumble *ptrtag; } can be used, in the declarations section, to declare the type of the yacc stack. The decseparate routine. The advantages include 1. It's faster 2. You can return a value from yyparse (and stop parsing...) by saying `return(x);' in an action 3. There are macros which simulate various interesting parsing actions: YYERROR causes the parser to behave as if a syntax error had been encountered (i.e., do error recovery) YYACCEPT causes a return from yyparse with a value of 0 YYABORT causes a return from yyparse with a value of 1 The repositioning of the  h  i  yaccpar. ڌt: ^ "*-z-z Sx1-6-87 yacc~Czr"actions may cause scope problems for some people who include lexical analyzers in funny places. This can probably be avoided by using another new feature: the `-d' option. Invoking Yacc with the -d option causes the #defines generated by Yacc to be written out onto a file called "y.tab.h". This can then be included as desired in lexical analyzers, etc. 11/28/76 A new version of Yacc has been installed which permits actions within rules. For such actions, $$ and $1, $2, etc. continue to have their usual m/* static char yaccpar_sccsid[] = "@(#)yaccpar 4.1 (Berkeley) 2/11/83"; */ # # define YYFLAG -1000 # define YYERROR goto yyerrlab # define YYACCEPT return(0) # define YYABORT return(1) /* parser for yacc output */ #ifdef YYDEBUG int yydebug = 0; /* 1 for debugging */ #endif YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */ int yychar = -1; /* current input token number */ int yynerrs = 0; /* number of errors */ short yyerrflag = 0; /* error recovery flag */ yyparse() { short yys[YYMAXDEPTH]eanings. An error message is returned if any $n refers to a value lying to the right of the action in the rule. These internal actions are assumed to return a value, which is accessed through the $n mechanism. In the y.output file, the actions are referred to by created nonterminal names of the form $$nnn. All actions within rules are assumed to be distinct. If some actions are the same, Yacc might report reduce/reduce conflicts which could be resolved by explicitly identifying identical actions; does ; short yyj, yym; register YYSTYPE *yypvt; register short yystate, *yyps, yyn; register YYSTYPE *yypv; register short *yyxi; yystate = 0; yychar = -1; yynerrs = 0; yyerrflag = 0; yyps= &yys[-1]; yypv= &yyv[-1]; yystack: /* put a state and value onto the stack */ #ifdef YYDEBUG if( yydebug ) printf( "state %d, char 0%o\n", yystate, yychar ); #endif if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); } *yyps = yystate; ++yypv; *yypv = yyval; yynewstate:  yyn = yypact[yystate]; if( yyn<= YYFLAG ) goto yydefault; /* simple state */ if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0; if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault; if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */ yychar = -1; yyval = yylval; yystate = yyn; if( yyerrflag > 0 ) --yyerrflag; goto yystack; } yydefault: /* default state action */ if( (yyn=yydef[yystate]) == -2 ) { if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0; /* look through exc#endif yyps -= yyr2[yyn]; yypvt = yypv; yypv -= yyr2[yyn]; yyval = yypv[1]; yym=yyn; /* consult goto table to find next state */ yyn = yyr1[yyn]; yyj = yypgo[yyn] + *yyps + 1; if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]]; switch(yym){ $A } goto yystack; /* stack new state and value */ } t be changed to use the appropriate union tag when assigning values. It is not necessary that the %union mechanism be used, as long as there is a uneption table */ for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */ while( *(yyxi+=2) >= 0 ){ if( *yyxi == yychar ) break; } if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */ } if( yyn == 0 ){ /* error */ /* error ... attempt to resume parsing */ switch( yyerrflag ){ case 0: /* brand new error */ yyerrlab: yyerror( "syntax error" ); ++yynerrs; case 1: case 2: /* incompletely recovered error ... try again */ yyerrflag = 3; /* f#F-ɲd\ig؊i i i 2#  i  i  yaccpar.ccparyaccparind a state where "error" is a legal shift action */ while ( yyps >= yys ) { yyn = yypact[*yyps] + YYERRCODE; if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){ yystate = yyact[yyn]; /* simulate a shift of "error" */ goto yystack; } yyn = yypact[*yyps]; /* the current yyps has no shift onn "error", pop stack */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] ); #endif --yyps; --yypv; } /* there is no state on the stack with an error shift ... abort */ yyabort: return(1); case 3: /* no shift yet; clobber input char */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery discards char %d\n", yychar ); #endif if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */ yychar = -1; goto yynewstate; /* try again in the same state */ } } /* reduction by production yyn */ #ifdef YYDEBUG if( yydebug ) printf("reduce %d\n",yyn);        !!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"! ""##$$%%&&''