[comp.sources.mac] Bison Macintosh Sources

wetter@tybalt.caltech.edu (Pierce T. Wetter) (05/14/88)

[Bison Macintosh Sources - part 1 of 6]

---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	Bison/COPYING
#	Bison/Makefile
#	Bison/REFERENCES
#	Bison/bison.1
#	Bison/bison.cld
#	Bison/bison.hairy
#	Bison/bison.simple
#	Bison/build.com
#	Bison/vmshlp.mar
# This archive created: Sat May 14 02:41:40 1988
# By:	Roger L. Long (bytebug@dhw68k.cts.com)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'COPYING'" '(7191 characters)'
if test -f 'COPYING'
then
	echo shar: will not over-write existing file "'COPYING'"
else
sed 's/^X//' << \SHAR_EOF > 'COPYING'
X
X		    BISON GENERAL PUBLIC LICENSE
X		      (Clarified 11 Feb 1988)
X
X Copyright (C) 1988 Richard M. Stallman
X Everyone is permitted to copy and distribute verbatim copies
X of this license, but changing it is not allowed.  You can also
X use this wording to make the terms for other programs.
X
X  The license agreements of most software companies keep you at the
Xmercy of those companies.  By contrast, our general public license is
Xintended to give everyone the right to share BISON.  To make sure that
Xyou get the rights we want you to have, we need to make restrictions
Xthat forbid anyone to deny you these rights or to ask you to surrender
Xthe rights.  Hence this license agreement.
X
X  Specifically, we want to make sure that you have the right to give
Xaway copies of BISON, that you receive source code or else can get it
Xif you want it, that you can change BISON or use pieces of it in new
Xfree programs, and that you know you can do these things.
X
X  To make sure that everyone has such rights, we have to forbid you to
Xdeprive anyone else of these rights.  For example, if you distribute
Xcopies of BISON, you must give the recipients all the rights that you
Xhave.  You must make sure that they, too, receive or can get the
Xsource code.  And you must tell them their rights.
X
X  Also, for our own protection, we must make certain that everyone
Xfinds out that there is no warranty for BISON.  If BISON is modified by
Xsomeone else and passed on, we want its recipients to know that what
Xthey have is not what we distributed, so that any problems introduced
Xby others will not reflect on our reputation.
X
X  Therefore we (Richard Stallman and the Free Software Fundation,
XInc.) make the following terms which say what you must do to be
Xallowed to distribute or change BISON.
X
X
X			COPYING POLICIES
X
X  1. You may copy and distribute verbatim copies of BISON source code as
Xyou receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy a valid copyright notice "Copyright
X(C) 1986 Free Software Foundation, Inc." (or with whatever year is
Xappropriate); keep intact the notices on all files that refer
Xto this License Agreement and to the absence of any warranty; and give
Xany other recipients of the BISON program a copy of this License
XAgreement along with the program.
X
X  2. You may modify your copy or copies of BISON or any portion of it,
Xand copy and distribute such modifications under the terms of
XParagraph 1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating
X    that you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish,
X    that in whole or in part contains or is a derivative of BISON or
X    any part thereof, to be licensed at no charge to all third
X    parties on terms identical to those contained in this License
X    Agreement (except that you may choose to grant more extensive
X    warranty protection to some or all third parties, at your
X    option)
X
X    c) You may charge a distribution fee for the physical act of
X    transferring a copy, and you may at your option offer warranty
X    protection in exchange for a fee.
X
XMere aggregation of another unrelated program with this program (or its
Xderivative) on a volume of a storage or distribution medium does not bring
Xthe other program under the scope of these terms.
X
X  3. You may copy and distribute BISON (or a portion or derivative of it,
Xunder Paragraph 2) in object code or executable form under the terms of
XParagraphs 1 and 2 above provided that you also do one of the following:
X
X    a) accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    b) accompany it with a written offer, valid for at least three
X    years, to give any third party free (except for a nominal
X    shipping charge) a complete machine-readable copy of the
X    corresponding source code, to be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    c) accompany it with the information you received as to where the
X    corresponding source code may be obtained.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form alone.)
X
XFor an executable file, complete source code means all the source code for
Xall modules it contains; but, as a special exception, it need not include
Xsource code for modules which are standard libraries that accompany the
Xoperating system on which the executable file runs.
X
X  4. You may not copy, sublicense, distribute or transfer BISON
Xexcept as expressly provided under this License Agreement.  Any attempt
Xotherwise to copy, sublicense, distribute or transfer BISON is void and
Xyour rights to use the program under this License agreement shall be
Xautomatically terminated.  However, parties who have received computer
Xsoftware programs from you with this License Agreement will not have
Xtheir licenses terminated so long as such parties remain in full compliance.
X
X  5. If you wish to incorporate parts of GNU CC into other free programs
Xwhose distribution conditions are different, write to the Free Software
XFoundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet worked
Xout a simple rule that can be stated here, but we will often permit this.
XWe will be guided by the two goals of preserving the free status of all
Xderivatives of our free software and of promoting the sharing and reuse of
Xsoftware.
X
XYour comments and suggestions about our licensing policies and our
Xsoftware are welcome!  Please contact the Free Software Foundation, Inc.,
X675 Mass Ave, Cambridge, MA 02139, or call (617) 876-3296.
X
XIn other words, go ahead and share BISON, but don't try to stop
Xanyone else from sharing it farther.  Help stamp out software hoarding!
X
X		       NO WARRANTY
X
X  BECAUSE BISON IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY NO
XWARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE BISON "AS IS" WITHOUT
XWARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
XLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
XA PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND
XPERFORMANCE OF BISON IS WITH YOU.  SHOULD BISON PROVE DEFECTIVE, YOU
XASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
X
X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
XWHO MAY MODIFY AND REDISTRIBUTE BISON AS PERMITTED ABOVE, BE LIABLE TO
XYOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER
XSPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
XINABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
XBEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A
XFAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) BISON, EVEN
XIF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR
XANY CLAIM BY ANY OTHER PARTY.
SHAR_EOF
if test 7191 -ne "`wc -c < 'COPYING'`"
then
	echo shar: error transmitting "'COPYING'" '(should have been 7191 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'Makefile'" '(1892 characters)'
if test -f 'Makefile'
then
	echo shar: will not over-write existing file "'Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'Makefile'
X# Makefile for bison
X
XDESTDIR=
X# where the installed binary goes
XBINDIR = $(DESTDIR)/usr/local
X
X# where the parsers go
XPARSERDIR = $(DESTDIR)/usr/local/lib
X
X# names of parser files
XPFILE = bison.simple
XPFILE1 = bison.hairy
X
X# It is unwise ever to compile a program without symbols.
XCFLAGS = -g
X
XPFILES = -DXPFILE=\"$(PARSERDIR)/$(PFILE)\" \
X	 -DXPFILE1=\"$(PARSERDIR)/$(PFILE1)\"
X
XOBJECTS = LR0.o allocate.o closure.o conflicts.o derives.o files.o	\
X	  getargs.o gram.o lalr.o					\
X	  lex.o main.o nullable.o output.o print.o reader.o symtab.o	\
X	  warshall.o
X
Xstart: bison
X
Xclean:
X	rm -f *.o core bison
X
Xinstall: bison
X	install bison $(BINDIR)
X	cp $(PFILE) $(PFILE1) $(PARSERDIR)
X
Xbison: $(OBJECTS)
X	$(CC) $(LDFLAGS) -o bison $(OBJECTS)
X
Xdist:	bison-dist.tar bison-dist.tar.Z
X
Xbison-dist.tar:
X	tar cvf bison-dist.tar \
X		COPYING Makefile REFERENCES bison.1 bison.simple bison.hairy \
X		LR0.c allocate.c closure.c conflicts.c \
X		derives.c files.c getargs.c gram.c lalr.c lex.c main.c \
X		nullable.c output.c print.c reader.c symtab.c warshall.c \
X		files.h gram.h lex.h machine.h new.h state.h symtab.h types.h \
X		bison.cld build.com vmsgetargs.c vmshlp.mar
Xbison-dist.tar.Z: bison-dist.tar
X	compress < bison-dist.tar > bison-dist.tar.Z
X
X# This file is different to pass the parser file names
X# to the compiler.
Xfiles.o: files.c files.h new.h gram.h
X	$(CC) -c $(CFLAGS) $(PFILES) files.c
X
XLR0.o: machine.h new.h gram.h state.h
Xclosure.o: machine.h new.h gram.h
Xconflicts.o: machine.h new.h files.h gram.h state.h
Xderives.o: new.h types.h gram.h
Xgetargs.o: files.h
Xlalr.o: machine.h types.h state.h new.h gram.h
Xlex.o: files.h symtab.h lex.h
Xmain.o: machine.h
Xnullable.o: types.h gram.h new.h
Xoutput.o: machine.h new.h files.h gram.h state.h
Xprint.o: machine.h new.h files.h gram.h state.h
Xreader.o: files.h new.h symtab.h lex.h gram.h
Xsymtab.o: new.h symtab.h gram.h
Xwarshall.o: machine.h
SHAR_EOF
if test 1892 -ne "`wc -c < 'Makefile'`"
then
	echo shar: error transmitting "'Makefile'" '(should have been 1892 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'REFERENCES'" '(1197 characters)'
if test -f 'REFERENCES'
then
	echo shar: will not over-write existing file "'REFERENCES'"
else
sed 's/^X//' << \SHAR_EOF > 'REFERENCES'
XFrom phr Tue Jul  8 10:36:19 1986
XDate: Tue, 8 Jul 86 00:52:24 EDT
XFrom: phr (Paul Rubin)
XTo: riferguson%watmath.waterloo.edu@CSNET-RELAY.ARPA, tower
XSubject: Re:  Bison documentation?
X
XThe main difference between Bison and Yacc that I know of is that
XBison supports the @N construction, which gives you access to
Xthe starting and ending line number and character number associated
Xwith any of the symbols in the current rule.
X
XAlso, Bison supports the command `%expect N' which says not to mention
Xthe conflicts if there are N shift/reduce conflicts and no reduce/reduce
Xconflicts.
X
XThe differences in the algorithms stem mainly from the horrible
Xkludges that Johnson had to perpetrate to make Yacc fit in a PDP-11.
X
XAlso, Bison uses a faster but less space-efficient encoding for the
Xparse tables (see Corbett's PhD thesis from Berkeley, "Static
XSemantics in Compiler Error Recovery", June 1985, Report No. UCB/CSD
X85/251), and more modern technique for generating the lookahead sets.
X(See "Efficient Construction of LALR(1) Lookahead Sets" by F. DeRemer
Xand A. Pennello, in ACM TOPLS Vol 4 No 4, October 1982.  Their
Xtechnique is the standard one now.)
X
X	paul rubin
X	free software foundation
X
X
SHAR_EOF
if test 1197 -ne "`wc -c < 'REFERENCES'`"
then
	echo shar: error transmitting "'REFERENCES'" '(should have been 1197 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'bison.1'" '(1136 characters)'
if test -f 'bison.1'
then
	echo shar: will not over-write existing file "'bison.1'"
else
sed 's/^X//' << \SHAR_EOF > 'bison.1'
X.TH BISON 1 local
X.SH NAME
Xbison \- GNU Project parser generator (yacc replacement)
X.SH SYNOPSIS
X.B bison
X[
X.B \-dvy
X] file
X.SH DESCRIPTION
X.I Bison
Xis a parser generator in the style of
X.IR yacc (1).
XIt should be upwardly compatible with input files designed
Xfor
X.IR yacc .
X.PP
XInput files should follow the
X.I yacc
Xconvention of ending in ``.y''.
XUnlike
X.IR yacc ,
Xthe generated files do not have fixed names, but instead use the prefix
Xof the input file.
XFor instance, a grammar description file named
X.B parse.y
Xwould produce the generated parser in a file named
X.BR parse.tab.c ,
Xinstead of
X.IR yacc 's
X.BR y.tab.c .
X.PP
X.I Bison
Xtakes three optional flags.
X.TP
X.B \-d
XProduce a
X.B .tab.h
Xfile, similar to
X.IR yacc 's
X.B y.tab.h
Xfile.
X.TP
X.B \-v
XBe verbose. Analogous to the same flag for
X.IR yacc .
X.TP
X.B \-y
XUse fixed output file names. I.e., force the output to be in files
X.BR y.tab.c ,
X.BR y.tab.h ,
Xand so on. This is for full
X.I yacc
Xcompatibility.
X.SH FILES
X/usr/local/lib/bison.simple	simple parser
X.br
X/usr/local/lib/bison.hairy	complicated parser
X.SH SEE ALSO
X.IR yacc (1)
X.SH DIAGNOSTICS
X``Self explanatory.''
X... ha!
SHAR_EOF
if test 1136 -ne "`wc -c < 'bison.1'`"
then
	echo shar: error transmitting "'bison.1'" '(should have been 1136 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'bison.cld'" '(301 characters)'
if test -f 'bison.cld'
then
	echo shar: will not over-write existing file "'bison.cld'"
else
sed 's/^X//' << \SHAR_EOF > 'bison.cld'
X!
X!	VMS BISON command definition file
X!
XDEFINE	VERB	BISON
X	IMAGE	GNU_BISON:[000000]BISON
X
X	PARAMETER	P1,Label=BISON$INFILE,Prompt="File"
X				value(required,type=$infile)
X	QUALIFIER	VERBOSE,Label=BISON$VERBOSE
X	QUALIFIER	DEFINES,Label=BISON$DEFINES
X	QUALIFIER	FIXED_OUTFILES,Label=BISON$FIXED_OUTFILES
SHAR_EOF
if test 301 -ne "`wc -c < 'bison.cld'`"
then
	echo shar: error transmitting "'bison.cld'" '(should have been 301 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'bison.hairy'" '(6474 characters)'
if test -f 'bison.hairy'
then
	echo shar: will not over-write existing file "'bison.hairy'"
else
sed 's/^X//' << \SHAR_EOF > 'bison.hairy'
X
Xextern int timeclock;
X
X
Xint yyerror;		/*  Yyerror and yycost are set by guards.	*/
Xint yycost;		/*  If yyerror is set to a nonzero value by a	*/
X			/*  guard, the reduction with which the guard	*/
X			/*  is associated is not performed, and the	*/
X			/*  error recovery mechanism is invoked.	*/
X			/*  Yycost indicates the cost of performing	*/
X			/*  the reduction given the attributes of the	*/
X			/*  symbols.					*/
X
X
X/*  YYMAXDEPTH indicates the size of the parser's state and value	*/
X/*  stacks.								*/
X
X#ifndef	YYMAXDEPTH
X#define	YYMAXDEPTH	500
X#endif
X
X/*  YYMAXRULES must be at least as large as the number of rules that	*/
X/*  could be placed in the rule queue.  That number could be determined	*/
X/*  from the grammar and the size of the stack, but, as yet, it is not.	*/
X
X#ifndef	YYMAXRULES
X#define	YYMAXRULES	100
X#endif
X
X#ifndef	YYMAXBACKUP
X#define YYMAXBACKUP	100
X#endif
X
X
Xshort	yyss[YYMAXDEPTH];	/*  the state stack			*/
XYYSTYPE	yyvs[YYMAXDEPTH];	/*  the semantic value stack		*/
XYYLTYPE yyls[YYMAXDEPTH];	/*  the location stack			*/
Xshort	yyrq[YYMAXRULES];	/*  the rule queue			*/
Xint	yychar;			/*  the lookahead symbol		*/
X
XYYSTYPE	yylval;			/*  the semantic value of the		*/
X				/*  lookahead symbol			*/
X
XYYSTYPE yytval;			/*  the semantic value for the state	*/
X				/*  at the top of the state stack.	*/
X
XYYSTYPE yyval;			/*  the variable used to return		*/
X				/*  semantic values from the action	*/
X				/*  routines				*/
X
XYYLTYPE yylloc;		/*  location data for the lookahead	*/
X				/*  symbol				*/
X
XYYLTYPE yytloc;		/*  location data for the state at the	*/
X				/*  top of the state stack		*/
X
X
Xint	yynunlexed;
Xshort	yyunchar[YYMAXBACKUP];
XYYSTYPE	yyunval[YYMAXBACKUP];
XYYLTYPE yyunloc[YYMAXBACKUP];
X
Xshort *yygssp;			/*  a pointer to the top of the state	*/
X				/*  stack; only set during error	*/
X				/*  recovery.				*/
X
XYYSTYPE *yygvsp;		/*  a pointer to the top of the value	*/
X				/*  stack; only set during error	*/
X				/*  recovery.				*/
X
XYYLTYPE *yyglsp;		/*  a pointer to the top of the		*/
X				/*  location stack; only set during	*/
X				/*  error recovery.			*/
X
X
X/*  Yyget is an interface between the parser and the lexical analyzer.	*/
X/*  It is costly to provide such an interface, but it avoids requiring	*/
X/*  the lexical analyzer to be able to back up the scan.		*/
X
Xyyget()
X{
X  if (yynunlexed > 0)
X    {
X      yynunlexed--;
X      yychar = yyunchar[yynunlexed];
X      yylval = yyunval[yynunlexed];
X      yylloc = yyunloc[yynunlexed];
X    }
X  else if (yychar <= 0)
X    yychar = 0;
X  else
X    {
X      yychar = yylex();
X      if (yychar < 0)
X	yychar = 0;
X      else yychar = YYTRANSLATE(yychar);
X    }
X}
X
X
X
Xyyunlex(chr, val, loc)
Xint chr;
XYYSTYPE val;
XYYLTYPE loc;
X{
X  yyunchar[yynunlexed] = chr;
X  yyunval[yynunlexed] = val;
X  yyunloc[yynunlexed] = loc;
X  yynunlexed++;
X}
X
X
X
Xyyrestore(first, last)
Xregister short *first;
Xregister short *last;
X{
X  register short *ssp;
X  register short *rp;
X  register int symbol;
X  register int state;
X  register int tvalsaved;
X
X  ssp = yygssp;
X  yyunlex(yychar, yylval, yylloc);
X
X  tvalsaved = 0;
X  while (first != last)
X    {
X      symbol = yystos[*ssp];
X      if (symbol < YYNTBASE)
X	{
X	  yyunlex(symbol, yytval, yytloc);
X	  tvalsaved = 1;
X	  ssp--;
X	}
X
X      ssp--;
X
X      if (first == yyrq)
X	first = yyrq + YYMAXRULES;
X
X      first--;
X
X      for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++)
X	{
X	  if (symbol < YYNTBASE)
X	    state = yytable[yypact[*ssp] + symbol];
X	  else
X	    {
X	      state = yypgoto[symbol - YYNTBASE] + *ssp;
X
X	      if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp)
X		state = yytable[state];
X	      else
X		state = yydefgoto[symbol - YYNTBASE];
X	    }
X
X	  *++ssp = state;
X	}
X    }
X
X  if ( ! tvalsaved && ssp > yyss)
X    {
X      yyunlex(yystos[*ssp], yytval, yytloc);
X      ssp--;
X    }
X
X  yygssp = ssp;
X}
X
X
X
Xint
Xyyparse()
X{
X  register int yystate;
X  register int yyn;
X  register short *yyssp;
X  register short *yyrq0;
X  register short *yyptr;
X  register YYSTYPE *yyvsp;
X
X  int yylen;
X  YYLTYPE *yylsp;
X  short *yyrq1;
X  short *yyrq2;
X
X  yystate = 0;
X  yyssp = yyss - 1;
X  yyvsp = yyvs - 1;
X  yylsp = yyls - 1;
X  yyrq0 = yyrq;
X  yyrq1 = yyrq0;
X  yyrq2 = yyrq0;
X
X  yychar = yylex();
X  if (yychar < 0)
X    yychar = 0;
X  else yychar = YYTRANSLATE(yychar);
X
Xyynewstate:
X
X  if (yyssp >= yyss + YYMAXDEPTH - 1)
X    {
X      yyabort("Parser Stack Overflow");
X      YYABORT;
X    }
X
X  *++yyssp = yystate;
X
Xyyresume:
X
X  yyn = yypact[yystate];
X  if (yyn == YYFLAG)
X    goto yydefault;
X
X  yyn += yychar;
X  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar)
X    goto yydefault;
X
X  yyn = yytable[yyn];
X  if (yyn < 0)
X    {
X      yyn = -yyn;
X      goto yyreduce;
X    }
X  else if (yyn == 0)
X    goto yyerrlab;
X
X  yystate = yyn;
X
X  yyptr = yyrq2;
X  while (yyptr != yyrq1)
X    {
X      yyn = *yyptr++;
X      yylen = yyr2[yyn];
X      yyvsp -= yylen;
X      yylsp -= yylen;
X
X      yyguard(yyn, yyvsp, yylsp);
X      if (yyerror)
X	goto yysemerr;
X
X      yyaction(yyn, yyvsp, yylsp);
X      *++yyvsp = yyval;
X
X      yylsp++;
X      if (yylen == 0)
X	{
X	  yylsp->timestamp = timeclock;
X	  yylsp->first_line = yytloc.first_line;
X	  yylsp->first_column = yytloc.first_column;
X	  yylsp->last_line = (yylsp-1)->last_line;
X	  yylsp->last_column = (yylsp-1)->last_column;
X	  yylsp->text = 0;
X	}
X      else
X	{
X	  yylsp->last_line = (yylsp+yylen-1)->last_line;
X	  yylsp->last_column = (yylsp+yylen-1)->last_column;
X	}
X	  
X      if (yyptr == yyrq + YYMAXRULES)
X        yyptr = yyrq;
X    }
X
X  if (yystate == YYFINAL)
X    YYACCEPT;
X
X  yyrq2 = yyptr;
X  yyrq1 = yyrq0;
X
X  *++yyvsp = yytval;
X  *++yylsp = yytloc;
X  yytval = yylval;
X  yytloc = yylloc;
X  yyget();
X
X  goto yynewstate;
X
Xyydefault:
X
X  yyn = yydefact[yystate];
X  if (yyn == 0)
X    goto yyerrlab;
X
Xyyreduce:
X
X  *yyrq0++ = yyn;
X
X  if (yyrq0 == yyrq + YYMAXRULES)
X    yyrq0 = yyrq;
X
X  if (yyrq0 == yyrq2)
X    {
X      yyabort("Parser Rule Queue Overflow");
X      YYABORT;
X    }
X
X  yyssp -= yyr2[yyn];
X  yyn = yyr1[yyn];
X
X  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
X  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
X    yystate = yytable[yystate];
X  else
X    yystate = yydefgoto[yyn - YYNTBASE];
X
X  goto yynewstate;
X
Xyysemerr:
X  *--yyptr = yyn;
X  yyrq2 = yyptr;
X  yyvsp += yyr2[yyn];
X
Xyyerrlab:
X
X  yygssp = yyssp;
X  yygvsp = yyvsp;
X  yyglsp = yylsp;
X  yyrestore(yyrq0, yyrq2);
X  yyrecover();
X  yystate = *yygssp;
X  yyssp = yygssp;
X  yyvsp = yygvsp;
X  yyrq0 = yyrq;
X  yyrq1 = yyrq0;
X  yyrq2 = yyrq0;
X  goto yyresume;
X}
SHAR_EOF
if test 6474 -ne "`wc -c < 'bison.hairy'`"
then
	echo shar: error transmitting "'bison.hairy'" '(should have been 6474 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'bison.simple'" '(15842 characters)'
if test -f 'bison.simple'
then
	echo shar: will not over-write existing file "'bison.simple'"
else
sed 's/^X//' << \SHAR_EOF > 'bison.simple'
X#line 2 "bison.simple"
X
X/* Skeleton output parser for bison,
X   copyright (C) 1984 Bob Corbett and Richard Stallman
X
X		       NO WARRANTY
X
X  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
XCORRECTION.
X
X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
X
X		GENERAL PUBLIC LICENSE TO COPY
X
X  1. You may copy and distribute verbatim copies of this source file
Xas you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy a valid copyright notice "Copyright
X(C) 1985 Free Software Foundation, Inc."; and include following the
Xcopyright notice a verbatim copy of the above disclaimer of warranty
Xand of this License.  You may charge a distribution fee for the
Xphysical act of transferring a copy.
X
X  2. You may modify your copy or copies of this source file or
Xany portion of it, and copy and distribute such modifications under
Xthe terms of Paragraph 1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating
X    that you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish,
X    that in whole or in part contains or is a derivative of this
X    program or any part thereof, to be licensed at no charge to all
X    third parties on terms identical to those contained in this
X    License Agreement (except that you may choose to grant more extensive
X    warranty protection to some or all third parties, at your option).
X
X    c) You may charge a distribution fee for the physical act of
X    transferring a copy, and you may at your option offer warranty
X    protection in exchange for a fee.
X
XMere aggregation of another unrelated program with this program (or its
Xderivative) on a volume of a storage or distribution medium does not bring
Xthe other program under the scope of these terms.
X
X  3. You may copy and distribute this program (or a portion or derivative
Xof it, under Paragraph 2) in object code or executable form under the terms
Xof Paragraphs 1 and 2 above provided that you also do one of the following:
X
X    a) accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    b) accompany it with a written offer, valid for at least three
X    years, to give any third party free (except for a nominal
X    shipping charge) a complete machine-readable copy of the
X    corresponding source code, to be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    c) accompany it with the information you received as to where the
X    corresponding source code may be obtained.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form alone.)
X
XFor an executable file, complete source code means all the source code for
Xall modules it contains; but, as a special exception, it need not include
Xsource code for modules which are standard libraries that accompany the
Xoperating system on which the executable file runs.
X
X  4. You may not copy, sublicense, distribute or transfer this program
Xexcept as expressly provided under this License Agreement.  Any attempt
Xotherwise to copy, sublicense, distribute or transfer this program is void and
Xyour rights to use the program under this License agreement shall be
Xautomatically terminated.  However, parties who have received computer
Xsoftware programs from you with this License Agreement will not have
Xtheir licenses terminated so long as such parties remain in full compliance.
X
X  5. If you wish to incorporate parts of this program into other free
Xprograms whose distribution conditions are different, write to the Free
XSoftware Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
Xworked out a simple rule that can be stated here, but we will often permit
Xthis.  We will be guided by the two goals of preserving the free status of
Xall derivatives of our free software and of promoting the sharing and reuse of
Xsoftware.
X
X
XIn other words, you are welcome to use, share and improve this program.
XYou are forbidden to forbid anyone else to use, share and improve
Xwhat you give them.   Help stamp out software-hoarding!  */
X
X/* This is the parser code that is written into each bison parser
X  when the %semantic_parser declaration is not specified in the grammar.
X  It was written by Richard Stallman by simplifying the hairy parser
X  used when %semantic_parser is specified.  */
X
X/* Note: there must be only one dollar sign in this file.
X   It is replaced by the list of actions, each action
X   as one case of the switch.  */
X
X#define yyerrok		(yyerrstatus = 0)
X#define yyclearin	(yychar = YYEMPTY)
X#define YYEMPTY		-2
X#define YYEOF		0
X#define YYFAIL		goto yyerrlab;
X
X#define YYTERROR	1
X
X#ifndef YYIMPURE
X#define YYLEX		yylex()
X#endif
X
X#ifndef YYPURE
X#define YYLEX		yylex(&yylval, &yylloc)
X#endif
X
X/* If nonreentrant, generate the variables here */
X
X#ifndef YYIMPURE
X
Xint	yychar;			/*  the lookahead symbol		*/
XYYSTYPE	yylval;			/*  the semantic value of the		*/
X				/*  lookahead symbol			*/
X
XYYLTYPE yylloc;			/*  location data for the lookahead	*/
X				/*  symbol				*/
X
X#ifdef YYDEBUG
Xint yydebug = 0;		/*  nonzero means print parse trace	*/
X#endif
X
X#endif  /* YYIMPURE */
X
X
X/*  YYMAXDEPTH indicates the initial size of the parser's stacks	*/
X
X#ifndef	YYMAXDEPTH
X#define YYMAXDEPTH 200
X#endif
X
X/*  YYMAXLIMIT is the maximum size the stacks can grow to
X    (effective only if the built-in stack extension method is used).  */
X
X#ifndef YYMAXLIMIT
X#define YYMAXLIMIT 10000
X#endif
X
X
X#line 87 "bison.simple"
Xint
Xyyparse()
X{
X  register int yystate;
X  register int yyn;
X  register short *yyssp;
X  register YYSTYPE *yyvsp;
X  YYLTYPE *yylsp;
X  int yyerrstatus;	/*  number of tokens to shift before error messages enabled */
X  int yychar1;		/*  lookahead token as an internal (translated) token number */
X
X  short	yyssa[YYMAXDEPTH];	/*  the state stack			*/
X  YYSTYPE yyvsa[YYMAXDEPTH];	/*  the semantic value stack		*/
X  YYLTYPE yylsa[YYMAXDEPTH];	/*  the location stack			*/
X
X  short *yyss = yyssa;		/*  refer to the stacks thru separate pointers */
X  YYSTYPE *yyvs = yyvsa;	/*  to allow yyoverflow to reallocate them elsewhere */
X  YYLTYPE *yyls = yylsa;
X
X  int yymaxdepth = YYMAXDEPTH;
X
X#ifndef YYPURE
X
X  int yychar;
X  YYSTYPE yylval;
X  YYLTYPE yylloc;
X
X#ifdef YYDEBUG
X  extern int yydebug;
X#endif
X
X#endif
X
X
X  YYSTYPE yyval;		/*  the variable used to return		*/
X				/*  semantic values from the action	*/
X				/*  routines				*/
X
X  int yylen;
X
X#ifdef YYDEBUG
X  if (yydebug)
X    fprintf(stderr, "Starting parse\n");
X#endif
X
X  yystate = 0;
X  yyerrstatus = 0;
X  yychar = YYEMPTY;		/* Cause a token to be read.  */
X
X  /* Initialize stack pointers.
X     Waste one element of value and location stack
X     so that they stay on the same level as the state stack.  */
X
X  yyssp = yyss - 1;
X  yyvsp = yyvs;
X  yylsp = yyls;
X
X/* Push a new state, which is found in  yystate  .  */
X/* In all cases, when you get here, the value and location stacks
X   have just been pushed. so pushing a state here evens the stacks.  */
Xyynewstate:
X
X  *++yyssp = yystate;
X
X  if (yyssp >= yyss + yymaxdepth - 1)
X    {
X      /* Give user a chance to reallocate the stack */
X      /* Use copies of these so that the &'s don't force the real ones into memory. */
X      YYSTYPE *yyvs1 = yyvs;
X      YYLTYPE *yyls1 = yyls;
X      short *yyss1 = yyss;
X
X      /* Get the current used size of the three stacks, in elements.  */
X      int size = yyssp - yyss + 1;
X
X#ifdef yyoverflow
X      /* Each stack pointer address is followed by the size of
X	 the data in use in that stack, in bytes.  */
X      yyoverflow("parser stack overflow",
X		 &yyss1, size * sizeof (*yyssp),
X		 &yyvs1, size * sizeof (*yyvsp),
X		 &yyls1, size * sizeof (*yylsp),
X		 &yymaxdepth);
X
X      yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
X#else /* no yyoverflow */
X      /* Extend the stack our own way.  */
X      if (yymaxdepth >= YYMAXLIMIT)
X	yyerror("parser stack overflow");
X      yymaxdepth *= 2;
X      if (yymaxdepth > YYMAXLIMIT)
X	yymaxdepth = YYMAXLIMIT;
X      yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
X      bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
X      yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
X      bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
X      yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
X      bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
X#endif /* no yyoverflow */
X
X      yyssp = yyss + size - 1;
X      yylsp = yyls + size - 1;
X      yyvsp = yyvs + size - 1;
X
X#ifdef YYDEBUG
X      if (yydebug)
X	fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
X#endif
X
X      if (yyssp >= yyss + yymaxdepth - 1)
X	YYERROR;
X    }
X
X#ifdef YYDEBUG
X  if (yydebug)
X    fprintf(stderr, "Entering state %d\n", yystate);
X#endif
X
X/* Do appropriate processing given the current state.  */
X/* Read a lookahead token if we need one and don't already have one.  */
Xyyresume:
X
X  /* First try to decide what to do without reference to lookahead token.  */
X
X  yyn = yypact[yystate];
X  if (yyn == YYFLAG)
X    goto yydefault;
X
X  /* Not known => get a lookahead token if don't already have one.  */
X
X  /* yychar is either YYEMPTY or YYEOF
X     or a valid token in external form.  */
X
X  if (yychar == YYEMPTY)
X    {
X#ifdef YYDEBUG
X      if (yydebug)
X	fprintf(stderr, "Reading a token: ");
X#endif
X      yychar = YYLEX;
X    }
X
X  /* Convert token to internal form (in yychar1) for indexing tables with */
X
X  if (yychar <= 0)		/* This means end of input. */
X    {
X      yychar1 = 0;
X      yychar = YYEOF;		/* Don't call YYLEX any more */
X
X#ifdef YYDEBUG
X      if (yydebug)
X	fprintf(stderr, "Now at end of input.\n");
X#endif
X    }
X  else
X    {
X      yychar1 = YYTRANSLATE(yychar);
X
X#ifdef YYDEBUG
X      if (yydebug)
X	fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
X#endif
X    }
X
X  yyn += yychar1;
X  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
X    goto yydefault;
X
X  yyn = yytable[yyn];
X
X  /* yyn is what to do for this token type in this state.
X     Negative => reduce, -yyn is rule number.
X     Positive => shift, yyn is new state.
X       New state is final state => don't bother to shift,
X       just return success.
X     0, or most negative number => error.  */
X
X  if (yyn < 0)
X    {
X      if (yyn == YYFLAG)
X	goto yyerrlab;
X      yyn = -yyn;
X      goto yyreduce;
X    }
X  else if (yyn == 0)
X    goto yyerrlab;
X
X  if (yyn == YYFINAL)
X    YYACCEPT;
X
X  /* Shift the lookahead token.  */
X
X#ifdef YYDEBUG
X  if (yydebug)
X    fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
X#endif
X
X  /* Discard the token being shifted unless it is eof.  */
X  if (yychar != YYEOF)
X    yychar = YYEMPTY;
X
X  *++yyvsp = yylval;
X  *++yylsp = yylloc;
X
X  /* count tokens shifted since error; after three, turn off error status.  */
X  if (yyerrstatus) yyerrstatus--;
X
X  yystate = yyn;
X  goto yynewstate;
X
X/* Do the default action for the current state.  */
Xyydefault:
X
X  yyn = yydefact[yystate];
X  if (yyn == 0)
X    goto yyerrlab;
X
X/* Do a reduction.  yyn is the number of a rule to reduce with.  */
Xyyreduce:
X  yylen = yyr2[yyn];
X  yyval = yyvsp[1-yylen]; /* implement default value of the action */
X
X#ifdef YYDEBUG
X  if (yydebug)
X    {
X      if (yylen == 1)
X	fprintf (stderr, "Reducing 1 value via line %d, ",
X		 yyrline[yyn]);
X      else
X	fprintf (stderr, "Reducing %d values via line %d, ",
X		 yylen, yyrline[yyn]);
X    }
X#endif
X
X$   /* the action file gets copied in in place of this dollarsign */
X#line 303 "bison.simple"
X
X  yyvsp -= yylen;
X  yylsp -= yylen;
X  yyssp -= yylen;
X
X#ifdef YYDEBUG
X  if (yydebug)
X    {
X      short *ssp1 = yyss - 1;
X      fprintf (stderr, "state stack now", yyssp-yyss);
X      while (ssp1 != yyssp)
X	fprintf (stderr, " %d", *++ssp1);
X      fprintf (stderr, "\n");
X    }
X#endif
X
X  *++yyvsp = yyval;
X
X  yylsp++;
X  if (yylen == 0)
X    {
X      yylsp->first_line = yylloc.first_line;
X      yylsp->first_column = yylloc.first_column;
X      yylsp->last_line = (yylsp-1)->last_line;
X      yylsp->last_column = (yylsp-1)->last_column;
X      yylsp->text = 0;
X    }
X  else
X    {
X      yylsp->last_line = (yylsp+yylen-1)->last_line;
X      yylsp->last_column = (yylsp+yylen-1)->last_column;
X    }
X
X  /* Now "shift" the result of the reduction.
X     Determine what state that goes to,
X     based on the state we popped back to
X     and the rule number reduced by.  */
X
X  yyn = yyr1[yyn];
X
X  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
X  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
X    yystate = yytable[yystate];
X  else
X    yystate = yydefgoto[yyn - YYNTBASE];
X
X  goto yynewstate;
X
Xyyerrlab:   /* here on detecting error */
X
X  if (! yyerrstatus)
X    /* If not already recovering from an error, report this error.  */
X    {
X      yyerror("parse error");
X    }
X
X  if (yyerrstatus == 3)
X    {
X      /* if just tried and failed to reuse lookahead token after an error, discard it.  */
X
X      /* return failure if at end of input */
X      if (yychar == YYEOF)
X	YYERROR;
X
X#ifdef YYDEBUG
X      if (yydebug)
X	fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
X#endif
X
X      yychar = YYEMPTY;
X    }
X
X  /* Else will try to reuse lookahead token
X     after shifting the error token.  */
X
X  yyerrstatus = 3;		/* Each real token shifted decrements this */
X
X  goto yyerrhandle;
X
Xyyerrdefault:  /* current state does not do anything special for the error token. */
X
X#if 0
X  /* This is wrong; only states that explicitly want error tokens
X     should shift them.  */
X  yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
X  if (yyn) goto yydefault;
X#endif
X
Xyyerrpop:   /* pop the current state because it cannot handle the error token */
X
X  if (yyssp == yyss) YYERROR;
X  yyvsp--;
X  yylsp--;
X  yystate = *--yyssp;
X
X#ifdef YYDEBUG
X  if (yydebug)
X    {
X      short *ssp1 = yyss - 1;
X      fprintf (stderr, "Error: state stack now", yyssp-yyss);
X      while (ssp1 != yyssp)
X	fprintf (stderr, " %d", *++ssp1);
X      fprintf (stderr, "\n");
X    }
X#endif
X
Xyyerrhandle:
X
X  yyn = yypact[yystate];
X  if (yyn == YYFLAG)
X    goto yyerrdefault;
X
X  yyn += YYTERROR;
X  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
X    goto yyerrdefault;
X
X  yyn = yytable[yyn];
X  if (yyn < 0)
X    {
X      if (yyn == YYFLAG)
X	goto yyerrpop;
X      yyn = -yyn;
X      goto yyreduce;
X    }
X  else if (yyn == 0)
X    goto yyerrpop;
X
X  if (yyn == YYFINAL)
X    YYACCEPT;
X
X#ifdef YYDEBUG
X  if (yydebug)
X    fprintf(stderr, "Shifting error token, ");
X#endif
X
X  *++yyvsp = yylval;
X  *++yylsp = yylloc;
X
X  yystate = yyn;
X  goto yynewstate;
X}
SHAR_EOF
if test 15842 -ne "`wc -c < 'bison.simple'`"
then
	echo shar: error transmitting "'bison.simple'" '(should have been 15842 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'build.com'" '(2196 characters)'
if test -f 'build.com'
then
	echo shar: will not over-write existing file "'build.com'"
else
sed 's/^X//' << \SHAR_EOF > 'build.com'
X$!
X$! This command procedure compiles and links BISON for VMS.
X$! BISON has been tested with VAXC version 2.3 and VMS version 4.5
X$! and on VMS 4.5 with GCC 1.12.
X$!
X$! Bj|rn Larsen			blarsen@ifi.uio.no
X$! With some contributions by Gabor Karsai, 
X$!  KARSAIG1%VUENGVAX.BITNET@jade.berkeley.edu
X$! All merged and cleaned by RMS.
X$!
X$! Adapted for both VAX-11 "C" and VMS/GCC compilation by
X$! David L. Kashtan		kashtan.iu.ai.sri.com
X$!
X$! Uncomment the appropriate compilation command (CC=VAX-11 "C", GCC=VMS/GCC)
X$ cc_command:="CC"
X$! cc_command:="GCC"
X$!
X$! Note: Change the directories immediately below to whereever 
X$! you have placed bison.simple & hairy
X$!
X$ if "''cc_command'" .nes. "CC" then goto Try_GCC
X$ cc_options:="/NOLIST/define=(""index=strchr"",""rindex=strrchr"",""XPFILE=""""DISK_USE:[BISON]bison.simple"""""",""XPFILE1=""""DISK_USE:[BISON]bison.hairy"""""")"
X$ extra_linker_files:="VMSHLP,"
X$ goto Compile
X$!
X$! VMS/GCC compilation:
X$!
X$ Try_GCC:
X$ if "''cc_command'" .nes. "GCC" then goto Fail
X$ cc_options:="/DEBUG"
X$ extra_linker_files:="GNU_CC:[000000]GCCLIB/LIB,"
X$ goto Compile
X$!
X$! Unknown compiler type
X$!
X$ Fail:
X$ write sys$output "Unknown compiler type: ''cc_command'"
X$ exit
X$!
X$!	Do the compilation (compiler type is all set up)
X$!
X$ Compile:
X$ if "''p1'" .eqs. "LINK" then goto Link
X$ 'cc_command' 'cc_options' files.c
X$ 'cc_command' 'cc_options' LR0.C
X$ 'cc_command' 'cc_options' ALLOCATE.C
X$ 'cc_command' 'cc_options' CLOSURE.C
X$ 'cc_command' 'cc_options' CONFLICTS.C
X$ 'cc_command' 'cc_options' DERIVES.C
X$ 'cc_command' 'cc_options' VMSGETARGS.C
X$ 'cc_command' 'cc_options' GRAM.C
X$ 'cc_command' 'cc_options' LALR.C
X$ 'cc_command' 'cc_options' LEX.C
X$ 'cc_command' 'cc_options' MAIN.C
X$ 'cc_command' 'cc_options' NULLABLE.C
X$ 'cc_command' 'cc_options' OUTPUT.C
X$ 'cc_command' 'cc_options' PRINT.C
X$ 'cc_command' 'cc_options' READER.C
X$ 'cc_command' 'cc_options' SYMTAB.C
X$ 'cc_command' 'cc_options' WARSHALL.C
X$ if "''cc_command'" .eqs. "CC" then macro vmshlp.mar
X$ Link:
X$ link/exec=bison main,LR0,allocate,closure,conflicts,derives,files,-
Xvmsgetargs,gram,lalr,lex,nullable,output,print,reader,symtab,warshall,-
X'extra_linker_files'sys$library:vaxcrtl/lib
SHAR_EOF
if test 2196 -ne "`wc -c < 'build.com'`"
then
	echo shar: error transmitting "'build.com'" '(should have been 2196 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'vmshlp.mar'" '(1524 characters)'
if test -f 'vmshlp.mar'
then
	echo shar: will not over-write existing file "'vmshlp.mar'"
else
sed 's/^X//' << \SHAR_EOF > 'vmshlp.mar'
X;/* Macro help routines for the BISON/VMS program
X;   Gabor Karsai, Vanderbilt University
X;
X;BISON is distributed in the hope that it will be useful, but WITHOUT ANY
X;WARRANTY.  No author or distributor accepts responsibility to anyone
X;for the consequences of using it or for whether it serves any
X;particular purpose or works at all, unless he says so in writing.
X;Refer to the BISON General Public License for full details.
X;
X;Everyone is granted permission to copy, modify and redistribute BISON,
X;but only under the conditions described in the BISON General Public
X;License.  A copy of this license is supposed to have been given to you
X;along with BISON so you can know your rights and responsibilities.  It
X;should be in a file named COPYING.  Among other things, the copyright
X;notice and this notice must be preserved on all copies.
X;
X; In other words, you are welcome to use, share and improve this program.
X; You are forbidden to forbid anyone else to use, share and improve
X; what you give them.   Help stamp out software-hoarding!  */
X;
X        .psect  vmshlp  pic,usr,rel,ovr,shr,long,exe,nowrt
X
Xalloca::
X        .word   0
X        subl2   ^X4(ap),sp
X        movl    ^X10(fp),r1
X        movq    ^X8(fp),ap
X        bicl2   #03,sp
X        addl2   #^X1c,sp
X        movl    sp,r0
X        jmp     (r1)
X
Xbcopy::
X        .word   ^X0e00
X        movl    ^X04(ap),r11
X        movl    ^X08(ap),r10
X        movl    ^X0c(ap),r9
X        brb     1$
X2$:     movb    (r10)+,(r11)+
X1$:     sobgeq  r9,2$
X        ret
X        .end
SHAR_EOF
if test 1524 -ne "`wc -c < 'vmshlp.mar'`"
then
	echo shar: error transmitting "'vmshlp.mar'" '(should have been 1524 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
--- end of part 1 ---

wetter@tybalt.caltech.edu (Pierce T. Wetter) (05/15/88)

[Bison Macintosh Sources - part 2 of 6]

---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	Bison/allocate.c
#	Bison/closure.c
#	Bison/conflicts.c
#	Bison/derives.c
#	Bison/files.c
#	Bison/getargs.c
# This archive created: Sat May 14 02:41:46 1988
# By:	Roger L. Long (bytebug@dhw68k.cts.com)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'allocate.c'" '(1332 characters)'
if test -f 'allocate.c'
then
	echo shar: will not over-write existing file "'allocate.c'"
else
sed 's/^X//' << \SHAR_EOF > 'allocate.c'
X/* Allocate and clear storage for bison,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#include <stdio.h>
X
X#define __SEG__ files
X
Xchar *
Xallocate(n)
Xregister unsigned n;
X{
X  register char *block;
X
X  extern char *calloc();
X
X  block = calloc(n,1);
X  if (block == NULL)
X    {
X      fprintf(stderr, "bison: memory exhausted\n");
X      done(1);
X    }
X
X  return (block);
X}
SHAR_EOF
if test 1332 -ne "`wc -c < 'allocate.c'`"
then
	echo shar: error transmitting "'allocate.c'" '(should have been 1332 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'closure.c'" '(7374 characters)'
if test -f 'closure.c'
then
	echo shar: will not over-write existing file "'closure.c'"
else
sed 's/^X//' << \SHAR_EOF > 'closure.c'
X/* Subroutines for bison
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* subroutines of file LR0.c.
X
XEntry points:
X
X  closure (items, n)
X
XGiven a vector of item numbers items, of length n,
Xset up ruleset and itemset to indicate what rules could be run
Xand which items could be accepted when those items are the active ones.
X
Xruleset contains a bit for each rule.  closure sets the bits
Xfor all rules which could potentially describe the next input to be read.
X
Xitemset is a vector of item numbers; itemsetend points to just beyond the end
X of the part of it that is significant.
Xclosure places there the indices of all items which represent units of
Xinput that could arrive next.
X
X  initialize_closure (n)
X
XAllocates the itemset and ruleset vectors,
Xand precomputes useful data so that closure can be called.
Xn is the number of elements to allocate for itemset.
X
X  finalize_closure ()
X
XFrees itemset, ruleset and internal data.
X
X*/
X
X#include <stdio.h>
X#include "machine.h"
X#include "new.h"
X#include "gram.h"
X
X
Xextern short **derives;
X
X
Xshort *itemset;
Xshort *itemsetend;
Xstatic unsigned *ruleset;
X
X/* internal data.  See comments before set_fderives and set_firsts.  */
Xstatic unsigned *fderives;
Xstatic unsigned *firsts;
X
X/* number of words required to hold a bit for each rule */
Xstatic int rulesetsize;
X
X/* number of words required to hold a bit for each variable */
Xstatic int varsetsize;
X
X
X
Xinitialize_closure(n)
Xint n;
X{
X  itemset = NEW2(n, short);
X
X  rulesetsize = WORDSIZE(nrules + 1);
X  ruleset = NEW2(rulesetsize, unsigned);
X
X  set_fderives();
X}
X
X
X
X/* set fderives to an nvars by nrules matrix of bits
X   indicating which rules can help derive the beginning of the data
X   for each nonterminal.  For example, if symbol 5 can be derived as
X   the sequence of symbols 8 3 20, and one of the rules for deriving
X   symbol 8 is rule 4, then the [5 - ntokens, 4] bit in fderives is set.  */
X
Xset_fderives()
X{
X  register unsigned *rrow;
X  register unsigned *vrow;
X  register int j;
X  register unsigned mask;
X  register unsigned cword;
X  register short *rp;
X
X  int ruleno;
X  int i;
X
X  fderives = NEW2(nvars * rulesetsize, unsigned) - ntokens * rulesetsize;
X
X  set_firsts();
X
X  rrow = fderives + ntokens * rulesetsize;
X
X  for (i = ntokens; i < nsyms; i++)
X    {
X      vrow = firsts + ((i - ntokens) * varsetsize);
X      cword = *vrow++;
X      mask = 1;
X      for (j = ntokens; j < nsyms; j++)
X	{
X	  if (cword & mask)
X	    {
X	      rp = derives[j];
X	      while ((ruleno = *rp++) > 0)
X		{
X		  SETBIT(rrow, ruleno);
X		}
X	    }
X
X	  mask <<= 1;
X	  if (mask == 0 && j + 1 < nsyms)
X	    {
X	      cword = *vrow++;
X	      mask = 1;
X	    }
X	}
X
X      vrow += varsetsize;
X      rrow += rulesetsize;
X    }
X
X#ifdef	DEBUG
X  print_fderives();
X#endif
X
X  FREE(firsts);
X}
X
X
X
X/* set firsts to be an nvars by nvars bit matrix indicating which items
X   can represent the beginning of the input corresponding to which other items.
X   For example, if some rule expands symbol 5 into the sequence of symbols 8 3 20,
X   the symbol 8 can be the beginning of the data for symbol 5,
X   so the bit [8 - ntokens, 5 - ntokens] in firsts is set. */
X
Xset_firsts()
X{
X  register unsigned *row;
X/*   register int done; JF unused */
X  register int symbol;
X  register short *sp;
X  register int rowsize;
X
X  int i;
X
X  varsetsize = rowsize = WORDSIZE(nvars);
X
X  firsts = NEW2(nvars * rowsize, unsigned);
X
X  row = firsts;
X  for (i = ntokens; i < nsyms; i++)
X    {
X      sp = derives[i];
X      while (*sp >= 0)
X	{
X	  symbol = ritem[rrhs[*sp++]];
X	  if (ISVAR(symbol))
X	    {
X	      symbol -= ntokens;
X	      SETBIT(row, symbol);
X	    }
X	}
X
X      row += rowsize;
X    }
X
X  RTC(firsts, nvars);
X
X#ifdef	DEBUG
X  print_firsts();
X#endif
X}
X
X
X
Xclosure(core, n)
Xshort *core;
Xint n;
X{
X  register int ruleno;
X  register unsigned word;
X  register unsigned mask;
X  register short *csp;
X  register unsigned *dsp;
X  register unsigned *rsp;
X
X  short *csend;
X  unsigned *rsend;
X  int symbol;
X  int itemno;
X
X  rsp = ruleset;
X  rsend = ruleset + rulesetsize;
X  csend = core + n;
X
X  if (n == 0)
X    {
X      dsp = fderives + start_symbol * rulesetsize;
X      while (rsp < rsend)
X	*rsp++ = *dsp++;
X    }
X  else
X    {
X      while (rsp < rsend)
X	*rsp++ = 0;
X
X      csp = core;
X      while (csp < csend)
X	{
X	  symbol = ritem[*csp++];
X	  if (ISVAR(symbol))
X	    {
X	      dsp = fderives + symbol * rulesetsize;
X	      rsp = ruleset;
X	      while (rsp < rsend)
X		*rsp++ |= *dsp++;
X	    }
X	}
X    }
X
X  ruleno = 0;
X  itemsetend = itemset;
X  csp = core;
X  rsp = ruleset;
X  while (rsp < rsend)
X    {
X      word = *rsp++;
X      if (word == 0)
X	{
X	  ruleno += BITS_PER_WORD;
X	}
X      else
X	{
X	  mask = 1;
X	  while (mask)
X	    {
X	      if (word & mask)
X		{
X		  itemno = rrhs[ruleno];
X		  while (csp < csend && *csp < itemno)
X		    *itemsetend++ = *csp++;
X		  *itemsetend++ = itemno;
X		}
X
X	      mask <<= 1;
X	      ruleno++;
X	    }
X	}
X    }
X
X  while (csp < csend)
X    *itemsetend++ = *csp++;
X
X#ifdef	DEBUG
X  print_closure(n);
X#endif
X}
X
X
X
Xfinalize_closure()
X{
X  FREE(itemset);
X  FREE(ruleset);
X  FREE(fderives + ntokens * rulesetsize);
X}
X
X
X
X#ifdef	DEBUG
X
Xprint_closure(n)
Xint n;
X{
X  register short *isp;
X
X  printf("\n\nn = %d\n\n", n);
X  for (isp = itemset; isp < itemsetend; isp++)
X    printf("   %d\n", *isp);
X}
X
X
X
Xprint_firsts()
X{
X  register int i;
X  register int j;
X  register unsigned *rowp;
X  register unsigned cword;
X  register unsigned mask;
X
X  extern char **tags;
X
X  printf("\n\n\nFIRSTS\n\n");
X
X  for (i = ntokens; i < nsyms; i++)
X    {
X      printf("\n\n%s firsts\n\n", tags[i]);
X
X      rowp = firsts + ((i - ntokens) * vrowsize);
X
X      cword = *rowp++;
X      mask = 1;
X      for (j = 0; j < nsyms; j++)
X	{
X	  if (cword & mask)
X	    printf("   %s\n", tags[j + ntokens]);
X
X	  mask <<= 1;
X
X	  if (mask == 0 && j + 1 < nsyms)
X	    {
X	      cword = *rowp++;
X	      mask = 1;
X	    }
X	}
X    }
X}
X
X
X
Xprint_fderives()
X{
X  register int i;
X  register int j;
X  register unsigned *rp;
X  register unsigned cword;
X  register unsigned mask;
X
X  extern char **tags;
X
X  printf("\n\n\nFDERIVES\n");
X
X  for (i = ntokens; i < nsyms; i++)
X    {
X      printf("\n\n%s derives\n\n", tags[i]);
X      rp = fderives + i * rrowsize;
X      cword = *rp++;
X      mask = 1;
X      for (j = 0; j <= nrules; j++)
X        {
X	  if (cword & mask)
X	    printf("   %d\n", j);
X
X	  mask <<= 1;
X	  if (mask == 0 && j + 1 < nrules)
X	    {
X	      cword = *rp++;
X	      mask = 1;
X	    }
X	}
X    }
X
X  fflush(stdout);
X}
X
X#endif
SHAR_EOF
if test 7374 -ne "`wc -c < 'closure.c'`"
then
	echo shar: error transmitting "'closure.c'" '(should have been 7374 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'conflicts.c'" '(14583 characters)'
if test -f 'conflicts.c'
then
	echo shar: will not over-write existing file "'conflicts.c'"
else
sed 's/^X//' << \SHAR_EOF > 'conflicts.c'
X/* Find and resolve or report look-ahead conflicts for bison,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#include <stdio.h>
X#include "machine.h"
X#include "new.h"
X#include "file.h"
X#include "gram.h"
X#include "state.h"
X
X
Xextern char **tags;
Xextern int tokensetsize;
Xextern char *consistent;
Xextern short *accessing_symbol;
Xextern shifts **shift_table;
Xextern unsigned *LA;
Xextern short *LAruleno;
Xextern short *lookaheads;
Xextern int verboseflag;
X
Xchar any_conflicts;
Xchar *conflicts;
Xerrs **err_table;
Xint expected_conflicts;
X
X
Xstatic unsigned *shiftset;
Xstatic unsigned *lookaheadset;
Xstatic int src_total;
Xstatic int rrc_total;
Xstatic int src_count;
Xstatic int rrc_count;
X
X
X
Xinitialize_conflicts()
X{
X  register int i;
X/*  register errs *sp; JF unused */
X
X  conflicts = NEW2(nstates, char);
X  shiftset = NEW2(tokensetsize, unsigned);
X  lookaheadset = NEW2(tokensetsize, unsigned);
X
X  err_table = NEW2(nstates, errs *);
X
X  any_conflicts = 0;
X
X  for (i = 0; i < nstates; i++)
X    set_conflicts(i);
X}
X
X
X
Xset_conflicts(state)
Xint state;
X{
X  register int i;
X  register int k;
X  register shifts *shiftp;
X  register unsigned *fp2;
X  register unsigned *fp3;
X  register unsigned *fp4;
X  register unsigned *fp1;
X  register int symbol;
X
X  if (consistent[state]) return;
X
X  for (i = 0; i < tokensetsize; i++)
X    lookaheadset[i] = 0;
X
X  shiftp = shift_table[state];
X  if (shiftp)
X    {
X      k = shiftp->nshifts;
X      for (i = 0; i < k; i++)
X	{
X	  symbol = accessing_symbol[shiftp->shifts[i]];
X	  if (ISVAR(symbol)) break;
X	  SETBIT(lookaheadset, symbol);
X	}
X    }
X
X  k = lookaheads[state + 1];
X  fp4 = lookaheadset + tokensetsize;
X
X  /* loop over all rules which require lookahead in this state */
X  /* first check for shift-reduce conflict, and try to resolve using precedence  */
X
X  for (i = lookaheads[state]; i < k; i++)
X    if (rprec[LAruleno[i]])
X      {
X	fp1 = LA + i * tokensetsize;
X	fp2 = fp1;
X	fp3 = lookaheadset;
X  
X	while (fp3 < fp4)
X	  {
X	    if (*fp2++ & *fp3++)
X	      {
X		resolve_sr_conflict(state, i);
X		break;
X	      }
X	  }
X      }
X
X  /* loop over all rules which require lookahead in this state */
X  /* Check for conflicts not resolved above.  */
X
X  for (i = lookaheads[state]; i < k; i++)
X    {
X      fp1 = LA + i * tokensetsize;
X      fp2 = fp1;
X      fp3 = lookaheadset;
X
X      while (fp3 < fp4)
X	{
X	  if (*fp2++ & *fp3++)
X	    {
X	      conflicts[state] = 1;
X	      any_conflicts = 1;
X	    }
X	}
X
X      fp2 = fp1;
X      fp3 = lookaheadset;
X
X      while (fp3 < fp4)
X	*fp3++ |= *fp2++;
X    }
X}
X
X
X
X/* Attempt to resolve shift-reduce conflict for one rule
Xby means of precedence declarations.
XIt has already been checked that the rule has a precedence.
XA conflict is resolved by modifying the shift or reduce tables
Xso that there is no longer a conflict.  */
X
Xresolve_sr_conflict(state, lookaheadnum)
Xint state;
Xint lookaheadnum;
X{
X  register int i;
X  register int mask;
X  register unsigned *fp1;
X  register unsigned *fp2;
X  register int redprec;
X  errs *errp = (errs *) malloc (sizeof(errs) + ntokens * sizeof(short));
X  short *errtokens = errp->errs;
X
X  /* find the rule to reduce by to get precedence of reduction  */
X  redprec = rprec[LAruleno[lookaheadnum]];
X
X  mask = 1;
X  fp1 = LA + lookaheadnum * tokensetsize;
X  fp2 = lookaheadset;
X  for (i = 0; i < ntokens; i++)
X    {
X      if ((mask & *fp2 & *fp1) && sprec[i])
X	/* shift-reduce conflict occurs for token number i and it has a precision.
X	   The precedence of shifting is that of token i.  */
X	{
X	  if (sprec[i] < redprec)
X	    {
X	      if (verboseflag) log_resolution(state, lookaheadnum, i, "reduce");
X	      *fp2 &= ~mask;  /* flush the shift for this token */
X	      flush_shift(state, i);
X	    }
X	  else if (sprec[i] > redprec)
X	    {
X	      if (verboseflag) log_resolution(state, lookaheadnum, i, "shift");
X	      *fp1 &= ~mask;  /* flush the reduce for this token */
X	    }
X	  else
X	    {
X	      /* Matching precedence levels.
X		 For left association, keep only the reduction.
X		 For right association, keep only the shift.
X		 For nonassociation, keep neither.  */
X
X	      switch (sassoc[i])
X		{
X
X		case RIGHT_ASSOC:
X	          if (verboseflag) log_resolution(state, lookaheadnum, i, "shift");
X		  break;
X
X		case LEFT_ASSOC:
X	          if (verboseflag) log_resolution(state, lookaheadnum, i, "reduce");
X		  break;
X
X		case NON_ASSOC:
X	          if (verboseflag) log_resolution(state, lookaheadnum, i, "an error");
X		  break;
X		}
X
X	      if (sassoc[i] != RIGHT_ASSOC)
X		{
X		  *fp2 &= ~mask;  /* flush the shift for this token */
X		  flush_shift(state, i);
X		}
X	      if (sassoc[i] != LEFT_ASSOC)
X	        {
X		  *fp1 &= ~mask;  /* flush the reduce for this token */
X		}
X	      if (sassoc[i] == NON_ASSOC)
X		{
X		  /* Record an explicit error for this token.  */
X		  *errtokens++ = i;
X		}
X	    }
X	}
X
X      mask <<= 1;
X      if (mask == 0)
X	{
X	  mask = 1;
X	  fp2++;  fp1++;
X	}
X    }
X  errp->nerrs = errtokens - errp->errs;
X  if (errp->nerrs)
X    {
X      /* Some tokens have been explicitly made errors.  Allocate
X	 a permanent errs structure for this state, to record them.  */
X      i = (char *) errtokens - (char *) errp;
X      err_table[state] = (errs *) allocate ((unsigned int)i);
X      memcpy(errp, err_table[state], i);
X    }
X  else
X    err_table[state] = 0;
X  free(errp);
X}
X
X
X
X/* turn off the shift recorded for the specified token in the specified state.
XUsed when we resolve a shift-reduce conflict in favor of the reduction.  */
X
Xflush_shift(state, token)
Xint state;
Xint token;
X{
X  register shifts *shiftp;
X  register int k, i;
X/*  register unsigned symbol; JF unused */
X
X  shiftp = shift_table[state];
X
X  if (shiftp)
X    {
X      k = shiftp->nshifts;
X      for (i = 0; i < k; i++)
X	{
X	  if (shiftp->shifts[i] && token == accessing_symbol[shiftp->shifts[i]])
X	    (shiftp->shifts[i]) = 0;
X	}
X    }
X}
X
X
X
Xlog_resolution(state, LAno, token, resolution)
Xint state, LAno, token;
Xchar *resolution;
X{
X  fprintf(foutput,
X	  "Conflict in state %d between rule %d and token %s resolved as %s.\n",
X	  state, LAruleno[LAno], tags[token], resolution);
X}
X
X
X
Xconflict_log()
X{
X  register int i;
X
X  src_total = 0;
X  rrc_total = 0;
X
X  for (i = 0; i < nstates; i++)
X    {
X      if (conflicts[i])
X	{
X	  count_sr_conflicts(i);
X	  count_rr_conflicts(i);
X	  src_total += src_count;
X	  rrc_total += rrc_count;
X	}
X    }
X
X  total_conflicts();
X}
X  
X
X
Xverbose_conflict_log()
X{
X  register int i;
X
X  src_total = 0;
X  rrc_total = 0;
X
X  for (i = 0; i < nstates; i++)
X    {
X      if (conflicts[i])
X	{
X	  count_sr_conflicts(i);
X	  count_rr_conflicts(i);
X	  src_total += src_count;
X	  rrc_total += rrc_count;
X
X	  fprintf(foutput, "State %d contains", i);
X
X	  if (src_count == 1)
X	    fprintf(foutput, " 1 shift/reduce conflict");
X	  else if (src_count > 1)
X	    fprintf(foutput, " %d shift/reduce conflicts", src_count);
X
X	  if (src_count > 0 && rrc_count > 0)
X	    fprintf(foutput, " and");
X
X	  if (rrc_count == 1)
X	    fprintf(foutput, " 1 reduce/reduce conflict");
X	  else if (rrc_count > 1)
X	    fprintf(foutput, " %d reduce/reduce conflicts", rrc_count);
X
X	  putc('.', foutput);
X	  putc('\n', foutput);
X	}
X    }
X
X  total_conflicts();
X}
X
X
X
Xtotal_conflicts()
X{
X  if (src_total == expected_conflicts && rrc_total == 0)
X    return;
X
X  fprintf(stderr, "%s contains", infile);
X
X  if (src_total == 1)
X    fprintf(stderr, " 1 shift/reduce conflict");
X  else if (src_total > 1)
X    fprintf(stderr, " %d shift/reduce conflicts", src_total);
X
X  if (src_total > 0 && rrc_total > 0)
X    fprintf(stderr, " and");
X
X  if (rrc_total == 1)
X    fprintf(stderr, " 1 reduce/reduce conflict");
X  else if (rrc_total > 1)
X    fprintf(stderr, " %d reduce/reduce conflicts", rrc_total);
X
X  putc('.', stderr);
X  putc('\n', stderr);
X}
X
X
X
Xcount_sr_conflicts(state)
Xint state;
X{
X  register int i;
X  register int k;
X  register int mask;
X  register shifts *shiftp;
X  register unsigned *fp1;
X  register unsigned *fp2;
X  register unsigned *fp3;
X  register int symbol;
X
X  src_count = 0;
X
X  shiftp = shift_table[state];
X  if (!shiftp) return;
X
X  for (i = 0; i < tokensetsize; i++)
X    {
X      shiftset[i] = 0;
X      lookaheadset[i] = 0;
X    }
X
X  k = shiftp->nshifts;
X  for (i = 0; i < k; i++)
X    {
X      if (! shiftp->shifts[i]) continue;
X      symbol = accessing_symbol[shiftp->shifts[i]];
X      if (ISVAR(symbol)) break;
X      SETBIT(shiftset, symbol);
X    }
X
X  k = lookaheads[state + 1];
X  fp3 = lookaheadset + tokensetsize;
X
X  for (i = lookaheads[state]; i < k; i++)
X    {
X      fp1 = LA + i * tokensetsize;
X      fp2 = lookaheadset;
X
X      while (fp2 < fp3)
X	*fp2++ |= *fp1++;
X    }
X
X  fp1 = shiftset;
X  fp2 = lookaheadset;
X
X  while (fp2 < fp3)
X    *fp2++ &= *fp1++;
X
X  mask = 1;
X  fp2 = lookaheadset;
X  for (i = 0; i < ntokens; i++)
X    {
X      if (mask & *fp2)
X	src_count++;
X
X      mask <<= 1;
X      if (mask == 0)
X	{
X	  mask = 1;
X	  fp2++;
X	}
X    }
X}
X
X
X
Xcount_rr_conflicts(state)
Xint state;
X{
X  register int i;
X  register int j;
X  register int count;
X  register unsigned mask;
X  register unsigned *baseword;
X  register unsigned *wordp;
X  register int m;
X  register int n;
X
X  rrc_count = 0;
X
X  m = lookaheads[state];
X  n = lookaheads[state + 1];
X
X  if (n - m < 2) return;
X
X  mask = 1;
X  baseword = LA + m * tokensetsize;
X  for (i = 0; i < ntokens; i++)
X    {
X      wordp = baseword;
X
X      count = 0;
X      for (j = m; j < n; j++)
X	{
X	  if (mask & *wordp)
X	    count++;
X
X	  wordp += tokensetsize;
X	}
X
X      if (count >= 2) rrc_count++;
X
X      mask <<= 1;
X      if (mask == 0)
X	{
X	  mask = 1;
X	  baseword++;
X	}
X    }
X}
X
X
X
Xprint_reductions(state)
Xint state;
X{
X  register int i;
X  register int j;
X  register int k;
X  register unsigned *fp1;
X  register unsigned *fp2;
X  register unsigned *fp3;
X  register unsigned *fp4;
X  register int rule;
X  register int symbol;
X  register unsigned mask;
X  register int m;
X  register int n;
X  register int default_LA;
X  register int default_rule;
X  register int cmax;
X  register int count;
X  register shifts *shiftp;
X  register errs *errp;
X  int nodefault = 0;
X
X  for (i = 0; i < tokensetsize; i++)
X    shiftset[i] = 0;
X
X  shiftp = shift_table[state];
X  if (shiftp)
X    {
X      k = shiftp->nshifts;
X      for (i = 0; i < k; i++)
X	{
X	  if (! shiftp->shifts[i]) continue;
X	  symbol = accessing_symbol[shiftp->shifts[i]];
X	  if (ISVAR(symbol)) break;
X	  /* if this state has a shift for the error token,
X	     don't use a default rule.  */
X	  if (symbol == error_token_number) nodefault = 1;
X	  SETBIT(shiftset, symbol);
X	}
X    }
X
X  errp = err_table[state];
X  if (errp)
X    {
X      k = errp->nerrs;
X      for (i = 0; i < k; i++)
X	{
X	  if (! errp->errs[i]) continue;
X	  symbol = errp->errs[i];
X	  SETBIT(shiftset, symbol);
X	}
X    }
X
X  m = lookaheads[state];
X  n = lookaheads[state + 1];
X
X  if (n - m == 1 && ! nodefault)
X    {
X      default_rule = LAruleno[m];
X
X      fp1 = LA + m * tokensetsize;
X      fp2 = shiftset;
X      fp3 = lookaheadset;
X      fp4 = lookaheadset + tokensetsize;
X
X      while (fp3 < fp4)
X	*fp3++ = *fp1++ & *fp2++;
X
X      mask = 1;
X      fp3 = lookaheadset;
X
X      for (i = 0; i < ntokens; i++)
X	{
X	  if (mask & *fp3)
X	    fprintf(foutput, "    %-4s\t[reduce  %d  (%s)]\n",
X		    tags[i], default_rule, tags[rlhs[default_rule]]);
X
X	  mask <<= 1;
X	  if (mask == 0)
X	    {
X	      mask = 1;
X	      fp3++;
X	    }
X	}
X
X      fprintf(foutput, "    $default\treduce  %d  (%s)\n\n",
X	      default_rule, tags[rlhs[default_rule]]);
X    }
X  else if (n - m >= 1)
X    {
X      cmax = 0;
X      default_LA = -1;
X      fp4 = lookaheadset + tokensetsize;
X
X      if (! nodefault)
X	for (i = m; i < n; i++)
X	  {
X	    fp1 = LA + i * tokensetsize;
X	    fp2 = shiftset;
X	    fp3 = lookaheadset;
X  
X	    while (fp3 < fp4)
X	      *fp3++ = *fp1++ & ( ~ (*fp2++));
X  
X	    count = 0;
X	    mask = 1;
X	    fp3 = lookaheadset;
X	    for (j = 0; j < ntokens; j++)
X	      {
X		if (mask & *fp3)
X		  count++;
X  
X		mask <<= 1;
X		if (mask == 0)
X		  {
X		    mask = 1;
X		    fp3++;
X		  }
X	      }
X  
X	    if (count > cmax)
X	      {
X		cmax = count;
X		default_LA = i;
X		default_rule = LAruleno[i];
X	      }
X  
X	    fp2 = shiftset;
X	    fp3 = lookaheadset;
X  
X	    while (fp3 < fp4)
X	      *fp2++ |= *fp3++;
X	  }
X
X      for (i = 0; i < tokensetsize; i++)
X        shiftset[i] = 0;
X
X      if (shiftp)
X        {
X          k = shiftp->nshifts;
X          for (i = 0; i < k; i++)
X	    {
X	      if (! shiftp->shifts[i]) continue;
X	      symbol = accessing_symbol[shiftp->shifts[i]];
X	      if (ISVAR(symbol)) break;
X	      SETBIT(shiftset, symbol);
X	    }
X        }
X
X      mask = 1;
X      fp1 = LA + m * tokensetsize;
X      fp2 = shiftset;
X      for (i = 0; i < ntokens; i++)
X	{
X	  int defaulted = 0;
X
X	  if (mask & *fp2)
X	    count = 1;
X	  else
X	    count = 0;
X
X	  fp3 = fp1;
X	  for (j = m; j < n; j++)
X	    {
X	      if (mask & *fp3)
X		{
X		  if (count == 0)
X		    {
X		      if (j != default_LA)
X			{
X			  rule = LAruleno[j];
X			  fprintf(foutput, "    %-4s\treduce  %d  (%s)\n",
X				  tags[i], rule, tags[rlhs[rule]]);
X			}
X		      else defaulted = 1;
X
X		      count++;
X		    }
X		  else
X		    {
X		      if (defaulted)
X			{
X			  rule = LAruleno[default_LA];
X			  fprintf(foutput, "    %-4s\treduce  %d  (%s)\n",
X				  tags[i], rule, tags[rlhs[rule]]);
X			  defaulted = 0;
X			}
X		      rule = LAruleno[j];
X		      fprintf(foutput, "    %-4s\t[reduce  %d  (%s)]\n",
X			      tags[i], rule, tags[rlhs[rule]]);
X		    }
X		}
X
X	      fp3 += tokensetsize;
X	    }
X
X	  mask <<= 1;
X	  if (mask == 0)
X	    {
X	      mask = 1;
X	      fp1++;
X	    }
X	}
X
X      if (default_LA >= 0)
X	{
X	  fprintf(foutput, "    $default\treduce  %d  (%s)\n",
X		  default_rule, tags[rlhs[default_rule]]);
X	}
X
X      putc('\n', foutput);
X    }
X}
X
X
X
Xfinalize_conflicts()
X{
X  FREE(conflicts);
X  FREE(shiftset);
X  FREE(lookaheadset);
X}
SHAR_EOF
if test 14583 -ne "`wc -c < 'conflicts.c'`"
then
	echo shar: error transmitting "'conflicts.c'" '(should have been 14583 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'derives.c'" '(2488 characters)'
if test -f 'derives.c'
then
	echo shar: will not over-write existing file "'derives.c'"
else
sed 's/^X//' << \SHAR_EOF > 'derives.c'
X/* Match rules with nonterminals for bison,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* set_derives finds, for each variable (nonterminal), which rules can derive it.
X   It sets up the value of derives so that
X   derives[i - ntokens] points to a vector of rule numbers, terminated with a zero.  */
X
X#include <stdio.h>
X#include "new.h"
X#include "types.h"
X#include "gram.h"
X
X
Xshort **derives;
X
X
Xset_derives()
X{
X  register int i;
X  register int lhs;
X  register shorts *p;
X  register short *q;
X  register shorts **dset;
X  register shorts *delts;
X
X  dset = NEW2(nvars, shorts *) - ntokens;
X  delts = NEW2(nrules + 1, shorts);
X
X  p = delts;
X  for (i = nrules; i > 0; i--)
X    {
X      lhs = rlhs[i];
X      p->next = dset[lhs];
X      p->value = i;
X      dset[lhs] = p;
X      p++;
X    }
X
X  derives = NEW2(nvars, short *) - ntokens;
X  q = NEW2(nvars + nrules, short);
X
X  for (i = ntokens; i < nsyms; i++)
X    {
X      derives[i] = q;
X      p = dset[i];
X      while (p)
X	{
X	  *q++ = p->value;
X	  p = p->next;
X	}
X      *q++ = -1;
X    }
X
X#ifdef	DEBUG
X  print_derives();
X#endif
X
X  FREE(dset + ntokens);
X  FREE(delts);
X}
X
X
Xfree_derives()
X{
X  FREE(derives[ntokens]);
X  FREE(derives + ntokens);
X}
X
X
X
X#ifdef	DEBUG
X
Xprint_derives()
X{
X  register int i;
X  register short *sp;
X
X  extern char **tags;
X
X  printf("\n\n\nDERIVES\n\n");
X
X  for (i = ntokens; i < nsyms; i++)
X    {
X      printf("%s derives", tags[i]);
X      for (sp = derives[i]; *sp > 0; sp++)
X	{
X	  printf("  %d", *sp);
X	}
X      putchar('\n');
X    }
X
X  putchar('\n');
X}
X
X#endif
X
SHAR_EOF
if test 2488 -ne "`wc -c < 'derives.c'`"
then
	echo shar: error transmitting "'derives.c'" '(should have been 2488 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'files.c'" '(7386 characters)'
if test -f 'files.c'
then
	echo shar: will not over-write existing file "'files.c'"
else
sed 's/^X//' << \SHAR_EOF > 'files.c'
X/* Open and close files for bison,
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#define __SEG__ files
X
X#ifdef VMS
X#include <ssdef.h>
X#define unlink delete
X#define XPFILE "GNU_BISON:[000000]BISON.SIMPLE"
X#define XPFILE1 "GNU_BISON:[000000]BISON.HAIRY"
X#endif
X
X#include <stdio.h>
X#include "file.h"
X#include "new.h"
X#include "gram.h"
X#include "Events.h"
X#include "Files.h" /* get mac file stuff as opposed to Bison file stuff*/
X
XFILE *finput = NULL;
XFILE *foutput = NULL;
XFILE *fdefines = NULL;
XFILE *ftable = NULL;
XFILE *fattrs = NULL;
XFILE *fguard = NULL;
XFILE *faction = NULL;
XFILE *fparser = NULL;
X
X/* File name specified with -o for the output file, or 0 if no -o.  */
Xchar *spec_outfile;
X
Xchar *infile;
Xchar *outfile;
Xchar *defsfile;
Xchar *tabfile;
Xchar *attrsfile;
Xchar *guardfile;
Xchar *actfile;
Xchar *tmpattrsfile;
Xchar *tmptabfile;
X
XFILE	*tryopen();	/* This might be a good idea */
X
Xextern int verboseflag;
Xextern int definesflag;
Xint fixed_outfiles = 0;
X
X
Xchar*
Xstringappend(string1, end1, string2)
Xchar *string1;
Xint end1;
Xchar *string2;
X{
X  register char *ostring;
X  register char *cp, *cp1;
X  register int i;
X
X  cp = string2;  i = 0;
X  while (*cp++) i++;
X
X  ostring = NEW2(i+end1+1, char);
X
X  cp = ostring;
X  cp1 = string1;
X  for (i = 0; i < end1; i++)
X    *cp++ = *cp1++;
X
X  cp1 = string2;
X  while (*cp++ = *cp1++) ;
X
X  return ostring;
X}
X
X
X/* JF this has been hacked to death.  Nowaday it sets up the file names for
X   the output files, and opens the tmp files and the parser */
Xopenfiles()
X{
X  char *name_base;
X  register char *cp;
X  char *filename;
X  int base_length;
X  int short_base_length;
X  
X  long time;
X
X#ifdef VMS
X  char *tmp_base = "sys$scratch:b_";
X#else
X  char *tmp_base = "Bison.";
X#endif
X
X  char holding[50];
X  int tmp_len;
X  
X  tmp_len = strlen (tmp_base);
X
X  if (spec_outfile)
X    {
X      /* -o was specified.  The precise -o name will be used for ftable.
X	 For other output files, remove the ".c" or ".tab.c" suffix.  */
X      name_base = spec_outfile;
X      /* BASE_LENGTH includes ".tab" but not ".c".  */
X      base_length = strlen (name_base);
X      if (!strcmp (name_base + base_length - 2, ".c"))
X	base_length -= 2;
X      /* SHORT_BASE_LENGTH includes neither ".tab" nor ".c".  */
X      short_base_length = base_length;
X      if (!strcmp (name_base + short_base_length - 4, ".tab"))
X	short_base_length -= 4;
X      else if (!strcmp (name_base + short_base_length - 4, "_tab"))
X	short_base_length -= 4;
X    }
X  else
X    {
X      /* -o was not specified; compute output file name from input
X	 or use y.tab.c, etc., if -y was specified.  */
X
X      name_base = fixed_outfiles ? "y.y" : infile;
X
X      /* Discard any directory names from the input file name
X	 to make the base of the output.  */
X      cp = name_base;
X      while (*cp)
X	{
X	  if (*cp == '/')
X	    name_base = cp+1;
X	  cp++;
X	}
X
X      /* BASE_LENGTH gets length of NAME_BASE, sans ".y" suffix if any.  */
X
X      base_length = strlen (name_base);
X      if (!strcmp (name_base + base_length - 2, ".y"))
X	base_length -= 2;
X      short_base_length = base_length;
X
X#ifdef VMS
X      name_base = stringappend(name_base, short_base_length, "_tab");
X#else
X      name_base = stringappend(name_base, short_base_length, ".tab");
X#endif
X      base_length = short_base_length + 4;
X    }
X
X  finput = tryopen(infile, "r");
X
X  filename = (char *) getenv ("BISON_SIMPLE");
X  fparser = tryopen(filename ? filename : PFILE, "r");
X
X  if (verboseflag)
X    {
X      outfile = stringappend(name_base, short_base_length, ".output");
X      foutput = tryopen(outfile, "w");
X    }
X
X  if (definesflag)
X    {
X      defsfile = stringappend(name_base, base_length, ".h");
X      fdefines = tryopen(defsfile, "w");
X    }
X  time=TickCount();
X  sprintf(holding,"%s%u","act.",time);
X  actfile = stringappend(tmp_base, tmp_len, holding);
X  faction = tryopen(actfile, "w+");
X  unlink(actfile);
X
X  sprintf(holding,"%s%u","attrs.",time);
X  tmpattrsfile = stringappend(tmp_base, tmp_len, holding);
X  fattrs = tryopen(tmpattrsfile,"w+");
X  unlink(tmpattrsfile);
X
X  sprintf(holding,"%s%u","tab.",time);
X  tmptabfile = stringappend(tmp_base, tmp_len, holding);
X  ftable = tryopen(tmptabfile, "w+");
X  unlink(tmptabfile);
X
X	/* These are opened by `done' or `open_extra_files', if at all */
X  if (spec_outfile)
X    tabfile = spec_outfile;
X  else
X    tabfile = stringappend(name_base, base_length, ".c");
X
X#ifdef VMS
X  attrsfile = stringappend(name_base, short_base_length, "_stype.h");
X  guardfile = stringappend(name_base, short_base_length, "_guard.c");
X#else
X  attrsfile = stringappend(name_base, short_base_length, ".stype.h");
X  guardfile = stringappend(name_base, short_base_length, ".guard.c");
X#endif
X}
X
X
X
X/* open the output files needed only for the semantic parser.
XThis is done when %semantic_parser is seen in the declarations section.  */
Xopen_extra_files()
X{
X  FILE *ftmp;
X  int c;
X  char *filename;
X		/* JF change open parser file */
X  fclose(fparser);
X  filename = (char *) getenv ("BISON_HAIRY");
X  fparser= tryopen(filename ? filename : PFILE1, "r");
X
X		/* JF change from inline attrs file to separate one */
X  ftmp = tryopen(attrsfile, "w");
X  rewind(fattrs);
X  while((c=getc(fattrs))!=EOF)	/* Thank god for buffering */
X    putc(c,ftmp);
X  fclose(fattrs);
X  fattrs=ftmp;
X
X  fguard = tryopen(guardfile, "w");
X
X}
X
X	/* JF to make file opening easier.  This func tries to open file
X	   NAME with mode MODE, and prints an error message if it fails. */
XFILE *
Xtryopen(name, mode)
Xchar *name;
Xchar *mode;
X{
X  FILE	*ptr;
X  Create(name,0,'MPS ','TEXT');
X  ptr = fopen(name, mode);
X  if (ptr == NULL)
X    {
X      fprintf(stderr, "bison cannot find: ");
X      fprintf(stderr, name);
X      done(2);
X    }
X  return ptr;
X}
X
Xdone(k)
Xint k;
X{
X  if (faction)
X    fclose(faction);
X
X  if (fattrs)
X    fclose(fattrs);
X
X  if (fguard)
X    fclose(fguard);
X
X  if (finput)
X    fclose(finput);
X
X  if (fparser)
X    fclose(fparser);
X
X/* JF we don't need this anymore
X  if (fparser1)
X    fclose(fparser1); */
X
X  if (foutput)
X    fclose(foutput);
X
X	/* JF write out the output file */
X  if (k == 0 && ftable)
X    {
X      FILE *ftmp;
X      register int c;
X
X      ftmp=tryopen(tabfile, "w");
X      rewind(ftable);
X      while((c=getc(ftable)) != EOF)
X        putc(c,ftmp);
X      fclose(ftmp);
X      fclose(ftable);
X    }
X
X#ifdef VMS
X  delete(actfile);
X  delete(tmpattrsfile);
X  delete(tmptabfile);
X  if (k==0) sys$exit(SS$_NORMAL);
X  sys$exit(SS$_ABORT);
X#else
X  exit(k);
X#endif
X}
SHAR_EOF
if test 7386 -ne "`wc -c < 'files.c'`"
then
	echo shar: error transmitting "'files.c'" '(should have been 7386 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'getargs.c'" '(1879 characters)'
if test -f 'getargs.c'
then
	echo shar: will not over-write existing file "'getargs.c'"
else
sed 's/^X//' << \SHAR_EOF > 'getargs.c'
X/* Parse command line arguments for bison,
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#include <stdio.h>
X#include "file.h"
X
X#define __SEG__ files
X
Xint verboseflag;
Xint definesflag;
Xextern int fixed_outfiles;/* JF */
X
X
Xgetargs(argc, argv)
Xint argc;
Xchar *argv[];
X{
X  register int c;
X
X  extern int optind;
X  extern char *optarg;
X
X  verboseflag = 0;
X  definesflag = 0;
X  fixed_outfiles = 0;
X
X  while ((c = getopt (argc, argv, "yYvVdDo:O:")) != EOF)
X    switch (c)
X      {
X      case 'y':
X      case 'Y':
X	fixed_outfiles = 1;
X	break;
X
X      case 'v':
X      case 'V':
X	verboseflag = 1;
X	break;
X
X      case 'd':
X      case 'D':
X	definesflag = 1;
X	break;
X
X      case 'o':
X      case 'O':
X	spec_outfile = optarg;
X      }
X
X  if (optind == argc)
X    fatal("grammar file not specified");
X  else
X    infile = argv[optind];
X
X  if (optind < argc - 1)
X    fprintf(stderr, "bison: warning: extra arguments ignored\n");
X}
SHAR_EOF
if test 1879 -ne "`wc -c < 'getargs.c'`"
then
	echo shar: error transmitting "'getargs.c'" '(should have been 1879 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
--- end of part 2 ---

wetter@tybalt.caltech.edu (Pierce T. Wetter) (05/16/88)

[Bison Macintosh Sources - part 3 of 6]

---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	Bison/lalr.c
#	Bison/lex.c
#	Bison/lro.c
# This archive created: Sat May 14 02:41:51 1988
# By:	Roger L. Long (bytebug@dhw68k.cts.com)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'lalr.c'" '(13469 characters)'
if test -f 'lalr.c'
then
	echo shar: will not over-write existing file "'lalr.c'"
else
sed 's/^X//' << \SHAR_EOF > 'lalr.c'
X/* Compute look-ahead criteria for bison,
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* Compute how to make the finite state machine deterministic;
X find which rules need lookahead in each state, and which lookahead tokens they accept.
X
Xlalr(), the entry point, builds these data structures:
X
Xgoto_map, from_state and to_state 
X record each shift transition which accepts a variable (a nonterminal).
Xngotos is the number of such transitions.
Xfrom_state[t] is the state number which a transition leads from
Xand to_state[t] is the state number it leads to.
XAll the transitions that accept a particular variable are grouped together and
Xgoto_map[i - ntokens] is the index in from_state and to_state of the first of them.
X
Xconsistent[s] is nonzero if no lookahead is needed to decide what to do in state s.
X
XLAruleno is a vector which records the rules that need lookahead in various states.
XThe elements of LAruleno that apply to state s are those from
X lookaheads[s] through lookaheads[s+1]-1.
XEach element of LAruleno is a rule number.
X
XIf lr is the length of LAruleno, then a number from 0 to lr-1 
Xcan specify both a rule and a state where the rule might be applied.
X
XLA is a lr by ntokens matrix of bits.
XLA[l, i] is 1 if the rule LAruleno[l] is applicable in the appropriate state
X when the next token is symbol i.
XIf LA[l, i] and LA[l, j] are both 1 for i != j, it is a conflict.
X*/
X
X#include <stdio.h>
X#include "machine.h"
X#include "types.h"
X#include "state.h"
X#include "new.h"
X#include "gram.h"
X
X
Xextern short **derives;
Xextern char *nullable;
X
X
Xint tokensetsize;
Xshort *lookaheads;
Xshort *LAruleno;
Xunsigned *LA;
Xshort *accessing_symbol;
Xchar *consistent;
Xcore **state_table;
Xshifts **shift_table;
Xreductions **reduction_table;
Xshort *goto_map;
Xshort *from_state;
Xshort *to_state;
X
Xshort **transpose();
X
X
Xstatic int infinity;
Xstatic int maxrhs;
Xstatic int ngotos;
Xstatic unsigned *F;
Xstatic short **includes;
Xstatic shorts **lookback;
Xstatic short **R;
Xstatic short *INDEX;
Xstatic short *VERTICES;
Xstatic int top;
X
X
X
Xlalr()
X{
X  tokensetsize = WORDSIZE(ntokens);
X
X  set_state_table();
X  set_accessing_symbol();
X  set_shift_table();
X  set_reduction_table();
X  set_maxrhs();
X  initialize_LA();
X  set_goto_map();
X  initialize_F();
X  build_relations();
X  compute_FOLLOWS();
X  compute_lookaheads();
X}
X
X
X
Xset_state_table()
X{
X  register core *sp;
X
X  state_table = NEW2(nstates, core *);
X
X  for (sp = first_state; sp; sp = sp->next)
X    state_table[sp->number] = sp;
X}
X
X
X
Xset_accessing_symbol()
X{
X  register core *sp;
X
X  accessing_symbol = NEW2(nstates, short);
X
X  for (sp = first_state; sp; sp = sp->next)
X    accessing_symbol[sp->number] = sp->accessing_symbol;
X}
X
X
X
Xset_shift_table()
X{
X  register shifts *sp;
X
X  shift_table = NEW2(nstates, shifts *);
X
X  for (sp = first_shift; sp; sp = sp->next)
X    shift_table[sp->number] = sp;
X}
X
X
X
Xset_reduction_table()
X{
X  register reductions *rp;
X
X  reduction_table = NEW2(nstates, reductions *);
X
X  for (rp = first_reduction; rp; rp = rp->next)
X    reduction_table[rp->number] = rp;
X}
X
X
X
Xset_maxrhs()
X{
X  register short *itemp;
X  register int length;
X  register int max;
X
X  length = 0;
X  max = 0;
X  for (itemp = ritem; *itemp; itemp++)
X    {
X      if (*itemp > 0)
X	{
X	  length++;
X	}
X      else
X	{
X	  if (length > max) max = length;
X	  length = 0;
X	}
X    }
X
X  maxrhs = max;
X}
X
X
X
Xinitialize_LA()
X{
X  register int i;
X  register int j;
X  register int count;
X  register reductions *rp;
X  register shifts *sp;
X  register short *np;
X
X  consistent = NEW2(nstates, char);
X  lookaheads = NEW2(nstates + 1, short);
X
X  count = 0;
X  for (i = 0; i < nstates; i++)
X    {
X      register int j;
X
X      lookaheads[i] = count;
X
X      rp = reduction_table[i];
X      sp = shift_table[i];
X      if (rp && (rp->nreds > 1
X          || (sp && ! ISVAR(accessing_symbol[sp->shifts[0]]))))
X	count += rp->nreds;
X      else
X	consistent[i] = 1;
X
X      if (sp)
X	for (j = 0; j < sp->nshifts; j++)
X	  {
X	    if (accessing_symbol[sp->shifts[j]] == error_token_number)
X	      {
X		consistent[i] = 0;
X		break;
X	      }
X	  }
X    }
X
X  lookaheads[nstates] = count;
X
X  LA = NEW2(count * tokensetsize, unsigned);
X  LAruleno = NEW2(count, short);
X  lookback = NEW2(count, shorts *);
X
X  np = LAruleno;
X  for (i = 0; i < nstates; i++)
X    {
X      if (!consistent[i])
X	{
X	  if (rp = reduction_table[i])
X	    for (j = 0; j < rp->nreds; j++)
X	      *np++ = rp->rules[j];
X	}
X    }
X}
X
X
X
Xset_goto_map()
X{
X  register shifts *sp;
X  register int i;
X  register int symbol;
X  register int k;
X  register short *temp_map;
X  register int state2;
X  register int state1;
X
X  goto_map = NEW2(nvars + 1, short) - ntokens;
X  temp_map = NEW2(nvars + 1, short) - ntokens;
X
X  ngotos = 0;
X  for (sp = first_shift; sp; sp = sp->next)
X    {
X      for (i = sp->nshifts - 1; i >= 0; i--)
X	{
X	  symbol = accessing_symbol[sp->shifts[i]];
X
X	  if (ISTOKEN(symbol)) break;
X
X	  if (ngotos == MAXSHORT)
X	    toomany("gotos");
X
X	  ngotos++;
X	  goto_map[symbol]++;
X        }
X    }
X
X  k = 0;
X  for (i = ntokens; i < nsyms; i++)
X    {
X      temp_map[i] = k;
X      k += goto_map[i];
X    }
X
X  for (i = ntokens; i < nsyms; i++)
X    goto_map[i] = temp_map[i];
X
X  goto_map[nsyms] = ngotos;
X  temp_map[nsyms] = ngotos;
X
X  from_state = NEW2(ngotos, short);
X  to_state = NEW2(ngotos, short);
X
X  for (sp = first_shift; sp; sp = sp->next)
X    {
X      state1 = sp->number;
X      for (i = sp->nshifts - 1; i >= 0; i--)
X	{
X	  state2 = sp->shifts[i];
X	  symbol = accessing_symbol[state2];
X
X	  if (ISTOKEN(symbol)) break;
X
X	  k = temp_map[symbol]++;
X	  from_state[k] = state1;
X	  to_state[k] = state2;
X	}
X    }
X
X  FREE(temp_map + ntokens);
X}
X
X
X
X/*  Map_goto maps a state/symbol pair into its numeric representation.	*/
X
Xint
Xmap_goto(state, symbol)
Xint state;
Xint symbol;
X{
X  register int high;
X  register int low;
X  register int middle;
X  register int s;
X
X  low = goto_map[symbol];
X  high = goto_map[symbol + 1];
X
X  while (low <= high)
X    {
X      middle = (low + high) / 2;
X      s = from_state[middle];
X      if (s == state)
X	return (middle);
X      else if (s < state)
X	low = middle + 1;
X      else
X	high = middle - 1;
X    }
X
X  berror("map_goto");
X
X/* NOTREACHED */
X}
X
X
X
Xinitialize_F()
X{
X  register int i;
X  register int j;
X  register int k;
X  register shifts *sp;
X  register short *edge;
X  register unsigned *rowp;
X  register short *rp;
X  register short **reads;
X  register int nedges;
X  register int stateno;
X  register int symbol;
X  register int nwords;
X
X  nwords = ngotos * tokensetsize;
X  F = NEW2(nwords, unsigned);
X
X  reads = NEW2(ngotos, short *);
X  edge = NEW2(ngotos + 1, short);
X  nedges = 0;
X
X  rowp = F;
X  for (i = 0; i < ngotos; i++)
X    {
X      stateno = to_state[i];
X      sp = shift_table[stateno];
X
X      if (sp)
X	{
X	  k = sp->nshifts;
X
X	  for (j = 0; j < k; j++)
X	    {
X	      symbol = accessing_symbol[sp->shifts[j]];
X	      if (ISVAR(symbol))
X		break;
X	      SETBIT(rowp, symbol);
X	    }
X
X	  for (; j < k; j++)
X	    {
X	      symbol = accessing_symbol[sp->shifts[j]];
X	      if (nullable[symbol])
X		edge[nedges++] = map_goto(stateno, symbol);
X	    }
X	
X	  if (nedges)
X	    {
X	      reads[i] = rp = NEW2(nedges + 1, short);
X
X	      for (j = 0; j < nedges; j++)
X		rp[j] = edge[j];
X
X	      rp[nedges] = -1;
X	      nedges = 0;
X	    }
X	}
X
X      rowp += tokensetsize;
X    }
X
X  digraph(reads);
X
X  for (i = 0; i < ngotos; i++)
X    {
X      if (reads[i])
X	FREE(reads[i]);
X    }
X
X  FREE(reads);
X  FREE(edge);
X}
X
X
X
Xbuild_relations()
X{
X  register int i;
X  register int j;
X  register int k;
X  register short *rulep;
X  register short *rp;
X  register shifts *sp;
X  register int length;
X  register int nedges;
X  register int done;
X  register int state1;
X  register int stateno;
X  register int symbol1;
X  register int symbol2;
X  register short *shortp;
X  register short *edge;
X  register short *states;
X  register short **new_includes;
X
X  includes = NEW2(ngotos, short *);
X  edge = NEW2(ngotos + 1, short);
X  states = NEW2(maxrhs + 1, short);
X
X  for (i = 0; i < ngotos; i++)
X    {
X      nedges = 0;
X      state1 = from_state[i];
X      symbol1 = accessing_symbol[to_state[i]];
X
X      for (rulep = derives[symbol1]; *rulep > 0; rulep++)
X	{
X	  length = 1;
X	  states[0] = state1;
X	  stateno = state1;
X
X	  for (rp = ritem + rrhs[*rulep]; *rp > 0; rp++)
X	    {
X	      symbol2 = *rp;
X	      sp = shift_table[stateno];
X	      k = sp->nshifts;
X
X	      for (j = 0; j < k; j++)
X		{
X		  stateno = sp->shifts[j];
X		  if (accessing_symbol[stateno] == symbol2) break;
X		}
X
X	      states[length++] = stateno;
X	    }
X
X	  if (!consistent[stateno])
X	    add_lookback_edge(stateno, *rulep, i);
X
X	  length--;
X	  done = 0;
X	  while (!done)
X	    {
X	      done = 1;
X	      rp--;
X			/* JF added rp>=ritem &&   I hope to god its right! */
X	      if (rp>=ritem && ISVAR(*rp))
X		{
X		  stateno = states[--length];
X		  edge[nedges++] = map_goto(stateno, *rp);
X		  if (nullable[*rp]) done = 0;
X		}
X	    }
X	}
X
X      if (nedges)
X	{
X	  includes[i] = shortp = NEW2(nedges + 1, short);
X	  for (j = 0; j < nedges; j++)
X	    shortp[j] = edge[j];
X	  shortp[nedges] = -1;
X	}
X    }
X
X  new_includes = transpose(includes, ngotos);
X
X  for (i = 0; i < ngotos; i++)
X    if (includes[i])
X      FREE(includes[i]);
X
X  FREE(includes);
X
X  includes = new_includes;
X
X  FREE(edge);
X  FREE(states);
X}
X
X
X
Xadd_lookback_edge(stateno, ruleno, gotono)
Xint stateno;
Xint ruleno;
Xint gotono;
X{
X  register int i;
X  register int k;
X  register int found;
X  register shorts *sp;
X
X  i = lookaheads[stateno];
X  k = lookaheads[stateno + 1];
X  found = 0;
X  while (!found && i < k)
X    {
X      if (LAruleno[i] == ruleno)
X	found = 1;
X      else
X	i++;
X    }
X
X  if (found == 0)
X    berror("add_lookback_edge");
X
X  sp = NEW(shorts);
X  sp->next = lookback[i];
X  sp->value = gotono;
X  lookback[i] = sp;
X}
X
X
X
Xshort **
Xtranspose(R, n)
Xshort **R;
Xint n;
X{
X  register short **new_R;
X  register short **temp_R;
X  register short *nedges;
X  register short *sp;
X  register int i;
X  register int k;
X
X  nedges = NEW2(n, short);
X
X  for (i = 0; i < n; i++)
X    {
X      sp = R[i];
X      if (sp)
X	{
X	  while (*sp >= 0)
X	    nedges[*sp++]++;
X	}
X    }
X
X  new_R = NEW2(n, short *);
X  temp_R = NEW2(n, short *);
X
X  for (i = 0; i < n; i++)
X    {
X      k = nedges[i];
X      if (k > 0)
X	{
X	  sp = NEW2(k + 1, short);
X	  new_R[i] = sp;
X	  temp_R[i] = sp;
X	  sp[k] = -1;
X	}
X    }
X
X  FREE(nedges);
X
X  for (i = 0; i < n; i++)
X    {
X      sp = R[i];
X      if (sp)
X	{
X	  while (*sp >= 0)
X	    *temp_R[*sp++]++ = i;
X	}
X    }
X
X  FREE(temp_R);
X
X  return (new_R);
X}
X
X
X
Xcompute_FOLLOWS()
X{
X  register int i;
X
X  digraph(includes);
X
X  for (i = 0; i < ngotos; i++)
X    {
X      if (includes[i]) FREE(includes[i]);
X    }
X
X  FREE(includes);
X}
X
X
X
Xcompute_lookaheads()
X{
X  register int i;
X  register int n;
X  register unsigned *fp1;
X  register unsigned *fp2;
X  register unsigned *fp3;
X  register shorts *sp;
X  register unsigned *rowp;
X/*   register short *rulep; JF unused */
X/*  register int count; JF unused */
X  register shorts *sptmp;/* JF */
X
X  rowp = LA;
X  n = lookaheads[nstates];
X  for (i = 0; i < n; i++)
X    {
X      fp3 = rowp + tokensetsize;
X      for (sp = lookback[i]; sp; sp = sp->next)
X	{
X	  fp1 = rowp;
X	  fp2 = F + tokensetsize * sp->value;
X	  while (fp1 < fp3)
X	    *fp1++ |= *fp2++;
X	}
X
X      rowp = fp3;
X    }
X
X  for (i = 0; i < n; i++)
X    {/* JF removed ref to freed storage */
X      for (sp = lookback[i]; sp; sp = sptmp) {
X	sptmp=sp->next;
X	FREE(sp);
X      }
X    }
X
X  FREE(lookback);
X  FREE(F);
X}
X
X
X
Xdigraph(relation)
Xshort **relation;
X{
X  register int i;
X
X  infinity = ngotos + 2;
X  INDEX = NEW2(ngotos + 1, short);
X  VERTICES = NEW2(ngotos + 1, short);
X  top = 0;
X
X  R = relation;
X
X  for (i = 0; i < ngotos; i++)
X    INDEX[i] = 0;
X
X  for (i = 0; i < ngotos; i++)
X    {
X      if (INDEX[i] == 0 && R[i])
X	traverse(i);
X    }
X
X  FREE(INDEX);
X  FREE(VERTICES);
X}
X
X
X
Xtraverse(i)
Xregister int i;
X{
X  register unsigned *fp1;
X  register unsigned *fp2;
X  register unsigned *fp3;
X  register int j;
X  register short *rp;
X
X  int height;
X  unsigned *base;
X
X  VERTICES[++top] = i;
X  INDEX[i] = height = top;
X
X  base = F + i * tokensetsize;
X  fp3 = base + tokensetsize;
X
X  rp = R[i];
X  if (rp)
X    {
X      while ((j = *rp++) >= 0)
X	{
X	  if (INDEX[j] == 0)
X	    traverse(j);
X
X	  if (INDEX[i] > INDEX[j])
X	    INDEX[i] = INDEX[j];
X
X	  fp1 = base;
X	  fp2 = F + j * tokensetsize;
X
X	  while (fp1 < fp3)
X	    *fp1++ |= *fp2++;
X	}
X    }
X
X  if (INDEX[i] == height)
X    {
X      for (;;)
X	{
X	  j = VERTICES[top--];
X	  INDEX[j] = infinity;
X
X	  if (i == j)
X	    break;
X
X	  fp1 = base;
X	  fp2 = F + j * tokensetsize;
X
X	  while (fp1 < fp3)
X	    *fp2++ = *fp1++;
X	}
X    }
X}
SHAR_EOF
if test 13469 -ne "`wc -c < 'lalr.c'`"
then
	echo shar: error transmitting "'lalr.c'" '(should have been 13469 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'lex.c'" '(8811 characters)'
if test -f 'lex.c'
then
	echo shar: will not over-write existing file "'lex.c'"
else
sed 's/^X//' << \SHAR_EOF > 'lex.c'
X/* Token-reader for Bison's input parser,
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* 
X   lex() is the entry point.  It is called from reader.c.
X   It returns one of the token-type codes defined in lex.h.
X   When an identifier is seen, the code IDENTIFIER is returned
X   and the name is looked up in the symbol table using symtab.c;
X   symval is set to a pointer to the entry found.  */
X
X#include <stdio.h>
X#include <ctype.h>
X#include "file.h"
X#include "symtab.h"
X#include "lex.h"
X
X
Xextern int lineno;
Xextern int translations;
X
X
Xchar token_buffer[MAXTOKEN + 1];
Xbucket *symval;
Xint numval;
X
Xstatic int unlexed;		/* these two describe a token to be reread */
Xstatic bucket *unlexed_symval;	/* by the next call to lex */
X
X
X
Xinit_lex()
X{
X  unlexed = -1;
X}
X
X
X
Xint
Xskip_white_space()
X{
X  register int c;
X  register int inside;
X
X  c = getc(finput);
X
X  for (;;)
X    {
X      switch (c)
X	{
X	case '/':
X	  c = getc(finput);
X	  if (c != '*')
X	    fatals("unexpected '/%c' found",c);
X
X	  c = getc(finput);
X
X	  inside = 1;
X	  while (inside)
X	    {
X	      if (c == '*')
X		{
X		  while (c == '*')
X		    c = getc(finput);
X
X		  if (c == '/')
X		    {
X		      inside = 0;
X		      c = getc(finput);
X		    }
X		}
X	      else if (c == '\n')
X		{
X		  lineno++;
X		  c = getc(finput);
X		}
X	      else if (c == EOF)
X		fatal("unterminated comment");
X	      else
X		c = getc(finput);
X	    }
X
X	  break;
X
X	case '\n':
X	  lineno++;
X
X	case ' ':
X	case '\t':
X	case '\f':
X	  c = getc(finput);
X	  break;
X
X	default:
X	  return (c);
X	}
X    }
X}
X
X
X
Xunlex(token)
Xint token;
X{
X  unlexed = token;
X  unlexed_symval = symval;
X}
X
X
X
Xint
Xlex()
X{
X  register int c;
X  register char *p;
X
X  if (unlexed >= 0)
X    {
X      symval = unlexed_symval;
X      c = unlexed;
X      unlexed = -1;
X      return (c);
X    }
X
X  c = skip_white_space();
X
X  switch (c)
X    {
X    case EOF:
X      return (ENDFILE);
X
X    case 'A':  case 'B':  case 'C':  case 'D':  case 'E':
X    case 'F':  case 'G':  case 'H':  case 'I':  case 'J':
X    case 'K':  case 'L':  case 'M':  case 'N':  case 'O':
X    case 'P':  case 'Q':  case 'R':  case 'S':  case 'T':
X    case 'U':  case 'V':  case 'W':  case 'X':  case 'Y':
X    case 'Z':
X    case 'a':  case 'b':  case 'c':  case 'd':  case 'e':
X    case 'f':  case 'g':  case 'h':  case 'i':  case 'j':
X    case 'k':  case 'l':  case 'm':  case 'n':  case 'o':
X    case 'p':  case 'q':  case 'r':  case 's':  case 't':
X    case 'u':  case 'v':  case 'w':  case 'x':  case 'y':
X    case 'z':
X    case '.':  case '_':
X      p = token_buffer;
X      while (isalnum(c) || c == '_' || c == '.')
X	{
X	  if (p < token_buffer + MAXTOKEN)
X	    *p++ = c;
X	  c = getc(finput);
X	}
X
X      *p = 0;
X      ungetc(c, finput);
X      symval = getsym(token_buffer);
X      return (IDENTIFIER);
X
X    case '0':  case '1':  case '2':  case '3':  case '4':
X    case '5':  case '6':  case '7':  case '8':  case '9':
X      {
X	numval = 0;
X
X	while (isdigit(c))
X	  {
X	    numval = numval*10 + c - '0';
X	    c = getc(finput);
X	  }
X	ungetc(c, finput);
X	return (NUMBER);
X      }
X
X    case '\'':
X      translations = -1;
X
X      /* parse the literal token and compute character code in  code  */
X
X      c = getc(finput);
X      {
X	register int code = 0;
X
X	if (c == '\\')
X	  {
X	    c = getc(finput);
X
X	    if (c <= '7' && c >= '0')
X	      {
X		while (c <= '7' && c >= '0')
X		  {
X		    code = (code * 8) + (c - '0');
X		    c = getc(finput);
X		  }
X		if (code >= 128 || code<0)/* JF this said if(c>=128) */
X		  fatals("malformatted literal token '\\%03o'",code);
X	      }
X	    else
X	      {
X		if (c == 't')
X		  code = '\t';
X		else if (c == 'n')
X		  code = '\n';
X		else if (c == 'r')
X		  code = '\r';
X		else if (c == 'f')
X		  code = '\f';
X		else if (c == 'b')
X		  code = '\b';
X		else if (c == '\\')
X		  code = '\\';
X		else if (c == '\'')
X		  code = '\'';
X		else if (c == '\"')	/* JF this is a good idea */
X		  code = '\"';
X		else fatals("invalid literal token '\\%c'",c);
X		c = getc(finput);
X	      }
X	  }
X	else
X	  {
X	    code = c;
X	    c = getc(finput);
X	  }
X	if (c != '\'')
X	  fatal("multicharacter literal tokens NOT supported");
X
X	/* now fill token_buffer with the canonical name for this character
X	   as a literal token.  Do not use what the user typed,
X	   so that '\012' and '\n' can be interchangeable.  */
X
X	p = token_buffer;
X	*p++ = '\'';
X	if (code == '\\')
X	  {
X	    p = token_buffer + 1;
X	    *p++ = '\\';
X	    *p++ = '\\';
X	  }
X	else if (code == '\'')
X	  {
X	    p = token_buffer + 1;
X	    *p++ = '\\';
X	    *p++ = '\'';
X	  }
X	else if (code >= 040 && code != 0177)
X	  *p++ = code;
X	else if (code == '\t')
X	  {
X	    p = token_buffer + 1;
X	    *p++ = '\\';
X	    *p++ = 't';
X	  }
X	else if (code == '\n')
X	  {
X	    p = token_buffer + 1;
X	    *p++ = '\\';
X	    *p++ = 'n';
X	  }
X	else if (code == '\r')
X	  {
X	    p = token_buffer + 1;
X	    *p++ = '\\';
X	    *p++ = 'r';
X	  }
X	else if (code == '\b')
X	  {
X	    p = token_buffer + 1;
X	    *p++ = '\\';
X	    *p++ = 'b';
X	  }
X	else if (code == '\f')
X	  {
X	    p = token_buffer + 1;
X	    *p++ = '\\';
X	    *p++ = 'f';
X	  }
X        else
X	  {
X	    *p++ = code / 0100 + '0';
X	    *p++ = ((code / 010) & 07) + '0';
X	    *p++ = (code & 07) + '0';
X	  }
X	*p++ = '\'';
X	*p = 0;
X	symval = getsym(token_buffer);
X	symval->class = STOKEN;
X	if (! symval->user_token_number)
X	  symval->user_token_number = code;
X	return (IDENTIFIER);
X      }
X
X    case ',':
X      return (COMMA);
X
X    case ':':
X      return (COLON);
X
X    case ';':
X      return (SEMICOLON);
X
X    case '|':
X      return (BAR);
X
X    case '{':
X      return (LEFT_CURLY);
X
X    case '=':
X      do c = getc(finput);
X      while(c==' ' || c=='\n' || c=='\t');
X      if (c == '{')
X      	return(LEFT_CURLY);
X      else
X	{
X	  ungetc(c, finput);
X	  return(ILLEGAL);
X	}
X
X    case '<':
X      p = token_buffer;
X      c = getc(finput);
X      while (c != '>')
X	{
X	  if (c == '\n' || c == EOF)
X	    fatal("unterminated type name");
X
X	  if (p >= token_buffer + MAXTOKEN - 1)
X	    fatals("type name too long (%d max)",MAXTOKEN-1);
X
X	  *p++ = c;
X	  c = getc(finput);
X	}
X      *p = 0;
X      return (TYPENAME);
X	    
X
X    case '%':
X      return (parse_percent_token());
X
X    default:
X      return (ILLEGAL);
X    }
X}
X
X
X/* parse a token which starts with %.  Assumes the % has already been read and discarded.  */
X
Xint
Xparse_percent_token ()
X{
X  register int c;
X  register char *p;
X
X  p = token_buffer;
X  c = getc(finput);
X
X  switch (c)
X    {
X    case '%':
X      return (TWO_PERCENTS);
X
X    case '{':
X      return (PERCENT_LEFT_CURLY);
X
X    case '<':
X      return (LEFT);
X
X    case '>':
X      return (RIGHT);
X
X    case '2':
X      return (NONASSOC);
X
X    case '0':
X      return (TOKEN);
X
X    case '=':
X      return (PREC);
X    }
X  if (!isalpha(c))
X    return (ILLEGAL);
X
X  while (isalpha(c) || c == '_')
X    {
X      if (p < token_buffer + MAXTOKEN)
X	*p++ = c;
X      c = getc(finput);
X    }
X
X  ungetc(c, finput);
X
X  *p = 0;
X
X  if (strcmp(token_buffer, "token") == 0
X      ||
X      strcmp(token_buffer, "term") == 0)
X    return (TOKEN);
X  else if (strcmp(token_buffer, "nterm") == 0)
X    return (NTERM);
X  else if (strcmp(token_buffer, "type") == 0)
X    return (TYPE);
X  else if (strcmp(token_buffer, "guard") == 0)
X    return (GUARD);
X  else if (strcmp(token_buffer, "union") == 0)
X    return (UNION);
X  else if (strcmp(token_buffer, "expect") == 0)
X    return (EXPECT);
X  else if (strcmp(token_buffer, "start") == 0)
X    return (START);
X  else if (strcmp(token_buffer, "left") == 0)
X    return (LEFT);
X  else if (strcmp(token_buffer, "right") == 0)
X    return (RIGHT);
X  else if (strcmp(token_buffer, "nonassoc") == 0
X	   ||
X	   strcmp(token_buffer, "binary") == 0)
X    return (NONASSOC);
X  else if (strcmp(token_buffer, "semantic_parser") == 0)
X    return (SEMANTIC_PARSER);
X  else if (strcmp(token_buffer, "pure_parser") == 0)
X    return (PURE_PARSER);
X  else if (strcmp(token_buffer, "prec") == 0)
X    return (PREC);
X  else return (ILLEGAL);
X}
SHAR_EOF
if test 8811 -ne "`wc -c < 'lex.c'`"
then
	echo shar: error transmitting "'lex.c'" '(should have been 8811 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'lro.c'" '(13509 characters)'
if test -f 'lro.c'
then
	echo shar: will not over-write existing file "'lro.c'"
else
sed 's/^X//' << \SHAR_EOF > 'lro.c'
X/* Generate the nondeterministic finite state machine for bison,
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* See comments in state.h for the data structures that represent it.
X   The entry point is generate_states.  */
X
X#include <stdio.h>
X#include "machine.h"
X#include "new.h"
X#include "gram.h"
X#include "state.h"
X
X
Xextern char *nullable;
Xextern short *itemset;
Xextern short *itemsetend;
X
X
Xint nstates;
Xint final_state;
Xcore *first_state;
Xshifts *first_shift;
Xreductions *first_reduction;
X
Xint get_state();
Xcore *new_state();
X
Xstatic core *this_state;
Xstatic core *last_state;
Xstatic shifts *last_shift;
Xstatic reductions *last_reduction;
X
Xstatic int nshifts;
Xstatic short *shift_symbol;
X
Xstatic short *redset;
Xstatic short *shiftset;
X
Xstatic short **kernel_base;
Xstatic short **kernel_end;
Xstatic short *kernel_items;
X
X/* hash table for states, to recognize equivalent ones.  */
X
X#define	STATE_TABLE_SIZE	1009
Xstatic core **state_table;
X
X
X
Xallocate_itemsets()
X{
X  register short *itemp;
X  register int symbol;
X  register int i;
X  register count;
X  register int max;
X  register short *symbol_count;
X
X  count = 0;
X  symbol_count = NEW2(nsyms, short);
X
X  itemp = ritem;
X  symbol = *itemp++;
X  while (symbol)
X    {
X      if (symbol > 0)
X	{
X	  count++;
X	  symbol_count[symbol]++;
X	}
X      symbol = *itemp++;
X    }
X
X  /* see comments before new-itemset.  All the vectors of items
X     live inside kernel_items.  The number of active items after
X     some symbol cannot be more than the number of times that symbol
X     appears as an item, which is symbol_count[symbol].
X     We allocate that much space for each symbol.  */
X
X  kernel_base = NEW2(nsyms, short *);
X  kernel_items = NEW2(count, short);
X
X  count = 0;
X  max = 0;
X  for (i = 0; i < nsyms; i++)
X    {
X      kernel_base[i] = kernel_items + count;
X      count += symbol_count[i];
X      if (max < symbol_count[i])
X	max = symbol_count[i];
X    }
X
X  shift_symbol = symbol_count;
X  kernel_end = NEW2(nsyms, short *);
X}
X
X
X
Xallocate_storage()
X{
X  allocate_itemsets();
X
X  shiftset = NEW2(nsyms, short);
X  redset = NEW2(nrules + 1, short);
X  state_table = NEW2(STATE_TABLE_SIZE, core *);
X}
X
X
X
Xfree_storage()
X{
X  FREE(shift_symbol);
X  FREE(redset);
X  FREE(shiftset);
X  FREE(kernel_base);
X  FREE(kernel_end);
X  FREE(kernel_items);
X  FREE(state_table);
X}
X
X
X
X/* compute the nondeterministic finite state machine (see state.h for details)
Xfrom the grammar.  */
X
Xgenerate_states()
X{
X  allocate_storage();
X  initialize_closure(nitems);
X  initialize_states();
X
X  while (this_state)
X    {
X      /* Set up ruleset and itemset for the transitions out of this state.
X         ruleset gets a 1 bit for each rule that could reduce now.
X	 itemset gets a vector of all the items that could be accepted next.  */
X      closure(this_state->items, this_state->nitems);
X      /* record the reductions allowed out of this state */
X      save_reductions();
X      /* find the itemsets of the states that shifts can reach */
X      new_itemsets();
X      /* find or create the core structures for those states */
X      append_states();
X
X      /* create the shifts structures for the shifts to those states,
X         now that the state numbers transitioning to are known */
X      if (nshifts > 0)
X        save_shifts();
X
X      /* states are queued when they are created; process them all */
X      this_state = this_state->next;
X    }
X
X  /* discard various storage */
X  finalize_closure();
X  free_storage();
X
X  /* set up initial and final states as parser wants them */
X  augment_automaton();
X}
X
X
X
X/* Find which symbols can be shifted in the current state,
X   and for each one record which items would be active after that shift.
X   Uses the contents of itemset.
X   shift_symbol is set to a vector of the symbols that can be shifted.
X   For each symbol in the grammer, kernel_base[symbol] points to
X   a vector of item numbers activated if that symbol is shifted,
X   and kernel_end[symbol] points after the end of that vector.  */
X
Xnew_itemsets()
X{
X  register int i;
X  register int shiftcount;
X  register short *isp;
X  register short *ksp;
X  register int symbol;
X
X#ifdef	TRACE
X  fprintf(stderr, "Entering new_itemsets\n");
X#endif
X
X  for (i = 0; i < nsyms; i++)
X    kernel_end[i] = NULL;
X
X  shiftcount = 0;
X
X  isp = itemset;
X
X  while (isp < itemsetend)
X    {
X      i = *isp++;
X      symbol = ritem[i];
X      if (symbol > 0)
X	{
X          ksp = kernel_end[symbol];
X
X          if (!ksp)
X	    {
X	      shift_symbol[shiftcount++] = symbol;
X	      ksp = kernel_base[symbol];
X	    }
X
X          *ksp++ = i + 1;
X          kernel_end[symbol] = ksp;
X	}
X    }
X
X  nshifts = shiftcount;
X}
X
X
X
X/* Use the information computed by new_itemset to find the state numbers
X   reached by each shift transition from the current state.
X
X   shiftset is set up as a vector of state numbers of those states.  */
X
Xappend_states()
X{
X  register int i;
X  register int j;
X  register int symbol;
X
X#ifdef	TRACE
X  fprintf(stderr, "Entering append_states\n");
X#endif
X
X  /* first sort shift_symbol into increasing order */
X
X  for (i = 1; i < nshifts; i++)
X    {
X      symbol = shift_symbol[i];
X      j = i;
X      while (j > 0 && shift_symbol[j - 1] > symbol)
X	{
X	  shift_symbol[j] = shift_symbol[j - 1];
X	  j--;
X	}
X      shift_symbol[j] = symbol;
X    }
X
X  for (i = 0; i < nshifts; i++)
X    {
X      symbol = shift_symbol[i];
X      shiftset[i] = get_state(symbol);
X    }
X}
X
X
X
X/* find the state number for the state we would get to
X(from the current state) by shifting symbol.
XCreate a new state if no equivalent one exists already.
XUsed by append_states  */
X
Xint
Xget_state(symbol)
Xint symbol;
X{
X  register int key;
X  register short *isp1;
X  register short *isp2;
X  register short *iend;
X  register core *sp;
X  register int found;
X
X  int n;
X
X#ifdef	TRACE
X  fprintf(stderr, "Entering get_state, symbol = %d\n", symbol);
X#endif
X
X  isp1 = kernel_base[symbol];
X  iend = kernel_end[symbol];
X  n = iend - isp1;
X
X  /* add up the target state's active item numbers to get a hash key */
X  key = 0;
X  while (isp1 < iend)
X    key += *isp1++;
X
X  key = key % STATE_TABLE_SIZE;
X
X  sp = state_table[key];
X
X  if (sp)
X    {
X      found = 0;
X      while (!found)
X	{
X	  if (sp->nitems == n)
X	    {
X	      found = 1;
X	      isp1 = kernel_base[symbol];
X	      isp2 = sp->items;
X
X	      while (found && isp1 < iend)
X		{
X		  if (*isp1++ != *isp2++)
X		    found = 0;
X		}
X	    }
X
X	  if (!found)
X	    {
X	      if (sp->link)
X		{
X		  sp = sp->link;
X		}
X	      else   /* bucket exhausted and no match */
X		{
X		  sp = sp->link = new_state(symbol);
X		  found = 1;
X		}
X	    }
X	}
X    }
X  else      /* bucket is empty */
X    {
X      state_table[key] = sp = new_state(symbol);
X    }
X
X  return (sp->number);
X}
X
X
X
X/* subroutine of get_state.  create a new state for those items, if necessary.  */
X
Xcore *
Xnew_state(symbol)
Xint symbol;
X{
X  register int n;
X  register core *p;
X  register short *isp1;
X  register short *isp2;
X  register short *iend;
X
X#ifdef	TRACE
X  fprintf(stderr, "Entering new_state, symbol = %d\n", symbol);
X#endif
X
X  if (nstates >= MAXSHORT)
X    toomany("states");
X
X  isp1 = kernel_base[symbol];
X  iend = kernel_end[symbol];
X  n = iend - isp1;
X
X  p = (core *) allocate((unsigned) (sizeof(core) + (n - 1) * sizeof(short)));
X  p->accessing_symbol = symbol;
X  p->number = nstates;
X  p->nitems = n;
X
X  isp2 = p->items;
X  while (isp1 < iend)
X    *isp2++ = *isp1++;
X
X  last_state->next = p;
X  last_state = p;
X
X  nstates++;
X
X  return (p);
X}
X
X
X
Xinitialize_states()
X{
X  register core *p;
X/*  register unsigned *rp1; JF unused */
X/*  register unsigned *rp2; JF unused */
X/*  register unsigned *rend; JF unused */
X
X  p = (core *) allocate((unsigned) (sizeof(core) - sizeof(short)));
X  first_state = last_state = this_state = p;
X  nstates = 1;
X}
X
X
X
Xsave_shifts()
X{
X  register shifts *p;
X  register short *sp1;
X  register short *sp2;
X  register short *send;
X
X  p = (shifts *) allocate((unsigned) (sizeof(shifts) +
X			(nshifts - 1) * sizeof(short)));
X
X  p->number = this_state->number;
X  p->nshifts = nshifts;
X
X  sp1 = shiftset;
X  sp2 = p->shifts;
X  send = shiftset + nshifts;
X
X  while (sp1 < send)
X    *sp2++ = *sp1++;
X
X  if (last_shift)
X    {
X      last_shift->next = p;
X      last_shift = p;
X    }
X  else
X    {
X      first_shift = p;
X      last_shift = p;
X    }
X}
X
X
X
X/* find which rules can be used for reduction transitions from the current state
X   and make a reductions structure for the state to record their rule numbers.  */
X
Xsave_reductions()
X{
X  register short *isp;
X  register short *rp1;
X  register short *rp2;
X  register int item;
X  register int count;
X  register reductions *p;
X
X  short *rend;
X
X  /* find and count the active items that represent ends of rules */
X
X  count = 0;
X  for (isp = itemset; isp < itemsetend; isp++)
X    {
X      item = ritem[*isp];
X      if (item < 0)
X	{
X	  redset[count++] = -item;
X	}
X    }
X
X  /* make a reductions structure and copy the data into it.  */
X
X  if (count)
X    {
X      p = (reductions *) allocate((unsigned) (sizeof(reductions) +
X					(count - 1) * sizeof(short)));
X
X      p->number = this_state->number;
X      p->nreds = count;
X
X      rp1 = redset;
X      rp2 = p->rules;
X      rend = rp1 + count;
X
X      while (rp1 < rend)
X	*rp2++ = *rp1++;
X
X      if (last_reduction)
X	{
X	  last_reduction->next = p;
X	  last_reduction = p;
X	}
X      else
X	{
X	  first_reduction = p;
X	  last_reduction = p;
X	}
X    }
X}
X
X
X
X/* Make sure that the initial state has a shift that accepts the
Xgrammar's start symbol and goes to the next-to-final state,
Xwhich has a shift going to the final state, which has a shift
Xto the termination state.
XCreate such states and shifts if they don't happen to exist already.  */
X
Xaugment_automaton()
X{
X  register int i;
X  register int k;
X/*  register int found; JF unused */
X  register core *statep;
X  register shifts *sp;
X  register shifts *sp2;
X  register shifts *sp1;
X
X  sp = first_shift;
X
X  if (sp)
X    {
X      if (sp->number == 0)
X	{
X	  k = sp->nshifts;
X	  statep = first_state->next;
X
X	  while (statep->accessing_symbol < start_symbol
X		  && statep->number < k)
X	    statep = statep->next;
X
X	  if (statep->accessing_symbol == start_symbol)
X	    {
X	      k = statep->number;
X
X	      while (sp->number < k)
X		{
X		  sp1 = sp;
X		  sp = sp->next;
X		}
X
X	      if (sp->number == k)
X		{
X		  sp2 = (shifts *) allocate((unsigned) (sizeof(shifts)
X					+ sp->nshifts * sizeof(short)));
X		  sp2->next = sp->next;
X		  sp2->number = k;
X		  sp2->nshifts = sp->nshifts + 1;
X		  sp2->shifts[0] = nstates;
X		  for (i = sp->nshifts; i > 0; i--)
X		    sp2->shifts[i] = sp->shifts[i - 1];
X
X		  sp1->next = sp2;
X		  FREE(sp);
X		}
X	      else
X		{
X		  sp2 = NEW(shifts);
X		  sp2->next = sp;
X		  sp2->number = k;
X		  sp2->nshifts = 1;
X		  sp2->shifts[0] = nstates;
X
X		  sp1->next = sp2;
X		  if (!sp)
X		    last_shift = sp2;
X		}
X	    }
X	  else
X	    {
X	      k = statep->number;
X	      sp = first_shift;
X
X	      sp2 = (shifts *) allocate((unsigned) (sizeof(shifts)
X					+ sp->nshifts * sizeof(short)));
X	      sp2->next = sp->next;
X	      sp2->nshifts = sp->nshifts + 1;
X
X	      for (i = 0; i < k; i++)
X		sp2->shifts[i] = sp->shifts[i];
X
X	      sp2->shifts[k] = nstates;
X
X	      for (i = k; i < sp->nshifts; i++)
X		sp2->shifts[i + 1] = sp->shifts[i];
X
X	      first_shift = sp2;
X	      if (last_shift == sp)
X		last_shift = sp2;
X
X	      FREE(sp);
X
X	      insert_start_shift();
X	    }
X	}
X      else
X	{
X	  sp = NEW(shifts);
X	  sp->next = first_shift;
X	  sp->nshifts = 1;
X	  sp->shifts[0] = nstates;
X
X	  first_shift = sp;
X
X	  insert_start_shift();
X	}
X    }
X  else
X    {
X      sp = NEW(shifts);
X      sp->nshifts = 1;
X      sp->shifts[0] = nstates;
X
X      first_shift = sp;
X      last_shift = sp;
X
X      insert_start_shift();
X    }
X
X  statep = (core *) allocate((unsigned) (sizeof(core) - sizeof(short)));
X  statep->number = nstates;
X  last_state->next = statep;
X  last_state = statep;
X
X  sp = NEW(shifts);
X  sp->number = nstates++;
X  sp->nshifts = 1;
X  sp->shifts[0] = nstates;
X  last_shift->next = sp;
X  last_shift = sp;
X
X  final_state = nstates;
X
X  statep = (core *) allocate((unsigned) (sizeof(core) - sizeof(short)));
X  statep->number = nstates++;
X  last_state->next = statep;
X  last_state = statep;
X}
X
X
X/* subroutine of augment_automaton */
X
Xinsert_start_shift()
X{
X  register core *statep;
X  register shifts *sp;
X
X  statep = (core *) allocate((unsigned) (sizeof(core) - sizeof(short)));
X  statep->number = nstates;
X  statep->accessing_symbol = start_symbol;
X
X  last_state->next = statep;
X  last_state = statep;
X
X  sp = NEW(shifts);
X  sp->number = nstates++;
X  sp->nshifts = 1;
X  sp->shifts[0] = nstates;
X
X  last_shift->next = sp;
X  last_shift = sp;
X}
SHAR_EOF
if test 13509 -ne "`wc -c < 'lro.c'`"
then
	echo shar: error transmitting "'lro.c'" '(should have been 13509 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
--- end of part 3 ---

wetter@tybalt.caltech.edu (Pierce T. Wetter) (05/17/88)

[Bison Macintosh Sources - part 4 of 6]

---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	Bison/main.c
#	Bison/nullable.c
#	Bison/output.c
#	Bison/print.c
# This archive created: Sat May 14 02:41:58 1988
# By:	Roger L. Long (bytebug@dhw68k.cts.com)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'main.c'" '(3142 characters)'
if test -f 'main.c'
then
	echo shar: will not over-write existing file "'main.c'"
else
sed 's/^X//' << \SHAR_EOF > 'main.c'
X/* Top level entry point of bison,
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#include <stdio.h>
X#include "machine.h"	/* JF for MAXSHORT */
X
Xextern	int lineno;
Xextern	int verboseflag;
X
X/* Nonzero means failure has been detected; don't write a parser file.  */
Xint failure;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X  failure = 0;
X  lineno = 0;
X  getargs(argc, argv);
X  openfiles();
X
X  /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
X     In file reader.
X     The other parts are recorded in the grammar; see gram.h.  */
X  reader();
X
X  /* record other info about the grammar.  In files derives and nullable.  */
X  set_derives();
X  set_nullable();
X
X  /* convert to nondeterministic finite state machine.  In file LR0.
X     See state.h for more info.  */
X  generate_states();
X
X  /* make it deterministic.  In file lalr.  */
X  lalr();
X
X  /* Find and record any conflicts: places where one token of lookahead is not
X     enough to disambiguate the parsing.  In file conflicts.
X     Currently this does not do anything to resolve them;
X     the trivial form of conflict resolution that exists is done in output.  */
X  initialize_conflicts();
X
X  /* print information about results, if requested.  In file print. */
X  if (verboseflag)
X    verbose();
X  else
X    terse();
X
X  /* output the tables and the parser to ftable.  In file output. */
X  output();
X  done(failure);
X}
X
X/* functions to report errors which prevent a parser from being generated */
X
Xfatal(s)
Xchar *s;
X{
X  extern char *infile;
X
X  if (infile == 0)
X    fprintf(stderr, "fatal error: %s\n", s);
X  else
X    fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
X  done(1);
X}
X
X
X/* JF changed to accept/deal with variable args.  Is a real kludge since
X   we don't support _doprnt calls */
X/*VARARGS1*/
Xfatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
Xchar *fmt;
X{
X  char buffer[200];
X
X  sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
X  fatal(buffer);
X}
X
X
X
Xtoomany(s)
Xchar *s;
X{
X  char buffer[200];
X
X	/* JF new msg */
X  sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
X  fatal(buffer);
X}
X
X
X
Xberror(s)
Xchar *s;
X{
X  fprintf(stderr, "internal error, %s\n", s);
X  exit(1);
X}
SHAR_EOF
if test 3142 -ne "`wc -c < 'main.c'`"
then
	echo shar: error transmitting "'main.c'" '(should have been 3142 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'nullable.c'" '(2824 characters)'
if test -f 'nullable.c'
then
	echo shar: will not over-write existing file "'nullable.c'"
else
sed 's/^X//' << \SHAR_EOF > 'nullable.c'
X/* Part of the bison parser generator,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* set up nullable, a vector saying which nonterminals can expand into the null string.
X   nullable[i - ntokens] is nonzero if symbol i can do so.  */
X
X#include <stdio.h>
X#include "types.h"
X#include "gram.h"
X#include "new.h"
X
X
Xchar *nullable;
X
X
Xset_nullable()
X{
X  register short *r;
X  register short *s1;
X  register short *s2;
X  register int ruleno;
X  register int symbol;
X  register shorts *p;
X
X  short *squeue;
X  short *rcount;
X  shorts **rsets;
X  shorts *relts;
X  char any_tokens;
X  short *r1;
X
X#ifdef	TRACE
X  fprintf(stderr, "Entering set_nullable");
X#endif
X
X  nullable = NEW2(nvars, char) - ntokens;
X
X  squeue = NEW2(nvars, short);
X  s1 = s2 = squeue;
X
X  rcount = NEW2(nrules + 1, short);
X  rsets = NEW2(nvars, shorts *) - ntokens;
X  relts = NEW2(nitems + nvars + 1, shorts);
X  p = relts;
X
X  r = ritem;
X  while (*r)
X    {
X      if (*r < 0)
X	{
X	  symbol = rlhs[-(*r++)];
X	  if (!nullable[symbol])
X	    {
X	      nullable[symbol] = 1;
X	      *s2++ = symbol;
X	    }
X	}
X      else
X	{
X	  r1 = r;
X	  any_tokens = 0;
X	  for (symbol = *r++; symbol > 0; symbol = *r++)
X	    {
X	      if (ISTOKEN(symbol))
X		any_tokens = 1;
X	    }
X
X	  if (!any_tokens)
X	    {
X	      ruleno = -symbol;
X	      r = r1;
X	      for (symbol = *r++; symbol > 0; symbol = *r++)
X		{
X		  rcount[ruleno]++;
X		  p->next = rsets[symbol];
X		  p->value = ruleno;
X		  rsets[symbol] = p;
X		  p++;
X		}
X	    }
X	}
X    }
X
X  while (s1 < s2)
X    {
X      p = rsets[*s1++];
X      while (p)
X	{
X	  ruleno = p->value;
X	  p = p->next;
X	  if (--rcount[ruleno] == 0)
X	    {
X	      symbol = rlhs[ruleno];
X	      if (!nullable[symbol])
X		{
X		  nullable[symbol] = 1;
X		  *s2++ = symbol;
X		}
X	    }
X	}
X    }
X
X  FREE(squeue);
X  FREE(rcount);
X  FREE(rsets + ntokens);
X  FREE(relts);
X}
X
X
Xfree_nullable()
X{
X  FREE(nullable + ntokens);
X}
SHAR_EOF
if test 2824 -ne "`wc -c < 'nullable.c'`"
then
	echo shar: error transmitting "'nullable.c'" '(should have been 2824 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'output.c'" '(24116 characters)'
if test -f 'output.c'
then
	echo shar: will not over-write existing file "'output.c'"
else
sed 's/^X//' << \SHAR_EOF > 'output.c'
X/* Output the generated parsing program for bison,
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* functions to output parsing data to various files.  Entries are:
X
X  output_headers ()
X
XOutput constant strings to the beginning of certain files.
X
X  output_trailers()
X
XOutput constant strings to the ends of certain files.
X
X  output ()
X
XOutput the parsing tables and the parser code to ftable.
X
XThe parser tables consist of:  (starred ones needed only for the semantic parser)
X
Xyytranslate = vector mapping yylex's token numbers into bison's token numbers.
X
Xyytname = vector of string-names indexed by bison token number
X
Xyyrline = vector of line-numbers of all rules.  For yydebug printouts.
X
X* yyrhs = vector of items of all rules.
X        This is exactly what ritems contains.
X
X* yyprhs[r] = index in yyrhs of first item for rule r.
X
Xyyr1[r] = symbol number of symbol that rule r derives.
X
Xyyr2[r] = number of symbols composing right hand side of rule r.
X
X* yystos[s] = the symbol number of the symbol that leads to state s.
X
Xyydefact[s] = default rule to reduce with in state s,
X	      when yytable doesn't specify something else to do.
X	      Zero means the default is an error.
X
Xyydefgoto[i] = default state to go to after a reduction of a rule that
X	       generates variable ntokens + i, except when yytable
X	       specifies something else to do.
X
Xyypact[s] = index in yytable of the portion describing state s.
X            The lookahed token's type is used to index that portion
X            to find out what to do.
X
X	    If the value in yytable is positive,
X	    we shift the token and go to that state.
X
X	    If the value is negative, it is minus a rule number to reduce by.
X
X	    If the value is zero, the default action from yydefact[s] is used.
X
Xyypgoto[i] = the index in yytable of the portion describing 
X             what to do after reducing a rule that derives variable i + ntokens.
X             This portion is indexed by the parser state number
X	     as of before the text for this nonterminal was read.
X	     The value from yytable is the state to go to.
X
Xyytable = a vector filled with portions for different uses,
X          found via yypact and yypgoto.
X
Xyycheck = a vector indexed in parallel with yytable.
X	  It indicates, in a roundabout way, the bounds of the
X	  portion you are trying to examine.
X
X	  Suppose that the portion of yytable starts at index p
X	  and the index to be examined within the portion is i.
X	  Then if yycheck[p+i] != i, i is outside the bounds
X	  of what is actually allocated, and the default
X	  (from yydefact or yydefgoto) should be used.
X	  Otherwise, yytable[p+i] should be used.
X
XYYFINAL = the state number of the termination state.
XYYFLAG = most negative short int.  Used to flag ??
XYYNTBASE = ntokens.
X
X*/
X
X#include <stdio.h>
X#include "machine.h"
X#include "new.h"
X#include "file.h"
X#include "gram.h"
X#include "state.h"
X
X#define	MAXTABLE 32767
X
X
Xextern char **tags;
Xextern int tokensetsize;
Xextern int final_state;
Xextern core **state_table;
Xextern shifts **shift_table;
Xextern errs **err_table;
Xextern reductions **reduction_table;
Xextern short *accessing_symbol;
Xextern unsigned *LA;
Xextern short *LAruleno;
Xextern short *lookaheads;
Xextern char *consistent;
Xextern short *goto_map;
Xextern short *from_state;
Xextern short *to_state;
X
X
Xstatic int nvectors;
Xstatic int nentries;
Xstatic short **froms;
Xstatic short **tos;
Xstatic short *tally;
Xstatic short *width;
Xstatic short *actrow;
Xstatic short *state_count;
Xstatic short *order;
Xstatic short *base;
Xstatic short *pos;
Xstatic short *table;
Xstatic short *check;
Xstatic int lowzero;
Xstatic int high;
X
X
X
X#define	GUARDSTR	"\n#include \"%s\"\nextern int yyerror;\n\
Xextern int yycost;\nextern char * yymsg;\nextern YYSTYPE yyval;\n\n\
Xyyguard(n, yyvsp, yylsp)\nregister int n;\nregister YYSTYPE *yyvsp;\n\
Xregister YYLTYPE *yylsp;\n\
X{\n  yyerror = 0;\nyycost = 0;\n  yymsg = 0;\nswitch (n)\n    {"
X
X#define	ACTSTR		"\n#include \"%s\"\nextern YYSTYPE yyval;\
X\nextern int yychar;\
Xyyaction(n, yyvsp, yylsp)\nregister int n;\nregister YYSTYPE *yyvsp;\n\
Xregister YYLTYPE *yylsp;\n{\n  switch (n)\n{"
X
X#define	ACTSTR_SIMPLE	"\n  switch (yyn) {\n"
X
X
X
Xoutput_headers()
X{
X  if (semantic_parser)
X    fprintf(fguard, GUARDSTR, attrsfile);
X  fprintf(faction, (semantic_parser ? ACTSTR : ACTSTR_SIMPLE), attrsfile);
X/*  if (semantic_parser)	JF moved this below
X    fprintf(ftable, "#include \"%s\"\n", attrsfile);
X  fprintf(ftable, "#include <stdio.h>\n\n"); */
X}
X
Xoutput_trailers()
X{
X  if (semantic_parser)
X    {
X      fprintf(fguard, "\n    }\n}\n");
X      fprintf(faction, "\n    }\n}\n");
X    }
X  else
X    fprintf(faction, "\n}\n");
X}
X
X
Xoutput()
X{
X  int c;
X
X  /* output_token_defines(ftable);	/* JF put out token defines FIRST */
X  if (!semantic_parser)		/* JF Put out other stuff */
X    {
X      rewind(fattrs);
X      while ((c=getc(fattrs))!=EOF)
X        putc(c,ftable);
X    }
X
X  if (semantic_parser)
X    fprintf(ftable, "#include \"%s\"\n", attrsfile);
X  fprintf(ftable, "#include <stdio.h>\n\n");
X
X  /* Make "const" do nothing if not in ANSI C.  */
X  fprintf (ftable, "#ifndef __STDC__\n#define const\n#endif\n\n");
X
X  free_itemsets();
X  output_defines();
X  output_token_translations();
X  if (semantic_parser)
X    output_gram();
X  FREE(ritem);
X  if (semantic_parser)
X    output_stos();
X  output_rule_data();
X  output_actions();
X  output_parser();
X  output_program();
X}
X
Xoutput_token_translations()
X{
X  register int i, j;
X/*   register short *sp; JF unused */
X
X  if (translations)
X    {
X      fprintf(ftable,
X	      "\n#define YYTRANSLATE(x) ((unsigned)(x) <= %d ? yytranslate[x] : %d)\n",
X	      max_user_token_number, nsyms);
X    
X      if (ntokens < 127)  /* play it very safe; check maximum element value.  */
X        fprintf(ftable, "\nstatic const char yytranslate[] = {     0");
X      else
X	fprintf(ftable, "\nstatic const short yytranslate[] = {     0");
X    
X      j = 10;
X      for (i = 1; i <= max_user_token_number; i++)
X	{
X	  putc(',', ftable);
X    
X	  if (j >= 10)
X	    {
X	      putc('\n', ftable);
X	      j = 1;
X	    }
X	  else
X	    {
X	      j++;
X	    }
X    
X	  fprintf(ftable, "%6d", token_translations[i]);
X	}
X    
X      fprintf(ftable, "\n};\n");
X    }
X  else
X    {
X      fprintf(ftable, "\n#define YYTRANSLATE(x) (x)\n");
X    } 
X}
X
X
X
Xoutput_gram()
X{
X  register int i;
X  register int j;
X  register short *sp;
X
X  fprintf(ftable, "\nstatic const short yyprhs[] = {     0");
X
X  j = 10;
X  for (i = 1; i <= nrules; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      fprintf(ftable, "%6d", rrhs[i]);
X    }
X
X  fprintf(ftable, "\n};\n\nstatic const short yyrhs[] = {%6d", ritem[0]);
X
X  j = 10;
X  for (sp = ritem + 1; *sp; sp++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      if (*sp > 0)
X	fprintf(ftable, "%6d", *sp);
X      else
X	fprintf(ftable, "     0");
X    }
X
X  fprintf(ftable, "\n};\n");
X}
X
X
X
Xoutput_stos()
X{
X  register int i;
X  register int j;
X
X  fprintf(ftable, "\nstatic const short yystos[] = {     0");
X
X  j = 10;
X  for (i = 1; i < nstates; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      fprintf(ftable, "%6d", accessing_symbol[i]);
X    }
X
X  fprintf(ftable, "\n};\n");
X}
X
X
X
Xoutput_rule_data()
X{
X  register int i;
X  register int j;
X
X  fprintf(ftable, "\nstatic const short yyrline[] = {     0");
X
X  j = 10;
X  for (i = 1; i <= nrules; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      fprintf(ftable, "%6d", rline[i]);
X    }
X
X  /* Output the table of token names.  */
X
X  fprintf(ftable, "\n};\n\nstatic const char * const yytname[] = {     0");
X
X  j = 10;
X  for (i = 1; i <= ntokens; i++)
X    {
X      register char *p;
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      putc ('\"', ftable);
X
X      for (p = tags[i]; *p; p++)
X	if (*p == '"' || *p == '\\')
X	  fprintf(ftable, "\\%c", *p);
X	else if (*p == '\n')
X	  fprintf(ftable, "\\n");
X	else if (*p == '\t')
X	  fprintf(ftable, "\\t");
X	else if (*p == '\b')
X	  fprintf(ftable, "\\b");
X	else if (*p < 040 || *p >= 0177)
X	  fprintf(ftable, "\\%03o", *p);
X	else
X	  putc(*p, ftable);
X
X      putc ('\"', ftable);
X    }
X
X  fprintf(ftable, "\n};\n\nstatic const short yyr1[] = {     0");
X
X  j = 10;
X  for (i = 1; i <= nrules; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      fprintf(ftable, "%6d", rlhs[i]);
X    }
X
X  FREE(rlhs + 1);
X
X  fprintf(ftable, "\n};\n\nstatic const short yyr2[] = {     0");
X
X  j = 10;
X  for (i = 1; i < nrules; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      fprintf(ftable, "%6d", rrhs[i + 1] - rrhs[i] - 1);
X    }
X
X  putc(',', ftable);
X  if (j >= 10)
X    putc('\n', ftable);
X
X  fprintf(ftable, "%6d\n};\n", nitems - rrhs[nrules] - 1);
X  FREE(rrhs + 1);
X}
X
X
X
Xoutput_defines()
X{
X  fprintf(ftable, "\n\n#define\tYYFINAL\t\t%d\n", final_state);
X  fprintf(ftable, "#define\tYYFLAG\t\t%d\n", MINSHORT);
X  fprintf(ftable, "#define\tYYNTBASE\t%d\n", ntokens);
X}
X
X
X
X/* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable and yycheck.  */
X
Xoutput_actions()
X{
X  nvectors = nstates + nvars;
X
X  froms = NEW2(nvectors, short *);
X  tos = NEW2(nvectors, short *);
X  tally = NEW2(nvectors, short);
X  width = NEW2(nvectors, short);
X
X  token_actions();
X  free_shifts();
X  free_reductions();
X  FREE(lookaheads);
X  FREE(LA);
X  FREE(LAruleno);
X  FREE(accessing_symbol);
X
X  goto_actions();
X  FREE(goto_map + ntokens);
X  FREE(from_state);
X  FREE(to_state);
X
X  sort_actions();
X  pack_table();
X  output_base();
X  output_table();
X  output_check();
X}
X
X
X
X/* figure out the actions for the specified state, indexed by lookahead token type.
X
X   The yydefact table is output now.  The detailed info
X   is saved for putting into yytable later.  */
X
Xtoken_actions()
X{
X  register int i;
X  register int j;
X  register int k;
X
X  actrow = NEW2(ntokens, short);
X
X  k = action_row(0);
X  fprintf(ftable, "\nstatic const short yydefact[] = {%6d", k);
X  save_row(0);
X
X  j = 10;
X  for (i = 1; i < nstates; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      k = action_row(i);
X      fprintf(ftable, "%6d", k);
X      save_row(i);
X    }
X
X  fprintf(ftable, "\n};\n");
X  FREE(actrow);
X}
X
X
X
X/* Decide what to do for each type of token if seen as the lookahead token in specified state.
X   The value returned is used as the default action (yydefact) for the state.
X   In addition, actrow is filled with what to do for each kind of token,
X   index by symbol number, with zero meaning do the default action.
X   The value MINSHORT, a very negative number, means this situation
X   is an error.  The parser recognizes this value specially.
X
X   This is where conflicts are resolved.  The loop over lookahead rules
X   considered lower-numbered rules last, and the last rule considered that likes
X   a token gets to handle it.  */
X
Xint
Xaction_row(state)
Xint state;
X{
X  register int i;
X  register int j;
X  register int k;
X  register int m;
X  register int n;
X  register int count;
X  register int default_rule;
X  register int nreds;
X  register int max;
X  register int rule;
X  register int shift_state;
X  register int symbol;
X  register unsigned mask;
X  register unsigned *wordp;
X  register reductions *redp;
X  register shifts *shiftp;
X  register errs *errp;
X  int nodefault = 0;  /* set nonzero to inhibit having any default reduction */
X
X  for (i = 0; i < ntokens; i++)
X    actrow[i] = 0;
X
X  default_rule = 0;
X  nreds = 0;
X  redp = reduction_table[state];
X
X  if (redp)
X    {
X      nreds = redp->nreds;
X
X      if (nreds >= 1)
X	{
X	  /* loop over all the rules available here which require lookahead */
X	  m = lookaheads[state];
X	  n = lookaheads[state + 1];
X
X	  for (i = n - 1; i >= m; i--)
X	    {
X	      rule = - LAruleno[i];
X	      wordp = LA + i * tokensetsize;
X	      mask = 1;
X
X	      /* and find each token which the rule finds acceptable to come next */
X	      for (j = 0; j < ntokens; j++)
X		{
X		  /* and record this rule as the rule to use if that token follows.  */
X		  if (mask & *wordp)
X		    actrow[j] = rule;
X
X		  mask <<= 1;
X		  if (mask == 0)
X		    {
X		      mask = 1;
X		      wordp++;
X		    }
X		}
X	    }
X	}
X    }
X
X  shiftp = shift_table[state];
X
X  /* now see which tokens are allowed for shifts in this state.
X     For them, record the shift as the thing to do.  So shift is preferred to reduce.  */
X
X  if (shiftp)
X    {
X      k = shiftp->nshifts;
X
X      for (i = 0; i < k; i++)
X	{
X	  shift_state = shiftp->shifts[i];
X	  if (! shift_state) continue;
X
X	  symbol = accessing_symbol[shift_state];
X
X	  if (ISVAR(symbol))
X	    break;
X
X	  actrow[symbol] = shift_state;
X
X	  /* do not use any default reduction if there is a shift for error */
X
X	  if (symbol == error_token_number) nodefault = 1;
X	}
X    }
X
X  errp = err_table[state];
X
X  /* See which tokens are an explicit error in this state
X     (due to %nonassoc).  For them, record MINSHORT as the action.  */
X
X  if (errp)
X    {
X      k = errp->nerrs;
X
X      for (i = 0; i < k; i++)
X	{
X	  symbol = errp->errs[i];
X	  actrow[symbol] = MINSHORT;
X	}
X    }
X
X  /* now find the most common reduction and make it the default action for this state.  */
X
X  if (nreds >= 1 && ! nodefault)
X    {
X      if (consistent[state])
X	default_rule = redp->rules[0];
X      else
X	{
X	  max = 0;
X	  for (i = m; i < n; i++)
X	    {
X	      count = 0;
X	      rule = - LAruleno[i];
X    
X	      for (j = 0; j < ntokens; j++)
X		{
X		  if (actrow[j] == rule)
X		    count++;
X		}
X    
X	      if (count > max)
X		{
X		  max = count;
X		  default_rule = rule;
X		}
X	    }
X    
X	  /* actions which match the default are replaced with zero,
X	     which means "use the default" */
X    
X	  if (max > 0)
X	    {
X	      for (j = 0; j < ntokens; j++)
X		{
X		  if (actrow[j] == default_rule)
X		    actrow[j] = 0;
X		}
X    
X	      default_rule = - default_rule;
X	    }
X	}
X    }
X
X  /* If have no default rule, the default is an error.
X     So replace any action which says "error" with "use default".  */
X
X  if (default_rule == 0)
X    for (j = 0; j < ntokens; j++)
X      {
X	if (actrow[j] == MINSHORT)
X	  actrow[j] = 0;
X      }
X
X  return (default_rule);
X}
X
X
X
Xsave_row(state)
Xint state;
X{
X  register int i;
X  register int count;
X  register short *sp;
X  register short *sp1;
X  register short *sp2;
X
X  count = 0;
X  for (i = 0; i < ntokens; i++)
X    {
X      if (actrow[i] != 0)
X	count++;
X    }
X
X  if (count == 0)
X    return;
X
X  froms[state] = sp1 = sp = NEW2(count, short);
X  tos[state] = sp2 = NEW2(count, short);
X
X  for (i = 0; i < ntokens; i++)
X    {
X      if (actrow[i] != 0)
X	{
X	  *sp1++ = i;
X	  *sp2++ = actrow[i];
X	}
X    }
X
X  tally[state] = count;
X  width[state] = sp1[-1] - sp[0] + 1;
X}
X
X
X
X/* figure out what to do after reducing with each rule,
X   depending on the saved state from before the beginning
X   of parsing the data that matched this rule.
X
X   The yydefgoto table is output now.  The detailed info
X   is saved for putting into yytable later.  */
X
Xgoto_actions()
X{
X  register int i;
X  register int j;
X  register int k;
X
X  state_count = NEW2(nstates, short);
X
X  k = default_goto(ntokens);
X  fprintf(ftable, "\nstatic const short yydefgoto[] = {%6d", k);
X  save_column(ntokens, k);
X
X  j = 10;
X  for (i = ntokens + 1; i < nsyms; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      k = default_goto(i);
X      fprintf(ftable, "%6d", k);
X      save_column(i, k);
X    }
X
X  fprintf(ftable, "\n};\n");
X  FREE(state_count);
X}
X
X
X
Xint
Xdefault_goto(symbol)
Xint symbol;
X{
X  register int i;
X  register int m;
X  register int n;
X  register int default_state;
X  register int max;
X
X  m = goto_map[symbol];
X  n = goto_map[symbol + 1];
X
X  if (m == n)
X    return (-1);
X
X  for (i = 0; i < nstates; i++)
X    state_count[i] = 0;
X
X  for (i = m; i < n; i++)
X    state_count[to_state[i]]++;
X
X  max = 0;
X  default_state = -1;
X
X  for (i = 0; i < nstates; i++)
X    {
X      if (state_count[i] > max)
X	{
X	  max = state_count[i];
X	  default_state = i;
X	}
X    }
X
X  return (default_state);
X}
X
X
X
Xsave_column(symbol, default_state)
Xint symbol;
Xint default_state;
X{
X  register int i;
X  register int m;
X  register int n;
X  register short *sp;
X  register short *sp1;
X  register short *sp2;
X  register int count;
X  register int symno;
X
X  m = goto_map[symbol];
X  n = goto_map[symbol + 1];
X
X  count = 0;
X  for (i = m; i < n; i++)
X    {
X      if (to_state[i] != default_state)
X	count++;
X    }
X
X  if (count == 0)
X    return;
X
X  symno = symbol - ntokens + nstates;
X
X  froms[symno] = sp1 = sp = NEW2(count, short);
X  tos[symno] = sp2 = NEW2(count, short);
X
X  for (i = m; i < n; i++)
X    {
X      if (to_state[i] != default_state)
X	{
X	  *sp1++ = from_state[i];
X	  *sp2++ = to_state[i];
X	}
X    }
X
X  tally[symno] = count;
X  width[symno] = sp1[-1] - sp[0] + 1;
X}
X
X
X
X/* the next few functions decide how to pack 
X   the actions and gotos information into yytable. */
X
Xsort_actions()
X{
X  register int i;
X  register int j;
X  register int k;
X  register int t;
X  register int w;
X
X  order = NEW2(nvectors, short);
X  nentries = 0;
X
X  for (i = 0; i < nvectors; i++)
X    {
X      if (tally[i] > 0)
X	{
X	  t = tally[i];
X	  w = width[i];
X	  j = nentries - 1;
X
X	  while (j >= 0 && (width[order[j]] < w))
X	    j--;
X
X	  while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t))
X	    j--;
X
X	  for (k = nentries - 1; k > j; k--)
X	    order[k + 1] = order[k];
X
X	  order[j + 1] = i;
X	  nentries++;
X	}
X    }
X}
X
X
X
Xpack_table()
X{
X  register int i;
X  register int place;
X  register int state;
X
X  base = NEW2(nvectors, short);
X  pos = NEW2(nentries, short);
X  table = NEW2(MAXTABLE, short);
X  check = NEW2(MAXTABLE, short);
X
X  lowzero = 0;
X  high = 0;
X
X  for (i = 0; i < nvectors; i++)
X    base[i] = MINSHORT;
X
X  for (i = 0; i < MAXTABLE; i++)
X    check[i] = -1;
X
X  for (i = 0; i < nentries; i++)
X    {
X      state = matching_state(i);
X
X      if (state < 0)
X	place = pack_vector(i);
X      else
X	place = base[state];
X
X      pos[i] = place;
X      base[order[i]] = place;
X    }
X
X  for (i = 0; i < nvectors; i++)
X    {
X      FREE(froms[i]);
X      FREE(tos[i]);
X    }
X
X  FREE(froms);
X  FREE(tos);
X  FREE(pos);
X}
X
X
X
Xint
Xmatching_state(vector)
Xint vector;
X{
X  register int i;
X  register int j;
X  register int k;
X  register int t;
X  register int w;
X  register int match;
X  register int prev;
X
X  i = order[vector];
X  if (i >= nstates)
X    return (-1);
X
X  t = tally[i];
X  w = width[i];
X
X  for (prev = vector - 1; prev >= 0; prev--)
X    {
X      j = order[prev];
X      if (width[j] != w || tally[j] != t)
X	return (-1);
X
X      match = 1;
X      for (k = 0; match && k < t; k++)
X	{
X	  if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
X	    match = 0;
X	}
X
X      if (match)
X	return (j);
X    }
X
X  return (-1);
X}
X
X
X
Xint
Xpack_vector(vector)
Xint vector;
X{
X  register int i;
X  register int j;
X  register int k;
X  register int t;
X  register int loc;
X  register int ok;
X  register short *from;
X  register short *to;
X
X  i = order[vector];
X  t = tally[i];
X
X  if (t == 0)
X    berror("pack_vector");
X
X  from = froms[i];
X  to = tos[i];
X
X  for (j = lowzero - from[0]; j < MAXTABLE; j++)
X    {
X      ok = 1;
X
X      for (k = 0; ok && k < t; k++)
X	{
X	  loc = j + from[k];
X	  if (loc > MAXTABLE)
X	    fatals("maximum table size (%d) exceeded",MAXTABLE);
X
X	  if (table[loc] != 0)
X	    ok = 0;
X	}
X
X      for (k = 0; ok && k < vector; k++)
X	{
X	  if (pos[k] == j)
X	    ok = 0;
X	}
X
X      if (ok)
X	{
X	  for (k = 0; k < t; k++)
X	    {
X	      loc = j + from[k];
X	      table[loc] = to[k];
X	      check[loc] = from[k];
X	    }
X
X	  while (table[lowzero] != 0)
X	    lowzero++;
X
X	  if (loc > high)
X	    high = loc;
X
X	  return (j);
X	}
X    }
X
X  berror("pack_vector");
X  return 0;	/* JF keep lint happy */
X}
X
X
X
X/* the following functions output yytable, yycheck
X   and the vectors whose elements index the portion starts */
X
Xoutput_base()
X{
X  register int i;
X  register int j;
X
X  fprintf(ftable, "\nstatic const short yypact[] = {%6d", base[0]);
X
X  j = 10;
X  for (i = 1; i < nstates; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      fprintf(ftable, "%6d", base[i]);
X    }
X
X  fprintf(ftable, "\n};\n\nstatic const short yypgoto[] = {%6d", base[nstates]);
X
X  j = 10;
X  for (i = nstates + 1; i < nvectors; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      fprintf(ftable, "%6d", base[i]);
X    }
X
X  fprintf(ftable, "\n};\n");
X  FREE(base);
X}
X
X
X
Xoutput_table()
X{
X  register int i;
X  register int j;
X
X  fprintf(ftable, "\n\n#define\tYYLAST\t\t%d\n\n", high);
X  fprintf(ftable, "\nstatic const short yytable[] = {%6d", table[0]);
X
X  j = 10;
X  for (i = 1; i <= high; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      fprintf(ftable, "%6d", table[i]);
X    }
X
X  fprintf(ftable, "\n};\n");
X  FREE(table);
X}
X
X
X
Xoutput_check()
X{
X  register int i;
X  register int j;
X
X  fprintf(ftable, "\nstatic const short yycheck[] = {%6d", check[0]);
X
X  j = 10;
X  for (i = 1; i <= high; i++)
X    {
X      putc(',', ftable);
X
X      if (j >= 10)
X	{
X	  putc('\n', ftable);
X	  j = 1;
X	}
X      else
X	{
X	  j++;
X	}
X
X      fprintf(ftable, "%6d", check[i]);
X    }
X
X  fprintf(ftable, "\n};\n");
X  FREE(check);
X}
X
X
X
X/* copy the parser code into the ftable file at the end.  */
X
Xoutput_parser()
X{
X  register int c;
X#ifdef DONTDEF
X  FILE *fpars;
X#else
X#define fpars fparser
X#endif
X
X  if (pure_parser)
X    fprintf(ftable, "#define YYIMPURE 1\n\n");
X  else
X    fprintf(ftable, "#define YYPURE 1\n\n");
X
X#ifdef DONTDEF	/* JF no longer needed 'cuz open_extra_files changes the
X		   currently open parser from bison.simple to bison.hairy */
X  if (semantic_parser)
X    fpars = fparser;
X  else fpars = fparser1;
X#endif
X
X  c = getc(fpars);
X  while (c != EOF)
X    {
X      if (c == '$') {
X#ifdef DONTDEF
X        fprintf(ftable, "#include \"%s\"\n", actfile);
X#else
X      	/* JF don't #include the action file.  Stuff it right in. */
X	rewind(faction);
X	for(c=getc(faction);c!=EOF;c=getc(faction))
X		putc(c,ftable);
X#endif
X      } else
X	putc(c, ftable);
X      c = getc(fpars);
X    }
X}
X
X
X
Xoutput_program()
X{
X  register int c;
X  extern int lineno;
X
X  fprintf(ftable, "#line %d \"%s\"\n", lineno, infile);
X
X  c = getc(finput);
X  while (c != EOF)
X    {
X      putc(c, ftable);
X      c = getc(finput);
X    }
X}
X
X
X
Xfree_itemsets()
X{
X  register core *cp,*cptmp;
X
X  FREE(state_table);
X
X  for (cp = first_state; cp; cp = cptmp) {
X    cptmp=cp->next;
X    FREE(cp);
X  }
X}
X
X
X
Xfree_shifts()
X{
X  register shifts *sp,*sptmp;/* JF derefrenced freed ptr */
X
X  FREE(shift_table);
X
X  for (sp = first_shift; sp; sp = sptmp) {
X    sptmp=sp->next;
X    FREE(sp);
X  }
X}
X
X
X
Xfree_reductions()
X{
X  register reductions *rp,*rptmp;/* JF fixed freed ptr */
X
X  FREE(reduction_table);
X
X  for (rp = first_reduction; rp; rp = rptmp) {
X    rptmp=rp->next;
X    FREE(rp);
X  }
X}
SHAR_EOF
if test 24116 -ne "`wc -c < 'output.c'`"
then
	echo shar: error transmitting "'output.c'" '(should have been 24116 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'print.c'" '(4598 characters)'
if test -f 'print.c'
then
	echo shar: will not over-write existing file "'print.c'"
else
sed 's/^X//' << \SHAR_EOF > 'print.c'
X/* Print information on generated parser, for bison,
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#include <stdio.h>
X#include "machine.h"
X#include "new.h"
X#include "file.h"
X#include "gram.h"
X#include "state.h"
X
X
Xextern char **tags;
Xextern int nstates;
Xextern short *accessing_symbol;
Xextern core **state_table;
Xextern shifts **shift_table;
Xextern errs **err_table;
Xextern reductions **reduction_table;
Xextern char *consistent;
Xextern char any_conflicts;
Xextern char *conflicts;
X
X
X
Xterse()
X{
X  if (any_conflicts)
X    {
X      conflict_log();
X    }
X}
X
X
X
Xverbose()
X{
X  register int i;
X
X  if (any_conflicts)
X    verbose_conflict_log();
X
X  fprintf(foutput, "\n\ntoken types:\n");
X  print_token (-1, 0);
X  if (translations)
X    {
X      for (i = 0; i <= max_user_token_number; i++)
X	/* Don't mention all the meaningless ones.  */
X	if (token_translations[i] != 2)
X	  print_token (i, token_translations[i]);
X    }
X  else
X    for (i = 1; i < ntokens; i++)
X      print_token (i, i);
X
X  for (i = 0; i < nstates; i++)
X    {
X      print_state(i);
X    }
X}
X
X
X
Xprint_token(extnum, token)
Xint extnum, token;
X{
X  fprintf(foutput, " type %d is %s\n", extnum, tags[token]);
X}
X
X
X
Xprint_state(state)
Xint state;
X{
X  fprintf(foutput, "\n\nstate %d\n\n", state);
X  print_core(state);
X  print_actions(state);
X}
X
X
X
Xprint_core(state)
Xint state;
X{
X  register int i;
X  register int k;
X  register int rule;
X  register core *statep;
X  register short *sp;
X  register short *sp1;
X
X  statep = state_table[state];
X  k = statep->nitems;
X
X  if (k == 0) return;
X
X  for (i = 0; i < k; i++)
X    {
X      sp1 = sp = ritem + statep->items[i];
X
X      while (*sp > 0)
X	sp++;
X
X      rule = -(*sp);
X      fprintf(foutput, "    %s  ->  ", tags[rlhs[rule]]);
X
X      for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
X	{
X	  fprintf(foutput, "%s ", tags[*sp]);
X	}
X
X      putc('.', foutput);
X
X      while (*sp > 0)
X	{
X	  fprintf(foutput, " %s", tags[*sp]);
X	  sp++;
X	}
X
X      fprintf (foutput, "   (%d)", rule);
X      putc('\n', foutput);
X    }
X
X  putc('\n', foutput);
X}
X
X
X
Xprint_actions(state)
Xint state;
X{
X  register int i;
X  register int k;
X  register int state1;
X  register int symbol;
X  register shifts *shiftp;
X  register errs *errp;
X  register reductions *redp;
X  register int rule;
X
X  shiftp = shift_table[state];
X  redp = reduction_table[state];
X  errp = err_table[state];
X
X  if (!shiftp && !redp)
X    {
X      fprintf(foutput, "    NO ACTIONS\n");
X      return;
X    }
X
X  if (shiftp)
X    {
X      k = shiftp->nshifts;
X
X      for (i = 0; i < k; i++)
X	{
X	  if (! shiftp->shifts[i]) continue;
X	  state1 = shiftp->shifts[i];
X	  symbol = accessing_symbol[state1];
X/*	  if (ISVAR(symbol)) break;  */
X	  fprintf(foutput, "    %-4s\tshift  %d\n", tags[symbol], state1);
X	}
X
X      if (i > 0)
X	putc('\n', foutput);
X    }
X  else
X    {
X      i = 0;
X      k = 0;
X    }
X
X  if (errp)
X    {
X      k = errp->nerrs;
X
X      for (i = 0; i < k; i++)
X	{
X	  if (! errp->errs[i]) continue;
X	  symbol = errp->errs[i];
X	  fprintf(foutput, "    %-4s\terror (nonassociative)\n", tags[symbol]);
X	}
X
X      if (i > 0)
X	putc('\n', foutput);
X    }
X  else
X    {
X      i = 0;
X      k = 0;
X    }
X
X  if (consistent[state] && redp)
X    {
X      rule = redp->rules[0];
X      symbol = rlhs[rule];
X      fprintf(foutput, "    $default\treduce  %d  (%s)\n\n",
X     	        rule, tags[symbol]);
X    }
X  else if (redp)
X    {
X      print_reductions(state);
X    }
X
X  if (i < k)
X    {
X      for (; i < k; i++)
X	{
X	  if (! shiftp->shifts[i]) continue;
X	  state1 = shiftp->shifts[i];
X	  symbol = accessing_symbol[state1];
X	  fprintf(foutput, "    %-4s\tgoto  %d\n", tags[symbol], state1);
X	}
X
X      putc('\n', foutput);
X    }
X}
SHAR_EOF
if test 4598 -ne "`wc -c < 'print.c'`"
then
	echo shar: error transmitting "'print.c'" '(should have been 4598 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
--- end of part 4 ---

wetter@tybalt.caltech.edu (Pierce T. Wetter) (05/18/88)

[Bison Macintosh Sources - part 5 of 6]

---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	Bison/reader.c
# This archive created: Sat May 14 02:42:03 1988
# By:	Roger L. Long (bytebug@dhw68k.cts.com)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'reader.c'" '(34877 characters)'
if test -f 'reader.c'
then
	echo shar: will not over-write existing file "'reader.c'"
else
sed 's/^X//' << \SHAR_EOF > 'reader.c'
X/* Input parser for bison
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* read in the grammar specification and record it in the format described in gram.h.
X  All guards are copied into the fguard file and all actions into faction,
X  in each case forming the body of a C function (yyguard or yyaction)
X  which contains a switch statement to decide which guard or action to execute.
X
XThe entry point is reader().  */
X
X#include <stdio.h>
X#include <ctype.h>
X#include "file.h"
X#include "new.h"
X#include "symtab.h"
X#include "lex.h"
X#include "gram.h"
X
X#define __SEG__ files
X
X
X#define	LTYPESTR	"\n#ifndef YYLTYPE\ntypedef\n  struct yyltype\n\
X    {\n      int timestamp;\n      int first_line;\n      int first_column;\n\
X      int last_line;\n      int last_column;\n      char *text;\n   }\n\
X  yyltype;\n\n#define YYLTYPE yyltype\n#endif\n\n"
X
X/* Number of slots allocated (but not necessarily used yet) in `rline'  */
Xint rline_allocated;
X
Xextern int definesflag;
Xextern bucket *symval;
Xextern int numval;
Xextern int failure;
Xextern int expected_conflicts;
X
Xtypedef
X  struct symbol_list
X    {
X      struct symbol_list *next;
X      bucket *sym;
X      bucket *ruleprec;
X    }
X  symbol_list;
X
X
X
Xint lineno;
Xbucket *symval;
Xsymbol_list *grammar;
Xint start_flag;
Xbucket *startval;
Xchar **tags;
X
Xstatic int typed;  /* nonzero if %union has been seen.  */
X
Xstatic int lastprec;  /* incremented for each %left, %right or %nonassoc seen */
X
Xstatic int gensym_count;  /* incremented for each generated symbol */
X
Xstatic bucket *errtoken;
X
Xreader()
X{
X
X  start_flag = 0;
X  startval = NULL;  /* start symbol not specified yet. */
X
X  translations = 0;  /* initially assume token number translation not needed.  */
X
X  nsyms = 1;
X  nvars = 0;
X  nrules = 0;
X  nitems = 0;
X  rline_allocated = 10;
X  rline = NEW2(rline_allocated, short);
X
X  typed = 0;
X  lastprec = 0;
X
X  gensym_count = 0;
X
X  semantic_parser = 0;
X  pure_parser = 0;
X
X  grammar = NULL;
X
X  init_lex();
X  lineno = 1;
X
X  /* initialize the symbol table.  */
X  tabinit();
X  /* construct the error token */
X  errtoken = getsym("error");
X  errtoken->class = STOKEN;
X  /* construct a token that represents all undefined literal tokens. */
X  /* it is always token number 2.  */
X  getsym("$illegal.")->class = STOKEN;
X  /* Read the declaration section.  Copy %{ ... %} groups to ftable and fdefines file.
X     Also notice any %token, %left, etc. found there.  */
X  fprintf(ftable, "\n/*  A Bison parser, made from %s  */\n\n", infile);
X  read_declarations();
X  /* output the definition of YYLTYPE into the fattrs and fdefines files.  */
X  output_ltype();
X  /* start writing the guard and action files, if they are needed.  */
X  output_headers();
X  /* read in the grammar, build grammar in list form.  write out guards and actions.  */
X  readgram();
X  /* write closing delimiters for actions and guards.  */
X  output_trailers();
X  /* assign the symbols their symbol numbers.
X     Write #defines for the token symbols into fdefines if requested.  */
X  packsymbols();
X  /* convert the grammar into the format described in gram.h.  */
X  packgram();
X  /* free the symbol table data structure
X     since symbols are now all referred to by symbol number.  */
X  free_symtab();
X}
X
X
X
X/* read from finput until %% is seen.  Discard the %%.
XHandle any % declarations,
Xand copy the contents of any %{ ... %} groups to fattrs.  */
X
Xread_declarations ()
X{
X  register int c;
X  register int tok;
X
X  for (;;)
X    {
X      c = skip_white_space();
X
X      if (c == '%')
X	{
X	  tok = parse_percent_token();
X
X	  switch (tok)
X	    {
X	    case TWO_PERCENTS:
X	      return;
X
X	    case PERCENT_LEFT_CURLY:
X	      copy_definition();
X	      break;
X
X	    case TOKEN:
X	      parse_token_decl (STOKEN, SNTERM);
X	      break;
X	
X	    case NTERM:
X	      parse_token_decl (SNTERM, STOKEN);
X	      break;
X	
X	    case TYPE:
X	      parse_type_decl();
X	      break;
X	
X	    case START:
X	      parse_start_decl();
X	      break;
X	
X	    case UNION:
X	      parse_union_decl();
X	      break;
X	
X	    case EXPECT:
X	      parse_expect_decl();
X	      break;
X	
X	    case LEFT:
X	      parse_assoc_decl(LEFT_ASSOC);
X	      break;
X
X	    case RIGHT:
X	      parse_assoc_decl(RIGHT_ASSOC);
X	      break;
X
X	    case NONASSOC:
X	      parse_assoc_decl(NON_ASSOC);
X	      break;
X
X	    case SEMANTIC_PARSER:
X	      semantic_parser = 1;
X	      open_extra_files();
X	      break;
X
X	    case PURE_PARSER:
X	      pure_parser = 1;
X	      break;
X
X	    default:
X	      fatal("junk after % in definition section");
X	    }
X	}
X      else if (c == EOF)
X        fatal("no input grammar");
X      else/* JF changed msg */
X        fatals("Unrecognized char '%c' in declaration section",c);
X
X    }
X}
X
X
X/* copy the contents of a %{ ... %} into the definitions file.
XThe %{ has already been read.  Return after reading the %}.  */
Xcopy_definition ()
X{
X  register int c;
X  register int match;
X  register int ended;
X  register int after_percent;  /* -1 while reading a character if prev char was % */
X
X  fprintf(fattrs, "#line %d \"%s\"\n", lineno, infile);
X
X  after_percent = 0;
X
X  c = getc(finput);
X
X  for (;;)
X    {
X      switch (c)
X	{
X	case '\n':
X	  putc(c, fattrs);
X	  lineno++;
X	  break;
X
X	case '%':
X          after_percent = -1;
X	  break;
X	      
X	case '\'':
X	case '"':
X	  match = c;
X	  putc(c, fattrs);
X	  c = getc(finput);
X
X	  while (c != match)
X	    {
X	      if (c == EOF || c == '\n')
X		fatal("unterminated string");
X
X	      putc(c, fattrs);
X	      
X	      if (c == '\\')
X		{
X		  c = getc(finput);
X		  if (c == EOF || c == '\n')
X		    fatal("unterminated string");
X		  putc(c, fattrs);
X		  if (c == '\n')
X		    lineno++;
X		}
X
X	      c = getc(finput);
X	    }
X
X	  putc(c, fattrs);
X	  break;
X
X	case '/':
X	  putc(c, fattrs);
X	  c = getc(finput);
X	  if (c != '*')
X	    continue;
X
X	  putc(c, fattrs);
X	  c = getc(finput);
X
X	  ended = 0;
X	  while (!ended)
X	    {
X	      if (c == '*')
X		{
X		  while (c == '*')
X		    {
X		      putc(c, fattrs);
X		      c = getc(finput);
X		    }
X
X		  if (c == '/')
X		    {
X		      putc(c, fattrs);
X		      ended = 1;
X		    }
X		}
X	      else if (c == '\n')
X		{
X		  lineno++;
X		  putc(c, fattrs);
X		  c = getc(finput);
X		}
X	      else if (c == EOF)
X		fatal("unterminated comment in %{ definition");
X	      else
X		{
X		  putc(c, fattrs);
X		  c = getc(finput);
X		}
X	    }
X
X	  break;
X
X	case EOF:
X	  fatal("unterminated %{ definition");
X
X	default:
X	  putc(c, fattrs);
X	}
X
X      c = getc(finput);
X
X      if (after_percent)
X	{
X	  if (c == '}')
X	    return;
X	  putc('%', fattrs);
X	}
X      after_percent = 0;
X
X    }
X
X}
X
X
X
X/* parse what comes after %token or %nterm.
XFor %token, what_is is STOKEN and what_is_not is SNTERM.
XFor %nterm, the arguments are reversed.  */
X
Xparse_token_decl (what_is, what_is_not)
X     int what_is, what_is_not;
X{
X/*   register int start_lineno; JF */
X  register int token = 0;
X  register int prev;
X  register char *typename = 0;
X  int k;
X  extern char token_buffer[];
X
X/*   start_lineno = lineno; JF */
X
X  for (;;)
X    {
X      if(ungetc(skip_white_space(), finput) == '%')
X	return;
X
X/*      if (lineno != start_lineno)
X	return; JF */
X
X      /* we have not passed a newline, so the token now starting is in this declaration */
X      prev = token;
X
X      if ((token = lex()) == TYPENAME)
X	{
X	  k = strlen(token_buffer);
X	  if (typename) free (typename);
X	  typename = NEW2(k + 1, char);
X	  strcpy(typename, token_buffer);
X	}
X      else if (token == IDENTIFIER)
X	{
X	  if (symval->class == what_is_not)
X	    fatals("symbol %s redefined", symval->tag);
X	  symval->class = what_is;
X	  if (what_is == SNTERM)
X	    symval->value = nvars++;
X
X	  if (typename)
X	    {
X	      if (symval->type_name == NULL)
X		symval->type_name = typename;
X	      else
X		fatals("type redeclaration for %s", symval->tag);
X	    }
X	}
X      else if (prev == IDENTIFIER && token == NUMBER)
X        {
X	  symval->user_token_number = numval;
X	  translations = 1;
X        }
X      else
X	fatal("invalid text in %token or %nterm declaration");
X    }
X
X}
X
X
X
X/* parse what comes after %start */
X
Xparse_start_decl ()
X{
X  if (start_flag)
X    fatal("multiple %start declarations");
X  start_flag = 1;
X  if (lex() != IDENTIFIER)
X    fatal("invalid %start declaration");
X  startval = symval;
X}
X
X
X
X/* read in a %type declaration and record its information for get_type_name to access */
X
Xparse_type_decl ()
X{
X  register int k;
X  register char *name;
X/*   register int start_lineno; JF */
X
X  extern char token_buffer[];
X
X  if (lex() != TYPENAME)
X    fatal("ill-formed %type declaration");
X
X  k = strlen(token_buffer);
X  name = NEW2(k + 1, char);
X  strcpy(name, token_buffer);
X
X/*   start_lineno = lineno; */
X
X  for (;;)
X    {
X      register int t;
X
X      if(ungetc(skip_white_space(), finput) == '%')
X	return;
X
X/*       if (lineno != start_lineno)
X	return; JF */
X
X      /* we have not passed a newline, so the token now starting is in this declaration */
X
X      t = lex();
X
X      switch (t)
X	{
X
X	case COMMA:
X	  break;
X
X	case IDENTIFIER:
X	  if (symval->type_name == NULL)
X	    symval->type_name = name;
X	  else
X	    fatals("type redeclaration for %s", symval->tag);
X
X	  break;
X
X	default:
X	  fatal("invalid %type declaration");
X	}
X    }
X}
X
X
X
X/* read in a %left, %right or %nonassoc declaration and record its information.  */
X/* assoc is either LEFT_ASSOC, RIGHT_ASSOC or NON_ASSOC.  */
X
Xparse_assoc_decl (assoc)
Xint assoc;
X{
X  register int k;
X  register char *name = NULL;
X/*  register int start_lineno; JF */
X  register int prev = 0;	/* JF added = 0 to keep lint happy */
X
X  extern char token_buffer[];
X
X  lastprec++;  /* assign a new precedence level.  */
X
X/*   start_lineno = lineno; */
X
X  for (;;)
X    {
X      register int t;
X
X      if(ungetc(skip_white_space(), finput) == '%')
X	return;
X
X      /* if (lineno != start_lineno)
X	return; JF */
X
X      /* we have not passed a newline, so the token now starting is in this declaration */
X
X      t = lex();
X
X      switch (t)
X	{
X
X	case TYPENAME:
X	  k = strlen(token_buffer);
X	  name = NEW2(k + 1, char);
X	  strcpy(name, token_buffer);
X	  break;
X
X	case COMMA:
X	  break;
X
X	case IDENTIFIER:
X	  symval->prec = lastprec;
X	  symval->assoc = assoc;
X	  if (symval->class == SNTERM)
X	    fatals("symbol %s redefined", symval->tag);
X	  symval->class = STOKEN;
X	  if (name)
X	    { /* record the type, if one is specified */
X	      if (symval->type_name == NULL)
X		symval->type_name = name;
X	      else
X		fatals("type redeclaration for %s", symval->tag);
X	    }
X	  break;
X
X	case NUMBER:
X	  if (prev == IDENTIFIER)
X            {
X	      symval->user_token_number = numval;
X	      translations = 1;
X            }
X          else	  
X	    fatal("invalid text in association declaration");
X	  break;
X
X	case SEMICOLON:
X	  return;
X
X	default:
X	  fatal("malformatted association declaration");
X	}
X
X      prev = t;
X
X    }
X}
X
X
X
X/* copy the union declaration into fattrs (and fdefines),
X   where it is made into the
X   definition of YYSTYPE, the type of elements of the parser value stack.  */
X
Xparse_union_decl()
X{
X  register int c;
X  register int count;
X  register int in_comment;
X
X  if (typed)
X    fatal("multiple %union declarations");
X
X  typed = 1;
X
X  fprintf(fattrs, "\n#line %d \"%s\"\n", lineno, infile);
X  fprintf(fattrs, "typedef union");
X  if (fdefines)
X    fprintf(fdefines, "typedef union");
X
X  count = 0;
X  in_comment = 0;
X
X  c = getc(finput);
X
X  while (c != EOF)
X    {
X      putc(c, fattrs);
X      if (fdefines)
X	putc(c, fdefines);
X
X      switch (c)
X	{
X	case '\n':
X	  lineno++;
X	  break;
X
X	case '/':
X	  c = getc(finput);
X	  if (c != '*')
X	    ungetc(c, finput);
X	  else
X	    {
X	      putc('*', fattrs);
X	      if (fdefines)
X		putc('*', fdefines);
X	      c = getc(finput);
X	      in_comment = 1;
X	      while (in_comment)
X		{
X		  if (c == EOF)
X		    fatal("unterminated comment");
X
X		  putc(c, fattrs);
X		  if (fdefines)
X		    putc(c, fdefines);
X		  if (c == '*')
X		    {
X		      c = getc(finput);
X		      if (c == '/')
X			{
X			  putc('/', fattrs);
X			  if (fdefines)
X			    putc('/', fdefines);
X			  in_comment = 0;
X			}
X		    }
X		  else
X		    c = getc(finput);
X		}
X	    }
X	  break;
X
X
X	case '{':
X	  count++;
X	  break;
X
X	case '}':
X	  count--;
X	  if (count == 0)
X	    {
X	      fprintf(fattrs, " YYSTYPE;\n");
X	      if (fdefines)
X		fprintf(fdefines, " YYSTYPE;\n");
X	      /* JF don't choke on trailing semi */
X	      c=skip_white_space();
X	      if(c!=';') ungetc(c,finput);
X	      return;
X	    }
X	}
X
X      c = getc(finput);
X    }
X}
X
X/* parse the declaration %expect N which says to expect N
X   shift-reduce conflicts.  */
X
Xparse_expect_decl()
X{
X  register int c;
X  register int count;
X  char buffer[20];
X
X  c = getc(finput);
X  while (c == ' ' || c == '\t')
X    c = getc(finput);
X
X  count = 0;
X  while (c >= '0' && c <= '9')
X    {
X      if (count < 20)
X	buffer[count++] = c;
X      c = getc(finput);
X    }
X
X  while (c != EOF && c != '\n')
X    c = getc(finput);
X
X  expected_conflicts = atoi (buffer);
X}
X
X/* that's all of parsing the declaration section */
X
Xoutput_ltype()
X{
X  fprintf(fattrs, LTYPESTR);/* JF added YYABORT() */
X  if (fdefines)
X    fprintf(fdefines, LTYPESTR);/* JF added YYABORT() */
X
X  fprintf(fattrs, "#define\tYYACCEPT\treturn(0)\n");
X  fprintf(fattrs, "#define\tYYABORT\treturn(1)\n");
X  fprintf(fattrs, "#define\tYYERROR\treturn(1)\n");
X
X  if (fdefines)
X    {
X      fprintf(fdefines, "#define\tYYACCEPT\treturn(0)\n");
X      fprintf(fdefines, "#define\tYYABORT\treturn(1)\n");
X      fprintf(fdefines, "#define\tYYERROR\treturn(1)\n");
X    }
X}
X
X
X
X/* Get the data type (alternative in the union) of the value for symbol n in rule rule.  */
X
Xchar *
Xget_type_name(n, rule)
Xint n;
Xsymbol_list *rule;
X{
X  static char *msg = "invalid $ value";
X
X  register int i;
X  register symbol_list *rp;
X
X  if (n < 0)
X    fatal(msg);
X
X  rp = rule;
X  i = 0;
X
X  while (i < n)
X    {
X      rp = rp->next;
X      if (rp == NULL || rp->sym == NULL)
X	fatal(msg);
X      i++;
X    }
X
X  return (rp->sym->type_name);
X}
X
X
X
X/* after %guard is seen in the input file,
Xcopy the actual guard into the guards file.
XIf the guard is followed by an action, copy that into the actions file.
Xstack_offset is the number of values in the current rule so far,
Xwhich says where to find $0 with respect to the top of the stack,
Xfor the simple parser in which the stack is not popped until after the guard is run.  */
X
Xcopy_guard(rule, stack_offset)
Xsymbol_list *rule;
Xint stack_offset;
X{
X  register int c;
X  register int n;
X  register int count;
X  register int match;
X  register int ended;
X  register char *type_name;
X  extern char token_buffer[];
X
X  /* offset is always 0 if parser has already popped the stack pointer */
X  if (semantic_parser) stack_offset = 0;
X
X  fprintf(fguard, "\ncase %d:\n", nrules);
X  fprintf(fguard, "#line %d \"%s\"\n", lineno, infile);
X  putc('{', fguard);
X
X  count = 0;
X  c = getc(finput);
X
X  while (count > 0 || c != ';' && c != '{')
X    {
X      switch (c)
X	{
X	case '\n':
X	  putc(c, fguard);
X	  lineno++;
X	  break;
X
X	case '{':
X	  putc(c, fguard);
X	  count++;
X	  break;
X
X	case '}':
X	  putc(c, fguard);
X	  if (count > 0)
X	    count--;
X	  else
X	    fatal("unmatched right brace ('}')");
X
X	case '\'':
X	case '"':
X	  match = c;
X	  putc(c, fguard);
X	  c = getc(finput);
X
X	  while (c != match)
X	    {
X	      if (c == EOF || c == '\n')
X		fatal("unterminated string");
X
X	      putc(c, fguard);
X	      
X	      if (c == '\\')
X		{
X		  c = getc(finput);
X		  if (c == EOF || c == '\n')
X		    fatal("unterminated string");
X		  putc(c, fguard);
X		  if (c == '\n')
X		    lineno++;
X		}
X
X	      c = getc(finput);
X	    }
X
X	  putc(c, fguard);
X	  break;
X
X	case '/':
X	  putc(c, fguard);
X	  c = getc(finput);
X	  if (c != '*')
X	    continue;
X
X	  putc(c, fguard);
X	  c = getc(finput);
X
X	  ended = 0;
X	  while (!ended)
X	    {
X	      if (c == '*')
X		{
X		  while (c == '*')
X		    {
X		      putc(c, fguard);
X		      c = getc(finput);
X		    }
X
X		  if (c == '/')
X		    {
X		      putc(c, fguard);
X		      ended = 1;
X		    }
X		}
X	      else if (c == '\n')
X		{
X		  lineno++;
X		  putc(c, fguard);
X		  c = getc(finput);
X		}
X	      else if (c == EOF)
X		fatal("unterminated comment");
X	      else
X		{
X		  putc(c, fguard);
X		  c = getc(finput);
X		}
X	    }
X
X	  break;
X
X	case '$':
X	  c = getc(finput);
X	  type_name = NULL;
X
X	  if (c == '<')
X	    {
X	      register char *cp = token_buffer;
X
X	      while ((c = getc(finput)) != '>' && c > 0)
X		*cp++ = c;
X	      *cp = 0;
X	      type_name = token_buffer;
X
X	      c = getc(finput);
X	    }
X
X	  if (c == '$')
X	    {
X	      fprintf(fguard, "yyval");
X	      if (!type_name) type_name = rule->sym->type_name;
X	      if (type_name)
X		fprintf(fguard, ".%s", type_name);
X	      if(!type_name && typed)	/* JF */
X		fprintf(stderr,"%s:%d:  warning:  $$ of '%s' has no declared type.\n",infile,lineno,rule->sym->tag);
X	    }
X
X	  else if (isdigit(c) || c == '-')
X	    {
X	      ungetc (c, finput);
X	      n = read_signed_integer(finput);
X	      c = getc(finput);
X
X	      if (!type_name && n > 0)
X		type_name = get_type_name(n, rule);
X
X	      fprintf(fguard, "yyvsp[%d]", n - stack_offset);
X	      if (type_name)
X		fprintf(fguard, ".%s", type_name);
X	      if(!type_name && typed)	/* JF */
X		fprintf(stderr,"%s:%d:  warning:  $%d of '%s' has no declared type.\n",infile,lineno,n,rule->sym->tag);
X	      continue;
X	    }
X	  else
X	    fatals("$%c is invalid",c);	/* JF changed style */
X
X	  break;
X
X	case '@':
X	  c = getc(finput);
X	  if (isdigit(c) || c == '-')
X	    {
X	      ungetc (c, finput);
X	      n = read_signed_integer(finput);
X	      c = getc(finput);
X	    }
X	  else
X	    fatals("@%c is invalid",c);	/* JF changed style */
X
X	  fprintf(fguard, "yylsp[%d]", n - stack_offset);
X
X	  continue;
X
X	case EOF:
X	  fatal("unterminated %guard clause");
X
X	default:
X	  putc(c, fguard);
X	}
X
X      c = getc(finput);
X    }
X
X  fprintf(fguard, ";\n    break;}");
X  if (c == '{')
X    copy_action(rule, stack_offset);
X  else if (c == '=')
X    {
X      c = getc(finput);
X      if (c == '{')
X	copy_action(rule, stack_offset);
X    }
X
X}
X
X
X
X/* Assuming that a { has just been seen, copy everything up to the matching }
Xinto the actions file.
Xstack_offset is the number of values in the current rule so far,
Xwhich says where to find $0 with respect to the top of the stack.  */
X
Xcopy_action(rule, stack_offset)
Xsymbol_list *rule;
Xint stack_offset;
X{
X  register int c;
X  register int n;
X  register int count;
X  register int match;
X  register int ended;
X  register char *type_name;
X  extern char token_buffer[];
X
X  /* offset is always 0 if parser has already popped the stack pointer */
X  if (semantic_parser) stack_offset = 0;
X
X  fprintf(faction, "\ncase %d:\n", nrules);
X  fprintf(faction, "#line %d \"%s\"\n", lineno, infile);
X  putc('{', faction);
X
X  count = 1;
X  c = getc(finput);
X
X  while (count > 0)
X    {
X      while (c != '}')
X        {
X          switch (c)
X	    {
X	    case '\n':
X	      putc(c, faction);
X	      lineno++;
X	      break;
X
X	    case '{':
X	      putc(c, faction);
X	      count++;
X	      break;
X
X	    case '\'':
X	    case '"':
X	      match = c;
X	      putc(c, faction);
X	      c = getc(finput);
X
X	      while (c != match)
X		{
X		  if (c == EOF || c == '\n')
X		    fatal("unterminated string");
X
X		  putc(c, faction);
X
X		  if (c == '\\')
X		    {
X		      c = getc(finput);
X		      if (c == EOF)
X			fatal("unterminated string");
X		      putc(c, faction);
X		      if (c == '\n')
X			lineno++;
X		    }
X
X		  c = getc(finput);
X		}
X
X	      putc(c, faction);
X	      break;
X
X	    case '/':
X	      putc(c, faction);
X	      c = getc(finput);
X	      if (c != '*')
X		continue;
X
X	      putc(c, faction);
X	      c = getc(finput);
X
X	      ended = 0;
X	      while (!ended)
X		{
X		  if (c == '*')
X		    {
X		      while (c == '*')
X		        {
X			  putc(c, faction);
X			  c = getc(finput);
X			}
X
X		      if (c == '/')
X			{
X			  putc(c, faction);
X			  ended = 1;
X			}
X		    }
X		  else if (c == '\n')
X		    {
X		      lineno++;
X		      putc(c, faction);
X		      c = getc(finput);
X		    }
X		  else if (c == EOF)
X		    fatal("unterminated comment");
X		  else
X		    {
X		      putc(c, faction);
X		      c = getc(finput);
X		    }
X		}
X
X	      break;
X
X	    case '$':
X	      c = getc(finput);
X	      type_name = NULL;
X
X	      if (c == '<')
X		{
X		  register char *cp = token_buffer;
X
X		  while ((c = getc(finput)) != '>' && c > 0)
X		    *cp++ = c;
X		  *cp = 0;
X		  type_name = token_buffer;
X
X		  c = getc(finput);
X		}
X	      if (c == '$')
X		{
X		  fprintf(faction, "yyval");
X		  if (!type_name) type_name = get_type_name(0, rule);
X		  if (type_name)
X		    fprintf(faction, ".%s", type_name);
X		  if(!type_name && typed)	/* JF */
X		    fprintf(stderr,"%s:%d:  warning:  $$ of '%s' has no declared type.\n",infile,lineno,rule->sym->tag);
X		}
X	      else if (isdigit(c) || c == '-')
X		{
X		  ungetc (c, finput);
X		  n = read_signed_integer(finput);
X		  c = getc(finput);
X
X		  if (!type_name && n > 0)
X		    type_name = get_type_name(n, rule);
X
X		  fprintf(faction, "yyvsp[%d]", n - stack_offset);
X		  if (type_name)
X		    fprintf(faction, ".%s", type_name);
X		  if(!type_name && typed)	/* JF */
X		    fprintf(stderr,"%s:%d:  warning:  $%d of '%s' has no declared type.\n",infile,lineno,n,rule->sym->tag);
X		  continue;
X		}
X	      else
X		fatal("$%c is invalid",c);	/* JF changed format */
X
X	      break;
X
X	    case '@':
X	      c = getc(finput);
X	      if (isdigit(c) || c == '-')
X		{
X		  ungetc (c, finput);
X		  n = read_signed_integer(finput);
X		  c = getc(finput);
X		}
X	      else
X		fatal("invalid @-construct");
X
X	      fprintf(faction, "yylsp[%d]", n - stack_offset);
X
X	      continue;
X
X	    case EOF:
X	      fatal("unmatched '{'");
X
X	    default:
X	      putc(c, faction);
X	    }
X
X          c = getc(finput);
X        }
X
X      /* above loop exits when c is '}' */
X
X      if (--count)
X        {
X	  putc(c, faction);
X	  c = getc(finput);
X	}
X    }
X
X  fprintf(faction, ";\n    break;}");
X}
X
X
X
X/* generate a dummy symbol, a nonterminal,
Xwhose name cannot conflict with the user's names. */
X
Xbucket *
Xgensym()
X{
X  register bucket *sym;
X
X  extern char token_buffer[];
X  sprintf (token_buffer, "@%d", ++gensym_count);
X  sym = getsym(token_buffer);
X  sym->class = SNTERM;
X  sym->value = nvars++;
X  return (sym);
X}
X
X
X
X/* Parse the input grammar into a one symbol_list structure.
XEach rule is represented by a sequence of symbols: the left hand side
Xfollowed by the contents of the right hand side, followed by a null pointer
Xinstead of a symbol to terminate the rule.
XThe next symbol is the lhs of the following rule.
X
XAll guards and actions are copied out to the appropriate files,
Xlabelled by the rule number they apply to.  */
X
Xreadgram()
X{
X  register int t;
X  register bucket *lhs;
X  register symbol_list *p;
X  register symbol_list *p1;
X  register bucket *bp;
X
X  symbol_list *crule;	/* points to first symbol_list of current rule.  */
X			/* its symbol is the lhs of the rule.   */
X  symbol_list *crule1;  /* points to the symbol_list preceding crule.  */
X
X  p1 = NULL;
X
X  t = lex();
X
X  while (t != TWO_PERCENTS && t != ENDFILE)
X    {
X      if (t == IDENTIFIER || t == BAR)
X	{
X	  register int actionflag = 0;
X	  int rulelength = 0;  /* number of symbols in rhs of this rule so far  */
X	  int xactions = 0;	/* JF for error checking */
X	  bucket *first_rhs = 0;
X
X	  if (t == IDENTIFIER)
X	    {
X	      lhs = symval;
X    
X	      t = lex();
X	      if (t != COLON)
X		fatal("ill-formed rule");
X	    }
X
X	  if (nrules == 0)
X	    {
X	      if (t == BAR)
X		fatal("grammar starts with vertical bar");
X
X	      if (!start_flag)
X		startval = lhs;
X	    }
X
X	  /* start a new rule and record its lhs.  */
X
X	  nrules++;
X	  nitems++;
X
X	  record_rule_line ();
X
X	  p = NEW(symbol_list);
X	  p->sym = lhs;
X
X	  crule1 = p1;
X	  if (p1)
X	    p1->next = p;
X	  else
X	    grammar = p;
X
X	  p1 = p;
X	  crule = p;
X
X	  /* mark the rule's lhs as a nonterminal if not already so.  */
X
X	  if (lhs->class == SUNKNOWN)
X	    {
X	      lhs->class = SNTERM;
X	      lhs->value = nvars;
X	      nvars++;
X	    }
X	  else if (lhs->class == STOKEN)
X	    fatals("rule given for %s, which is a token", lhs->tag);
X
X	  /* read the rhs of the rule.  */
X
X	  for (;;)
X	    {
X	      t = lex();
X
X	      if (! (t == IDENTIFIER || t == LEFT_CURLY)) break;
X
X	      /* if next token is an identifier, see if a colon follows it.
X		 If one does, exit this rule now.  */
X	      if (t == IDENTIFIER)
X		{
X		  register bucket *ssave;
X		  register int t1;
X
X		  ssave = symval;
X		  t1 = lex();
X		  unlex(t1);
X		  symval = ssave;
X		  if (t1 == COLON) break;
X
X		  if(!first_rhs)	/* JF */
X		  	first_rhs = symval;
X		  /* not followed by colon => process as part of this rule's rhs.  */
X		  if (actionflag)
X		    {
X		      register bucket *sdummy;
X
X		      /* if this symbol was preceded by an action, */
X		      /* make a dummy nonterminal to replace that action in this rule */
X		      /* and make another rule to associate the action to the dummy.  */
X		      /* Since the action was written out with this rule's number, */
X		      /* we must write give the new rule this number */
X		      /* by inserting the new rule before it.  */
X
X		      /* make a dummy nonterminal, a gensym.  */
X		      sdummy = gensym();
X
X		      /* make a new rule, whose body is empty, before the current one.  */
X		      /* so that the action just read can belong to it.  */
X		      nrules++;
X		      nitems++;
X		      record_rule_line ();
X		      p = NEW(symbol_list);
X		      if (crule1)
X			crule1->next = p;
X		      else grammar = p;
X		      p->sym = sdummy;
X		      crule1 = NEW(symbol_list);
X		      p->next = crule1;
X		      crule1->next = crule;
X		      
X		      /* insert the dummy generated by that rule into this rule.  */
X		      nitems++;
X		      p = NEW(symbol_list);
X		      p->sym = sdummy;
X		      p1->next = p;
X		      p1 = p;
X
X		      actionflag = 0;
X		    }
X		  nitems++;
X		  p = NEW(symbol_list);
X		  p->sym = symval;
X		  p1->next = p;
X		  p1 = p;
X		}
X	      else /* handle an action.  */
X		{
X		  copy_action(crule, rulelength);
X		  actionflag = 1;
X		  xactions++;	/* JF */
X		}
X	      rulelength++;
X	    }
X
X	  /* Put an empty link in the list to mark the end of this rule  */
X	  p = NEW(symbol_list);
X	  p1->next = p;
X	  p1 = p;
X
X	  if (t == PREC)
X	    {
X	      t = lex();
X	      crule->ruleprec = symval;
X	      t = lex();
X	    }
X	  if (t == GUARD)
X	    {
X	      if (! semantic_parser)
X		fatal("%guard present but %semantic_parser not specified");
X
X	      copy_guard(crule, rulelength);
X	      t = lex();
X	    }
X	  else if (t == LEFT_CURLY)
X	    {
X	      if (actionflag) fatal("two actions at end of one rule");
X	      copy_action(crule, rulelength);
X	      t = lex();
X	    }
X	  /* JF if we'd end up using default, get a warning */
X	  else if(!xactions && first_rhs && lhs->type_name!=first_rhs->type_name) {
X	    if(lhs->type_name == 0 || first_rhs->type_name == 0 ||
X				      strcmp(lhs->type_name,first_rhs->type_name))
X	      fprintf(stderr,"%s:%d:  warning:  type clash ('%s' '%s') on default action\n",
X		      infile,
X		      lineno,
X		      lhs->type_name ? lhs->type_name : "",
X		      first_rhs->type_name ? first_rhs->type_name : "");
X	  }
X	  if (t == SEMICOLON)
X	    t = lex();
X	}
X      /* these things can appear as alternatives to rules.  */
X      else if (t == TOKEN)
X	{
X	  parse_token_decl(STOKEN, SNTERM);
X	  t = lex();
X	}
X      else if (t == NTERM)
X	{
X	  parse_token_decl(SNTERM, STOKEN);
X	  t = lex();
X	}
X      else if (t == TYPE)
X	{
X	  t = get_type();
X	}
X      else if (t == UNION)
X	{
X	  parse_union_decl();
X	  t = lex();
X	}
X      else if (t == EXPECT)
X	{
X	  parse_expect_decl();
X	  t = lex();
X	}
X      else if (t == START)
X	{
X	  parse_start_decl();
X	  t = lex();
X	}
X      else
X	fatal("invalid input");
X    }
X
X  if (nrules == 0)
X    fatal("no input grammar");
X
X  if (typed == 0)/* JF put out same default YYSTYPE as YACC does */
X    {
X      fprintf(fattrs, "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
X      if (fdefines)
X	fprintf(fdefines, "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
X    }
X
X  /* Report any undefined symbols and consider them nonterminals.  */
X
X  for (bp = firstsymbol; bp; bp = bp->next)
X    if (bp->class == SUNKNOWN)
X      {
X	fprintf(stderr, "symbol %s used, not defined as token, and no rules for it\n",
X			bp->tag);
X	failure = 1;
X	bp->class = SNTERM;
X	bp->value = nvars++;
X      }
X
X  ntokens = nsyms - nvars;
X}
X
X
Xrecord_rule_line ()
X{
X  /* Record each rule's source line number in rline table.  */
X
X  if (nrules >= rline_allocated)
X    {
X      rline_allocated = nrules * 2;
X      rline = (short *) realloc (rline,
X				 rline_allocated * sizeof (short));
X      if (rline == 0)
X	{
X	  fprintf (stderr, "bison: memory exhausted\n");
X	  done (1);
X	}
X    }
X  rline[nrules] = lineno;
X}
X
X
X/* read in a %type declaration and record its information for get_type_name to access */
X
Xint
Xget_type()
X{
X  register int k;
X  register int t;
X  register char *name;
X
X  extern char token_buffer[];
X
X  t = lex();
X
X  if (t != TYPENAME)
X    fatal("ill-formed %type declaration");
X
X  k = strlen(token_buffer);
X  name = NEW2(k + 1, char);
X  strcpy(name, token_buffer);
X
X  for (;;)
X    {
X      t = lex();
X
X      switch (t)
X	{
X	case SEMICOLON:
X	  return (lex());
X
X	case COMMA:
X	  break;
X
X	case IDENTIFIER:
X	  if (symval->type_name == NULL)
X	    symval->type_name = name;
X	  else
X	    fatals("type redeclaration for %s", symval->tag);
X
X	  break;
X
X	default:
X	  return (t);
X	}
X    }
X}
X
X
X
X/* assign symbol numbers, and write definition of token names into fdefines.
XSet up vectors tags and sprec of names and precedences of symbols.  */
X
Xpacksymbols()
X{
X  register bucket *bp;
X  register int tokno = 1;
X  register int i;
X  register int last_user_token_number;
X
X  /* int lossage = 0; JF set but not used */
X
X  tags = NEW2(nsyms + 1, char *);
X  tags[0] = "$";
X
X  sprec = NEW2(nsyms, short);
X  sassoc = NEW2(nsyms, short);
X
X  max_user_token_number = 255;
X  last_user_token_number = 255;
X
X  for (bp = firstsymbol; bp; bp = bp->next)
X    {
X      if (bp->class == SNTERM)
X	{
X	  bp->value += ntokens;
X	}
X      else
X	{
X	  if (translations && !(bp->user_token_number))
X	    bp->user_token_number = ++last_user_token_number;
X	  if (bp->user_token_number > max_user_token_number)
X	    max_user_token_number = bp->user_token_number;
X	  bp->value = tokno++;
X	}
X
X      tags[bp->value] = bp->tag;
X      sprec[bp->value] = bp->prec;
X      sassoc[bp->value] = bp->assoc;
X
X    }
X
X  if (translations)
X    {
X      register int i;
X
X      token_translations = NEW2(max_user_token_number+1, short);
X
X      /* initialize all entries for literal tokens to 2,
X	 the internal token number for $illegal., which represents all invalid inputs.  */
X      for (i = 0; i <= max_user_token_number; i++)
X        token_translations[i] = 2;      
X    }
X
X  for (bp = firstsymbol; bp; bp = bp->next)
X    {
X      if (bp->value >= ntokens) continue;
X      if (translations)
X	{
X	  if (token_translations[bp->user_token_number] != 2)
X	    {
X	    	/* JF made this a call to fatals() */
X	      fatals( "tokens %s and %s both assigned number %d",
X			      tags[token_translations[bp->user_token_number]],
X			      bp->tag,
X			      bp->user_token_number);
X	    }
X	  token_translations[bp->user_token_number] = bp->value;
X	}
X    }
X
X  error_token_number = errtoken->value;
X
X  output_token_defines(ftable);
X
X  if (startval->class == SUNKNOWN)
X    fatals("the start symbol %s is undefined", startval->tag);
X  else if (startval->class == STOKEN)
X    fatals("the start symbol %s is a token", startval->tag);
X
X  start_symbol = startval->value;
X
X  if (definesflag)
X    {
X      output_token_defines(fdefines);
X
X      if (semantic_parser)
X	for (i = ntokens; i < nsyms; i++)
X	  {
X	    /* don't make these for dummy nonterminals made by gensym.  */
X	    if (*tags[i] != '@')
X	      fprintf(fdefines, "#define\tNT%s\t%d\n", tags[i], i);
X	  }
X
X      fclose(fdefines);
X      fdefines = NULL;
X    }
X}
X      
X
Xoutput_token_defines(file)
XFILE *file;
X{
X  bucket *bp;
X
X  for (bp = firstsymbol; bp; bp = bp->next)
X    {
X      if (bp->value >= ntokens) continue;
X
X      /* For named tokens, but not literal ones, define the name.  */
X      /* The value is the user token number.  */
X
X      if ('\'' != *tags[bp->value] && bp != errtoken)
X	{
X	  register char *cp = tags[bp->value];
X	  register char c;
X
X	  /* Don't #define nonliteral tokens whose names contain periods.  */
X
X	  while ((c = *cp++) && c != '.');
X	  if (!c)
X	    {
X              fprintf(file, "#define\t%s\t%d\n", tags[bp->value],
X			    (translations ? bp->user_token_number : bp->value));
X	      if (semantic_parser)
X                fprintf(file, "#define\tT%s\t%d\n", tags[bp->value],
X			      bp->value);
X	    }
X	}
X    }
X
X  putc('\n', file);
X}
X
X
X
X/* convert the rules into the representation using rrhs, rlhs and ritems.  */
X
Xpackgram()
X{
X  register int itemno;
X  register int ruleno;
X  register symbol_list *p;
X/*  register bucket *bp; JF unused */
X
X  bucket *ruleprec;
X
X  ritem = NEW2(nitems + 1, short);
X  rlhs = NEW2(nrules, short) - 1;
X  rrhs = NEW2(nrules, short) - 1;
X  rprec = NEW2(nrules, short) - 1;
X  rassoc = NEW2(nrules, short) - 1;
X
X  itemno = 0;
X  ruleno = 1;
X
X  p = grammar;
X  while (p)
X    {
X      rlhs[ruleno] = p->sym->value;
X      rrhs[ruleno] = itemno;
X      ruleprec = p->ruleprec;
X
X      p = p->next;
X      while (p && p->sym)
X	{
X	  ritem[itemno++] = p->sym->value;
X	  /* a rule gets the precedence and associativity of the last token in it.  */
X          if (p->sym->class == STOKEN)
X	    {
X	      rprec[ruleno] = p->sym->prec;
X	      rassoc[ruleno] = p->sym->assoc;
X	    }
X	  if (p) p = p->next;
X	}
X
X      /* if this rule has a %prec, specified symbol's precedence replaces the default */
X      if (ruleprec)
X	{
X          rprec[ruleno] = ruleprec->prec;
X          rassoc[ruleno] = ruleprec->assoc;
X	}
X
X      ritem[itemno++] = -ruleno;
X      ruleno++;
X
X      if (p) p = p->next;
X    }
X
X  ritem[itemno] = 0;
X}
X
X/* Read a signed integer from STREAM and return its value.  */
X
Xread_signed_integer (stream)
X     FILE *stream;
X{
X  register int c = getc(stream);
X  register int sign = 1;
X  register int n;
X
X  if (c == '-')
X    {
X      c = getc(stream);
X      sign = -1;
X    }
X  n = 0;
X  while (isdigit(c))
X    {
X      n = 10*n + (c - '0');
X      c = getc(stream);
X    }
X
X  ungetc(c, stream);
X
X  return n * sign;
X}
SHAR_EOF
if test 34877 -ne "`wc -c < 'reader.c'`"
then
	echo shar: error transmitting "'reader.c'" '(should have been 34877 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
--- end of part 5 ---

wetter@tybalt.caltech.edu (Pierce T. Wetter) (05/19/88)

[Bison Macintosh Sources - part 6 of 6]

---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	Bison/symtab.c
#	Bison/vmsgetargs.c
#	Bison/warshall.c
#	Bison/file.h
#	Bison/gram.h
#	Bison/lex.h
#	Bison/machine.h
#	Bison/new.h
#	Bison/state.h
#	Bison/symtab.h
#	Bison/types.h
# This archive created: Sat May 14 02:42:08 1988
# By:	Roger L. Long (bytebug@dhw68k.cts.com)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'symtab.c'" '(2628 characters)'
if test -f 'symtab.c'
then
	echo shar: will not over-write existing file "'symtab.c'"
else
sed 's/^X//' << \SHAR_EOF > 'symtab.c'
X/* Symbol table manager for Bison,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#include <stdio.h>
X#include <strings.h>
X#include "new.h"
X#include "symtab.h"
X#include "gram.h"
X
X
Xbucket **symtab;
Xbucket *firstsymbol;
Xbucket *lastsymbol;
X
X
X
Xint
Xhash(key)
Xchar *key;
X{
X  register char *cp;
X  register int k;
X
X  cp = key;
X  k = 0;
X  while (*cp)
X    k = ((k << 1) ^ (*cp++)) & 0x3fff;
X
X  return (k % TABSIZE);
X}
X
X
X
Xchar *
Xcopys(s)
Xchar *s;
X{
X  register int i;
X  register char *cp;
X  register char *result;
X
X  i = 1;
X  for (cp = s; *cp; cp++)
X    i++;
X
X  result =  allocate((unsigned int)i);
X  strcpy(result, s);
X  return (result);
X}
X
X
X
Xtabinit()
X{
X/*   register int i; JF unused */
X
X  symtab = NEW2(TABSIZE, bucket *);
X
X  firstsymbol = NULL;
X  lastsymbol = NULL;
X}
X
X
X
X
Xbucket *getsym(key)
Xchar *key;
X{
X  register int hashval;
X  register bucket *bp;
X  register int found;
X
X  hashval = hash(key);
X  bp = symtab[hashval];
X
X  found = 0;
X  while (bp != NULL && found == 0)
X    {
X      if (strcmp(key, bp->tag) == 0)
X	found = 1;
X      else
X	bp = bp->link;
X    }
X
X  if (found == 0)
X    {
X      nsyms++;
X
X      bp = NEW(bucket);
X      bp->link = symtab[hashval];
X      bp->next = NULL;
X      bp->tag = copys(key);
X      bp->class = SUNKNOWN;
X
X      if (firstsymbol == NULL)
X	{
X	  firstsymbol = bp;
X	  lastsymbol = bp;
X	}
X      else
X	{
X	  lastsymbol->next = bp;
X	  lastsymbol = bp;
X	}
X
X      symtab[hashval] = bp;
X    }
X
X  return (bp);
X}
X
X
X
Xfree_symtab()
X{
X  register int i;
X  register bucket *bp,*bptmp;/* JF don't use ptr after free */
X
X  for (i = 0; i < TABSIZE; i++)
X    {
X      bp = symtab[i];
X      while (bp)
X	{
X	  bptmp=bp->link;
X	  FREE(bp);
X	  bp = bptmp;
X	}
X    }
X}
SHAR_EOF
if test 2628 -ne "`wc -c < 'symtab.c'`"
then
	echo shar: error transmitting "'symtab.c'" '(should have been 2628 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'vmsgetargs.c'" '(1446 characters)'
if test -f 'vmsgetargs.c'
then
	echo shar: will not over-write existing file "'vmsgetargs.c'"
else
sed 's/^X//' << \SHAR_EOF > 'vmsgetargs.c'
X/*
X *	VMS version of getargs(): Uses DCL command parsing
X *		(argc and argv are ignored)
X */
Xgetargs(argc,argv)
X     int argc;
X     char *argv[];
X{
X  register char *cp;
X  static char Input_File[256];
X
X  verboseflag = 0;
X  definesflag = 0;
X  /*
X   *	Check for /VERBOSE qualifier
X   */
X  if (cli_present("BISON$VERBOSE")) verboseflag = 1;
X  /*
X   *	Check for /DEFINES qualifier
X   */
X  if (cli_present("BISON$DEFINES")) definesflag = 1;
X  /*
X   *	Check for /FIXED_OUTFILES qualifier
X   */
X  if (cli_present("BISON$FIXED_OUTFILES")) fixed_outfiles = 1;
X  /*
X   *	Get the filename
X   */
X  cli_get_value("BISON$INFILE", Input_File, sizeof(Input_File));
X  /*
X   *	Lowercaseify the input filename
X   */
X  cp = Input_File;
X  while(*cp) {
X    if (isupper(*cp)) *cp = tolower(*cp);
X    cp++;
X  }
X  infile = Input_File;
X}
X
X/************		DCL PARSING ROUTINES		**********/
X
X/*
X *	See if "NAME" is present
X */
Xint
Xcli_present(Name)
X     char *Name;
X{
X  struct {int Size; char *Ptr;} Descr;
X
X  Descr.Ptr = Name;
X  Descr.Size = strlen(Name);
X  return((cli$present(&Descr) & 1) ? 1 : 0);
X}
X
X/*
X *	Get value of "NAME"
X */
Xint
Xcli_get_value(Name,Buffer,Size)
X     char *Name;
X     char *Buffer;
X{
X  struct {int Size; char *Ptr;} Descr1,Descr2;
X
X  Descr1.Ptr = Name;
X  Descr1.Size = strlen(Name);
X  Descr2.Ptr = Buffer;
X  Descr2.Size = Size-1;
X  if (cli$get_value(&Descr1,&Descr2,&Descr2.Size) & 1) {
X    Buffer[Descr2.Size] = 0;
X    return(1);
X  }
X  return(0);
X}
X
SHAR_EOF
if test 1446 -ne "`wc -c < 'vmsgetargs.c'`"
then
	echo shar: error transmitting "'vmsgetargs.c'" '(should have been 1446 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'warshall.c'" '(2652 characters)'
if test -f 'warshall.c'
then
	echo shar: will not over-write existing file "'warshall.c'"
else
sed 's/^X//' << \SHAR_EOF > 'warshall.c'
X/* Generate transitive closure of a matrix,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#include <stdio.h>
X#include "machine.h"
X
X
X/* given n by n matrix of bits R, modify its contents
X   to be the transive closure of what was given.  */
X
XTC(R, n)
Xunsigned *R;
Xint n;
X{
X  register int rowsize;
X  register unsigned mask;
X  register unsigned *rowj;
X  register unsigned *rp;
X  register unsigned *rend;
X  register unsigned *ccol;
X
X  unsigned *relend;
X  unsigned *cword;
X  unsigned *rowi;
X
X  rowsize = WORDSIZE(n) * sizeof(unsigned);
X  relend = (unsigned *) ((char *) R + (n * rowsize));
X
X  cword = R;
X  mask = 1;
X  rowi = R;
X  while (rowi < relend)
X    {
X      ccol = cword;
X      rowj = R;
X
X      while (rowj < relend)
X	{
X	  if (*ccol & mask)
X	    {
X	      rp = rowi;
X	      rend = (unsigned *) ((char *) rowj + rowsize);
X
X	      while (rowj < rend)
X		*rowj++ |= *rp++;
X	    }
X	  else
X	    {
X	      rowj = (unsigned *) ((char *) rowj + rowsize);
X	    }
X
X	  ccol = (unsigned *) ((char *) ccol + rowsize);
X	}
X
X      mask <<= 1;
X      if (mask == 0)
X	{
X	  mask = 1;
X	  cword++;
X	}
X
X      rowi = (unsigned *) ((unsigned) rowi + rowsize);
X    }
X}
X
X
X/* Reflexive Transitive Closure.  Same as TC
X   and then set all the bits on the diagonal of R.  */
X
XRTC(R, n)
Xunsigned *R;
Xint n;
X{
X  register int rowsize;
X  register unsigned mask;
X  register unsigned *rp;
X  register unsigned *relend;
X
X  TC(R, n);
X
X  rowsize = WORDSIZE(n) * sizeof(unsigned);
X  relend = (unsigned *) ((unsigned) R + n*rowsize);
X
X  mask = 1;
X  rp = R;
X  while (rp < relend)
X    {
X      *rp |= mask;
X
X      mask <<= 1;
X      if (mask == 0)
X	{
X	  mask = 1;
X	  rp++;
X	}
X
X      rp = (unsigned *) ((unsigned) rp + rowsize);
X    }
X}
SHAR_EOF
if test 2652 -ne "`wc -c < 'warshall.c'`"
then
	echo shar: error transmitting "'warshall.c'" '(should have been 2652 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'file.h'" '(2374 characters)'
if test -f 'file.h'
then
	echo shar: will not over-write existing file "'file.h'"
else
sed 's/^X//' << \SHAR_EOF > 'file.h'
X/* File names and variables for bison,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* These two should be pathnames for opening the sample parser files.
X   When bison is installed, they should be absolute pathnames.
X   XPFILE1 and XPFILE2 normally come from the Makefile.  */
X
X#define PFILE	"bison.simple"		/* Simple parser */
X#define PFILE1	"bison.hairy"		/* Semantic parser */
X
Xextern FILE *finput;   /* read grammar specifications */
Xextern FILE *foutput;  /* optionally output messages describing the actions taken */
Xextern FILE *fdefines; /* optionally output #define's for token numbers. */
Xextern FILE *ftable;   /* output the tables and the parser */
Xextern FILE *fattrs;   /* if semantic parser, output a .h file that defines YYSTYPE */
X		       /* and also contains all the %{ ... %} definitions.  */
Xextern FILE *fguard;   /* if semantic parser, output yyguard, containing all the guard code */
Xextern FILE *faction;  /* output all the action code; precise form depends on which parser */
Xextern FILE *fparser;  /* read the parser to copy into ftable */
X
X/* File name specified with -o for the output file, or 0 if no -o.  */
Xextern char *spec_outfile;
X
Xextern char *infile;
Xextern char *outfile;
Xextern char *defsfile;
Xextern char *tabfile;
Xextern char *attrsfile;
Xextern char *guardfile;
Xextern char *actfile;
X/* JF nobody seems to care about these
Xextern char *pfile;
Xextern char *pfile1; */
SHAR_EOF
if test 2374 -ne "`wc -c < 'file.h'`"
then
	echo shar: error transmitting "'file.h'" '(should have been 2374 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'gram.h'" '(4280 characters)'
if test -f 'gram.h'
then
	echo shar: will not over-write existing file "'gram.h'"
else
sed 's/^X//' << \SHAR_EOF > 'gram.h'
X/* Data definitions for internal representation of bison's input,
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* representation of the grammar rules:
X
Xntokens is the number of tokens, and nvars is the number of variables (nonterminals).
Xnsyms is the total number, ntokens + nvars.
X
XEach symbol (either token or variable) receives a symbol number.
XNumbers 0 to ntokens-1 are for tokens, and ntokens to nsyms-1 are for variables.
XSymbol number zero is the end-of-input token.  This token is counted in ntokens.
X
XThe rules receive rule numbers 1 to nrules in the order they are written.
XActions and guards are accessed via the rule number.
X
XThe rules themselves are described by three arrays: rrhs, rlhs and ritems.
Xrlhs[r] is the symbol number of the left hand side of rule r.
XThe right hand side is stored as symbol numbers in a portion of ritems.
Xrrhs[r] contains the index in ritems of the beginning of the portion for rule r.
XThe length of the portion is one greater
X than the number of symbols in the rule's right hand side.
XThe last element in the portion contains minus r, which
Xidentifies it as the end of a portion and says which rule it is for.
X
XThe portions of ritems come in order of increasing rule number and are
Xfollowed by an element which is zero to mark the end.  nitems is the
Xtotal length of ritems, not counting the final zero.  Each element of
Xritems is called an "item" and its index in ritems is an item number.
X
XItem numbers are used in the finite state machine to represent
Xplaces that parsing can get to.
X
XPrecedence levels are recorded in the vectors sprec and rprec.
Xsprec records the precedence level of each symbol,
Xrprec the precedence level of each rule.
X
XPrecedence levels are assigned in increasing order starting with 1
Xso that numerically higher precedence values mean tighter binding
Xas they ought to.  Zero as a symbol or rule's precedence means none is assigned.
X
XAssociativities are recorded similarly in rassoc and sassoc.  */
X
X
X#define	ISTOKEN(s)	((s) < ntokens)
X#define	ISVAR(s)	((s) >= ntokens)
X
X
Xextern int nitems;
Xextern int nrules;
Xextern int nsyms;
Xextern int ntokens;
Xextern int nvars;
X
Xextern short *ritem;
Xextern short *rlhs;
Xextern short *rrhs;
Xextern short *rprec;
Xextern short *sprec;
Xextern short *rassoc;
Xextern short *sassoc;
Xextern short *rline;		/* Source line number of each rule */
X
Xextern int start_symbol;
X
X
X/* associativity values in elements of rassoc, sassoc.  */
X
X#define RIGHT_ASSOC 1
X#define LEFT_ASSOC 2
X#define NON_ASSOC 3
X
X/* token translation table:
Xindexed by a token number as returned by the user's yylex routine,
Xit yields the internal token number used by the parser and throughout bison.
XIf translations is zero, the translation table is not used because
Xthe two kinds of token numbers are the same.  */
X
Xextern short *token_translations;
Xextern int translations;
Xextern int max_user_token_number;
X
X/* semantic_parser is nonzero if the input file says to use the hairy parser
Xthat provides for semantic error recovery.  If it is zero, the yacc-compatible
Xsimplified parser is used.  */
X
Xextern int semantic_parser;
X
X/* pure_parser is nonzero if should generate a parser that is all pure and reentrant. */
X
Xextern int pure_parser;
X
X/* error_token_number is the token number of the error token.  */
X
Xextern int error_token_number;
SHAR_EOF
if test 4280 -ne "`wc -c < 'gram.h'`"
then
	echo shar: error transmitting "'gram.h'" '(should have been 4280 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'lex.h'" '(1649 characters)'
if test -f 'lex.h'
then
	echo shar: will not over-write existing file "'lex.h'"
else
sed 's/^X//' << \SHAR_EOF > 'lex.h'
X/* Token type definitions for bison's input reader,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#define	ENDFILE		0
X#define	IDENTIFIER	1
X#define	COMMA		2
X#define COLON		3
X#define	SEMICOLON	4
X#define	BAR		5
X#define LEFT_CURLY	6
X#define TWO_PERCENTS	7
X#define PERCENT_LEFT_CURLY	8
X#define	TOKEN		9
X#define	NTERM		10
X#define GUARD	       11
X#define	TYPE	       12
X#define	UNION	       13
X#define START	       14
X#define LEFT	       15
X#define RIGHT	       16
X#define NONASSOC       17
X#define PREC	       18
X#define SEMANTIC_PARSER 19
X#define PURE_PARSER    20
X#define TYPENAME       21
X#define NUMBER	       22
X#define EXPECT	       23
X#define	ILLEGAL	       24
X
X#define	MAXTOKEN	1024
SHAR_EOF
if test 1649 -ne "`wc -c < 'lex.h'`"
then
	echo shar: error transmitting "'lex.h'" '(should have been 1649 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'machine.h'" '(1218 characters)'
if test -f 'machine.h'
then
	echo shar: will not over-write existing file "'machine.h'"
else
sed 's/^X//' << \SHAR_EOF > 'machine.h'
X/* Define machine-dependencies for bison,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#define	MAXSHORT	32767
X#define	MINSHORT	-32768
X
X#define	BITS_PER_WORD	32
X#define	WORDSIZE(n)	(((n) + 31) / 32)
X#define	SETBIT(x, i)	((x)[(i)>>5] |= (1<<((i) & 31)))
SHAR_EOF
if test 1218 -ne "`wc -c < 'machine.h'`"
then
	echo shar: error transmitting "'machine.h'" '(should have been 1218 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'new.h'" '(1246 characters)'
if test -f 'new.h'
then
	echo shar: will not over-write existing file "'new.h'"
else
sed 's/^X//' << \SHAR_EOF > 'new.h'
X/* Storage allocation interface for bison,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#define	NEW(t)		((t *) allocate((unsigned) sizeof(t)))
X#define	NEW2(n, t)	((t *) allocate((unsigned) ((n) * sizeof(t))))
X
X#define	FREE(x)		(x && free((char *) (x)))
X
X
Xextern	char *allocate();
SHAR_EOF
if test 1246 -ne "`wc -c < 'new.h'`"
then
	echo shar: error transmitting "'new.h'" '(should have been 1246 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'state.h'" '(4951 characters)'
if test -f 'state.h'
then
	echo shar: will not over-write existing file "'state.h'"
else
sed 's/^X//' << \SHAR_EOF > 'state.h'
X/* Type definitions for nondeterministic finite state machine for bison,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* These type definitions are used to represent a nondeterministic
X   finite state machine that parses the specified grammar.
X   This information is generated by the function generate_states
X   in the file LR0.
X
XEach state of the machine is described by a set of items --
Xparticular positions in particular rules -- that are the possible
Xplaces where parsing could continue when the machine is in this state.
XThese symbols at these items are the allowable inputs that can follow now.
X
XA core represents one state.  States are numbered in the number field.
XWhen generate_states is finished, the starting state is state 0
Xand nstates is the number of states.  (A transition to a state
Xwhose state number is nstates indicates termination.)  All the cores
Xare chained together and first_state points to the first one (state 0).
X
XFor each state there is a particular symbol which must have been the
Xlast thing accepted to reach that state.  It is the accessing_symbol
Xof the core.
X
XEach core contains a vector of nitems items which are the indices
Xin the ritems vector of the items that are selected in this state.
X
XThe link field is used for chaining buckets that hash states by
Xtheir itemsets.  This is for recognizing equivalent states and
Xcombining them when the states are generated.
X
XThe two types of transitions are shifts (push the lookahead token
Xand read another) and reductions (combine the last n things on the
Xstack via a rule, replace them with the symbol that the rule derives,
Xand leave the lookahead token alone).  When the states are generated,
Xthese transitions are represented in two other lists.
X
XEach shifts structure describes the possible shift transitions out
Xof one state, the state whose number is in the number field.
XThe shifts structures are linked through next and first_shift points to them.
XEach contains a vector of numbers of the states that shift transitions
Xcan go to.  The accessing_symbol fields of those states' cores say what kind
Xof input leads to them.
X
XA shift to state zero should be ignored.  Conflict resolution
Xdeletes shifts by changing them to zero.
X
XEach reductions structure describes the possible reductions at the state
Xwhose number is in the number field.  The data is a list of nreds rules,
Xrepresented by their rule numbers.   first_reduction points to the list
Xof these structures.
X
XConflict resolution can decide that certain tokens in certain
Xstates should explicitly be errors (for implementing %nonassoc).
XFor each state, the tokens that are errors for this reason
Xare recorded in an errs structure, which has the state number
Xin its number field.  The rest of the errs structure is full
Xof token numbers.
X
XThere is at least one shift transition present in state zero.
XIt leads to a next-to-final state whose accessing_symbol is
Xthe grammar's start symbol.  The next-to-final state has one shift
Xto the final state, whose accessing_symbol is zero (end of input).
XThe final state has one shift, which goes to the termination state
X(whose number is nstates, and for which there is no core structure).
XThe reason for the extra state at the end is to placate the parser's
Xstrategy of making all decisions one token ahead of its actions.  */
X
X
Xtypedef
X  struct core
X    {
X      struct core *next;
X      struct core *link;
X      short number;
X      short accessing_symbol;
X      short nitems;
X      short items[1];
X    }
X  core;
X
X
X
Xtypedef
X  struct shifts
X    {
X      struct shifts *next;
X      short number;
X      short nshifts;
X      short shifts[1];
X    }
X  shifts;
X
X
X
Xtypedef
X  struct errs
X    {
X      short nerrs;
X      short errs[1];
X    }
X  errs;
X
X
X
Xtypedef
X  struct reductions
X    {
X      struct reductions *next;
X      short number;
X      short nreds;
X      short rules[1];
X    }
X  reductions;
X
X
X
Xextern int nstates;
Xextern core *first_state;
Xextern shifts *first_shift;
Xextern reductions *first_reduction;
SHAR_EOF
if test 4951 -ne "`wc -c < 'state.h'`"
then
	echo shar: error transmitting "'state.h'" '(should have been 4951 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'symtab.h'" '(1496 characters)'
if test -f 'symtab.h'
then
	echo shar: will not over-write existing file "'symtab.h'"
else
sed 's/^X//' << \SHAR_EOF > 'symtab.h'
X/* Definitions for symtab.c and callers, part of bison,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X#define	TABSIZE	1009
X
X
X/*  symbol classes  */
X
X#define SUNKNOWN 0
X#define STOKEN	 1
X#define SNTERM	 2
X
X
Xtypedef
X  struct bucket
X    {
X      struct bucket *link;
X      struct bucket *next;
X      char *tag;
X      char *type_name;
X      short value;
X      short prec;
X      short assoc;
X      short user_token_number;
X      char class;
X    }
X  bucket;
X
X
Xextern bucket **symtab;
Xextern bucket *firstsymbol;
X
Xextern bucket *getsym();
SHAR_EOF
if test 1496 -ne "`wc -c < 'symtab.h'`"
then
	echo shar: error transmitting "'symtab.h'" '(should have been 1496 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'types.h'" '(1179 characters)'
if test -f 'types.h'
then
	echo shar: will not over-write existing file "'types.h'"
else
sed 's/^X//' << \SHAR_EOF > 'types.h'
X/* Define data type for representing bison's grammar input as it is parsed,
X   Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
Xtypedef
X  struct shorts
X    {
X      struct shorts *next;
X      short value;
X    }
X  shorts;
SHAR_EOF
if test 1179 -ne "`wc -c < 'types.h'`"
then
	echo shar: error transmitting "'types.h'" '(should have been 1179 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
--- end of part 6 ---

wetter@tybalt.caltech.edu (Pierce T. Wetter) (05/24/88)

[Bison Macintosh Sources - part 7 of 6]

Accidentally left out a file in the recent posting of Bison.  I
included two copies of main.c though, so its OK.  This is file
"gram.c", which like most GNU stuff is mostly copyright.

Pierce

---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	gram.c
# This archive created: Tue May 24 07:40:31 1988
# By:	Roger L. Long (bytebug@dhw68k.cts.com)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'gram.c'" '(1446 characters)'
if test -f 'gram.c'
then
	echo shar: will not over-write existing file "'gram.c'"
else
sed 's/^X//' << \SHAR_EOF > 'gram.c'
X
X/* Allocate input grammar variables for bison,
X   Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
X
XBISON is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the BISON General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute BISON,
Xbut only under the conditions described in the BISON General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with BISON so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
X In other words, you are welcome to use, share and improve this program.
X You are forbidden to forbid anyone else to use, share and improve
X what you give them.   Help stamp out software-hoarding!  */
X
X/* comments for these variables are in gram.h  */
X
Xint nitems;
Xint nrules;
Xint nsyms;
Xint ntokens;
Xint nvars;
X
Xshort *ritem;
Xshort *rlhs;
Xshort *rrhs;
Xshort *rprec;
Xshort *sprec;
Xshort *rassoc;
Xshort *sassoc;
Xshort *token_translations;
Xshort *rline;
X
Xint start_symbol;
X
Xint translations;
X
Xint max_user_token_number;
X
Xint semantic_parser;
X
Xint pure_parser;
X
Xint error_token_number;
SHAR_EOF
if test 1446 -ne "`wc -c < 'gram.c'`"
then
	echo shar: error transmitting "'gram.c'" '(should have been 1446 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
---