[pe.cust.sources] Little Smalltalk Source, *New* Part 6 of 20

earlw@pesnta.UUCP (Earl Wallace) (06/13/85)

#! /bin/sh 
#
# This is an another posting of the Little Smalltalk source, the last posting
# of this source went out in 5 parts and they were too big (>200k) for most
# sites so I redid the whole mess to keep the files around the 50k range.
#
# The complete set is now 20 parts.
#
# P.S. - If you don't receive all 20 parts within 5 days, drop me a line.
#	 Also, I have the Rand sources of May 1984, if someone has a more
#	 updated copy, I'll be happy to post them (or YOU can post them :-))
# 
# -earlw@pesnta
#
#! /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:
#	parser/parser.h
#	parser/parser.lex
#	parser/parser.y
#	parser/uchar.c
#	parser/y.tab.c
#	parser/y.tab.h
#	prelude/Makefile
#	prelude/acollection.p
#	prelude/acollection.st
#	prelude/array.p
#	prelude/array.st
#	prelude/bag.p
#	prelude/bag.st
#	prelude/block.p
#	prelude/block.st
# This archive created: Thu Jun 13 11:31:53 1985
# By:	Earl Wallace (Perkin-Elmer Data Systems Group / Customer Service)
export PATH; PATH=/bin:$PATH
if test -f 'parser/parser.h'
then
	echo shar: will not over-write existing file "'parser/parser.h'"
else
cat << \SHAR_EOF > 'parser/parser.h'
/*
	Little Smalltalk
		definitions used by parser
*/


enum vartypes {instvar, argvar, tempvar};

struct varstruct {
        struct varstruct *nextvar;
        enum vartypes vtype;
        char *text;
        short position;
        };

enum objtypes {classobj, varobj, instvarobj, contvarobj, 
	litobj, pseuobj, primobj, exprobj, blockobj};

struct objstruct {
        enum objtypes objtype;
        union {
		char *varname;
		int varoffset;
                struct litstruct *litinfo;
                enum   pseuvars pseuinfo;
		struct primstruct *priminfo;
                struct statestruct *stateinfo;
                struct blockstruct *blockinfo;
             } ee;
        };

struct blockstruct {
	int arglocation;
	int numargs;
	struct statestruct *bstates;
	};

enum littypes {numlit, fnumlit, charlit, strlit, symlit, arlit, bytelit};

struct litstruct {
        enum littypes littype;
        union {
                int litint;
                char litchar;
                char *litstr;
                char *litsym;
                struct litlist *litarry;
             } ll;
        };

struct litlist {
        struct litstruct *litele;
        struct litlist *nextlit;
        int    litposition;
        };

struct primstruct {
	int primnumber;
	struct primlist *plist;
	} ;

struct primlist {
	struct primlist *nextprim;
	struct objstruct *pobject;
	};

enum cmdtypes {reccmd, uncmd, bincmd, keycmd, semistart, semiend};

struct exprstruct {
        enum   cmdtypes cmdtype;
        char   *cmdname;
        struct exprstruct *receiver;
        union {
                struct exprstruct *argument;
                struct keylist *keys;
                struct objstruct *recobj;
              } cc;
        struct exprstruct *nextcmd;
        };

enum statetypes {blkupar, upar, asgn, iasgn, casgn, expr};

struct statestruct {
        enum statetypes statetype;
        struct statestruct *nextstate;
        union {
                struct varstruct *variable;
		int varpos;
              } mm;
        union {
                struct statestruct *stateexpr;
                struct exprstruct *cmd;
              } nn;
        };

struct keylist {
        char   *keyword;
        struct exprstruct *arg;
        struct keylist *nextkey;
        };

struct methodstruct {
	struct exprstruct *pattern;
	int    numtempvars;
        struct statestruct *states;
        struct methodstruct *nextmethod;
        };

struct classstruct {
        char *name;
        char *super;
        };

# define structalloc(type) (struct type *) alloc(sizeof (struct type ))

extern struct varstruct *instvars;
extern struct varstruct *contextvars;

# define addinst(x) (instvars = addvlist(mkvar(x, instvar), instvars))

extern char *walloc();
SHAR_EOF
if test 2746 -ne "`wc -c < 'parser/parser.h'`"
then
	echo shar: error transmitting "'parser/parser.h'" '(should have been 2746 characters)'
fi
fi # end of overwriting check
if test -f 'parser/parser.lex'
then
	echo shar: will not over-write existing file "'parser/parser.lex'"
else
cat << \SHAR_EOF > 'parser/parser.lex'
%{
/*
        Little Smalltalk lexical analyzer
*/
# include <math.h>

# undef input
# undef unput

double atof();
int linenum = 1;
%}
%%
[ \t]+                          {;}
\n                              {linenum++;}
\"                              {readcomment();}
":="                            {return(ASSIGN);}
"<-"                            {return(ASSIGN);}
Class                           {return(lexsave(CLASS));}
self                            {yylval.p = selfvar;  return(PSEUDO);}
selfProcess			{yylval.p = procvar;  return(PSEUDO);}
super                           {yylval.p = supervar; return(PSEUDO);}
nil                             {yylval.p = nilvar;   return(PSEUDO);}
true                            {yylval.p = truevar;  return(PSEUDO);}
false                           {yylval.p = falsevar; return(PSEUDO);}
smalltalk                       {yylval.p = smallvar; return(PSEUDO);}
\$.                             {yylval.i = yytext[1]; return(LITCHAR);}
#                               {return(PS);}
[0-9]+r-?[0-9A-Z]+(\.[0-9A-Z]+)?(e[-+]?[0-9]+)? {return(lexsave(LITFNUM));}
[0-9]+                          {yylval.i = atoi(yytext); return(LITNUM);}
[0-9]+(\.[0-9]+)?(e[-+]?[0-9]+)?   {return(lexsave(LITFNUM));}
'[^']*'                         {char c; unput(c = input());
                                 if (c == '\'') yymore();
                                 else return(lexlstr());}
[a-zA-Z0-9]+:?                  {return(varlex());}
:[a-zA-Z0-9]+                   {return(slexsave(COLONVAR));}
#[^ \t\n.()\[]+                 {return(slexsave(LITSYM));}
"-"                             {return(lexsave(MINUS));}
"("                             {return(LP);}
")"                             {return(RP);}
"["                             {return(LB);}
"]"                             {return(RB);}
"."                             {return(PERIOD);}
^"|"				{return(lexsave(MBAR));}
^"!"				{return(lexsave(MBAR));}
"|"                             {return(lexsave(BAR));}
"!"                             {return(lexsave(BAR));}
";"                             {return(SEMI);}
"^"                             {return(lexsave(UPARROW));}
">"				{return(lexsave(PE));}
[^ \t\nA-Za-z0-9]               {return(lexsave(BINARY));}
"<primitive"   			{return(PRIMITIVE);}
%%
static int ocbuf = 0;
static int pbbuf[400];

static int input()
{	int c;

	if (ocbuf) {c = pbbuf[--ocbuf]; }
	else {
		c = getc(fp);
		if (c == EOF) c = 0;
		}
	return(c);
}

static unput(c)
char c;
{
	if (c) pbbuf[ocbuf++] = c;
}

# include <ctype.h>

static readcomment()
{  char c;

   while ((c = input()) && c != '\"')
	if (c == '\n') linenum++;
   if (!c) yyerror("unterminated comment");
}

char *walloc(s) char *s;
{  char *p, *malloc();

   p = malloc((unsigned) (strlen(s) + 1));
   if (p == (char *) 0) yyerror("out of variable string space");
   strcpy(p, s);
   return(p);
}

static int slexsave(type)
int type;
{

	yylval.c = walloc(&yytext[1]);
	if (yylval.c == 0) yerr("cannot create symbol %s", yytext);
	return(type);
}

static int lexsave(type)
int type;
{

	yylval.c = walloc(yytext);
	if (yylval.c == 0) yerr("cannot create string %s", yytext);
	return(type);
}

static int varlex()
{  

   lexsave(0);
   if (yytext[yyleng-1] == ':') return(KEYWORD);
   else if (islower(yytext[0])) return(LOWERCASEVAR);
   else return(UPPERCASEVAR);
}

static int lexlstr()
{  char *p, *q;

   yylval.c = p = walloc(&yytext[1]);
   *(p + yyleng -2) = '\0';
   return(LITSTR);
}
SHAR_EOF
if test 3484 -ne "`wc -c < 'parser/parser.lex'`"
then
	echo shar: error transmitting "'parser/parser.lex'" '(should have been 3484 characters)'
fi
fi # end of overwriting check
if test -f 'parser/parser.y'
then
	echo shar: will not over-write existing file "'parser/parser.y'"
else
cat << \SHAR_EOF > 'parser/parser.y'
/*
	Little Smalltalk Class method syntax
		
		differs from smalltalk-80 slightly

			class heading is different
			vertical bar must appear between methods
			syntax for primitives is different

*/

/*      literals        */
%token LITNUM LITFNUM LITCHAR LITSTR LITSYM 

/*      basic objects   */
%token CLASS ASSIGN BINARY PRIMITIVE

/*      types of variables */
%token PSEUDO UPPERCASEVAR LOWERCASEVAR COLONVAR KEYWORD

/*      one character symbols */
%token LP RP LB RB PERIOD BAR MBAR SEMI UPARROW PS MINUS PE
/*     (  )  [  ]  .      |   ^|   ;    ^       #  -     > */

%{
# include "env.h"
# include "drive.h"
# include "parser.h"
%}

%union {
	struct litlist 		*a;
	struct blockstruct 	*b;
	char 			*c;
	struct exprstruct 	*e;
	int  			 i;
	struct keylist 		*k;
	struct classstruct 	*l;
	struct methodstruct 	*m;
	struct objstruct 	*o;
	enum pseuvars 		 p;
	struct primlist 	*r;
	struct statestruct 	*s;
	struct litstruct 	*t;
	struct primstruct 	*u
	}

%{
extern struct blockstruct *mkblock();
extern struct classstruct *mkclass();
extern struct varstruct *mkvar(), *addvlist(), *invlist();
extern struct methodstruct *mkmethod();
extern struct exprstruct *mkexpr(), *mkkey();
extern struct keylist *mkklist();
extern struct statestruct *mkstate();
extern struct objstruct *mkobj();
extern struct primstruct *mkprim();
extern struct primlist *addprim();
extern struct litstruct *mklit();
extern struct litlist *addlit();
extern char   *bincat();

struct varstruct *instvars;
struct varstruct *contextvars;

int bytetop = 0;
uchar bytearray[1000];

YYSTYPE e;
int errorcount = 0;
%}

%type <a> litarray
%type <b> block
%type <c> CLASS KEYWORD LOWERCASEVAR UPPERCASEVAR COLONVAR LITSYM LITSTR
%type <c> BINARY BAR MINUS UPARROW PE
%type <c> classname binarysym binarychar
%type <c> LITFNUM fliteral
%type <e> pattern expression cexpression binary unary
%type <e> kcontinuation bcontinuation ucontinuation
%type <i> LITCHAR LITNUM PRIMITIVE
%type <i> tempvars cvarlist namelist barglist nliteral
%type <k> keypattern keywordlist
%type <l> super classheading
%type <m> method methodlist
%type <o> primary
%type <p> PSEUDO
%type <r> objlist
%type <s> statelist statement sexpression opmessagelist
%type <s> bstatelist bstatement bexpression
%type <t> literal iliteral aliteral
%type <u> primitive


%start file

%%
file    :       classdef
        |       file classdef
        ;

classdef:       classheading lb methodlist RB   
			{if (errorcount == 0) genclass($1, $3);}
        ;

lb      :       LB
        |       error   {if ((yytext[0] == ':') ||
                             isalpha(yytext[0])) expect(":SuperClass");
                         else expect("open brace [");}
        ;

classheading:   class super instancevars {$$ = $2;}
        ;

class   :       CLASS
        |       error                   {expect("keyword Class");}
        ;

super   :       classname              	{$$ = mkclass($1, (char *) 0);}
        |       classname COLONVAR    	{$$ = mkclass($1, $2);}
        |       error                   {expect("Classname :Superclass");
                                         $$ = mkclass("Error", (char *) 0);}
        ;

classname:	UPPERCASEVAR
	|	CLASS
	;

instancevars:   /* empty */             
        |       bar instvarlist bar     
        ;

instvarlist:    LOWERCASEVAR			{addinst($1);}               
        |       instvarlist LOWERCASEVAR	{addinst($2);}
        |       error                   	{expect("instance variable");}
        ;

methodlist:     method			
        |       methodlist MBAR method
			{$3->nextmethod = $1; $$ = $3;}
        ;

method  :       pattern tempvars statelist op
			{deltemps($2); $$ = mkmethod($1, $2, $3);}
        ;

pattern:        keypattern
{$$ = mkkey((struct exprstruct *) 0, $1);}
        |       binarysym argvariable
{$$ = mkexpr((struct exprstruct *) 0, bincmd, $1, (struct exprstruct *) 0);}
        |       LOWERCASEVAR
{$$ = mkexpr((struct exprstruct *) 0, uncmd, $1, (struct exprstruct *) 0);}
        |       error                   {expect("method pattern");
$$ = mkexpr((struct exprstruct *) 0, uncmd, "", (struct exprstruct *) 0);}
        ;

keypattern:     KEYWORD argvariable
{$$ = mkklist((struct keylist *) 0, $1, (struct exprstruct *) 0);}
        |       keypattern KEYWORD argvariable
{$$ = mkklist($1, $2, (struct exprstruct *) 0);}
        ;

argvariable:      LOWERCASEVAR            {addtemp($1, argvar);}
        |         error                   {expect("argument variable");}
        ;

tempvars:       /* empty */             {$$ = 0;}
        |       bar namelist bar        {$$ = $2;}
        ;

bar     :       BAR
        |       MBAR
        |       error                   {expect("| (vertical bar)");}
        ;

namelist:       tvariable               {$$ = 1;}
        |       namelist tvariable      {$$ = $1 + 1;}
        ;

tvariable:      LOWERCASEVAR               {addtemp($1, tempvar);}
        ;

statelist:	statement			{$$ = $1;}
        |	statelist PERIOD statement	{$3->nextstate = $1; $$ = $3;}
        ;

op	:	/* empty - optional period */
	|	PERIOD
	;

statement:	UPARROW sexpression	{$$ = mkstate(upar, (char *) 0, $2);}
	|	sexpression
	;

sexpression:	LOWERCASEVAR ASSIGN sexpression
				{$$ = mkstate(asgn, $1, $3);}
	|	cexpression	
	{$$ = mkstate(expr, (char *) 0, (struct statestruct *) $1);}
	;

cexpression:	expression
	|	kcontinuation	{$$ = mkexpr($1, semiend, 0, 0);}
	;

kcontinuation:	bcontinuation
	|	bcontinuation keywordlist {$$ = mkkey($1, $2);}
	;

bcontinuation:	ucontinuation
	|	bcontinuation binarysym unary
			{$$ = mkexpr($1, bincmd, $2, $3);}
	;

ucontinuation:	cexpression SEMI	{$$ = mkexpr($1, semistart, 0, 0);}
	|	ucontinuation LOWERCASEVAR
		{$$ = mkexpr($1, uncmd, $2, (struct exprstruct *) 0);}
	;

expression:     binary			{$$ = $1;}
        |       binary keywordlist	{$$ = mkkey($1, $2);}
        ;

keywordlist:    KEYWORD binary		
			{$$ = mkklist((struct keylist *) 0, $1, $2);}
        |       keywordlist KEYWORD binary  
			{$$ = mkklist($1, $2, $3);}
        ;

binary  :       unary			{$$ = $1;}
        |       binary binarysym unary	{$$ = mkexpr($1, bincmd, $2, $3);}
        ;

binarysym:	binarychar		{$$ = $1;}
	|	binarychar binarychar	{$$ = bincat($1, $2);}
	;

binarychar:      BINARY
        |       BAR
        |       MINUS
        |       UPARROW
	|	PE			
        ;

unary   :       primary			
		{$$ = mkexpr((struct exprstruct *) 0, reccmd, (char *) 0, 
					(struct exprstruct *) $1);}
        |       unary LOWERCASEVAR
		{$$ = mkexpr($1, uncmd, $2, (struct exprstruct *) 0);}
        ;

primary :	classname		{e.c = $1; $$ = mkobj(classobj, &e);}
        |       LOWERCASEVAR		{e.c = $1; $$ = mkobj(varobj, &e);}
        |       literal			{e.t = $1; $$ = mkobj(litobj, &e);}
        |       PSEUDO			{e.p = $1; $$ = mkobj(pseuobj, &e);}
	|	primitive		{e.u = $1; $$ = mkobj(primobj, &e);}
        |       LP sexpression RP	{e.s = $2; $$ = mkobj(exprobj, &e);}
	|	block 			{e.b = $1; $$ = mkobj(blockobj, &e);}
        ;

primitive:	PRIMITIVE LITNUM objlist PE
					{$$ = mkprim($2, $3);}
	;

objlist :	/* empty */		{$$ = (struct primlist *) 0;}
	|	objlist primary		{$$ = addprim($1, $2);}
	;

block	:	LB barglist opmessagelist RB
					{$$ = mkblock($2, $3);
					deltemps($2);}
	;

barglist :       /* empty */             {$$ = 0;}
        |       cvarlist BAR            {$$ = $1;}
        ;

cvarlist:       COLONVAR               {addtemp($1, argvar); $$ = 1;}
        |       cvarlist COLONVAR      {addtemp($2, argvar); $$ = $1 + 1;}
        ;

opmessagelist:	bstatelist bstatement 	{$2->nextstate = $1; $$ = $2;}
	|	bstatement 		{$$ = $1;}
	;

bstatement:	UPARROW sexpression 	{$$ = mkstate(blkupar, (char *) 0, $2);}
	|	bexpression		{$$ = mkstate(upar, (char *) 0, $1);}
	;

bexpression:	/* empty */
{e.p = nilvar;
$$ = mkstate(expr, (char *) 0,
(struct statestruct *) mkexpr((struct exprstruct *) 0, reccmd, (char *) 0,
	(struct exprstruct *) mkobj(pseuobj, &e)));}
	|	sexpression		{$$ = $1;}
	;

bstatelist:     sexpression PERIOD	{$$ = $1;}
        |       bstatelist sexpression PERIOD
			{$2->nextstate = $1; $$ = $2;}
        ;

literal :       iliteral                {$$ = $1;}
        |       alitstart litarray RP   {e.a = $2; $$ = mklit(arlit, &e);}
        ;

alitstart:      PS LP
        ;

iliteral:	fliteral		{e.c = $1; $$ = mklit(fnumlit, &e);}
	|	nliteral		{e.i = $1; $$ = mklit(numlit, &e);}
	|       LITCHAR                 {e.i = $1; $$ = mklit(charlit, &e);}
        |       LITSTR                  {e.c = $1; $$ = mklit(strlit, &e);}
        |       LITSYM                  {e.c = $1; $$ = mklit(symlit, &e);}
        |       PS LB bytearray RB      {bytearray[bytetop] = '\0';
                                         $$ = mklit(bytelit, &e);}
        ;

fliteral:	LITFNUM			{$$ = $1;}
	| 	MINUS LITFNUM		{$$ = bincat("-", $2);}
	;

nliteral:	LITNUM			{$$ = $1;}
	|	MINUS LITNUM		{$$ = - $2;}
	;

aliteral:       iliteral                {$$ = $1;}
        |       LOWERCASEVAR            {e.c = $1; $$ = mklit(symlit, &e);}
        |       UPPERCASEVAR            {e.c = $1; $$ = mklit(symlit, &e);}
	|	KEYWORD			{e.c = $1; $$ = mklit(symlit, &e);}
	|	COLONVAR		{e.c = $1; $$ = mklit(symlit, &e);}
	|	CLASS			{e.c = $1; $$ = mklit(symlit, &e);}
        |       binarysym               {e.c = $1; $$ = mklit(symlit, &e);}
        |       ias litarray RP         {e.a = $2; $$ = mklit(arlit, &e);}
        ;

ias     :       PS LP
        |       LP
        ;

litarray:       /* empty */             {$$ = (struct litlist *) 0;}
        |       litarray aliteral       {$$ = addlit($1, $2);}
        ;

bytearray:      LITNUM                  {bytetop = 0;
                                         bytearray[bytetop++] = itouc($1);}
        |       bytearray LITNUM        {bytearray[bytetop++] = itouc($2);}
        ;
%%
# include <stdio.h>

char *filename;
FILE *fp;
FILE *ofd;

# include "lex.yy.c"

main(argc, argv) 
int argc;
char **argv;
{	
	if (argc != 2) quiter("parser: wrong number of arguments");
	filename = argv[1];
	fp = fopen(filename, "r");
	if (fp == NULL) {
		yerr("cannot open input file %s", filename);
		quiter("parser quits");
		}
	ofd = stdout;
	return(yyparse());
}

quiter(s) char *s; {fprintf(stderr,"%s\n", s); exit(1);}

yywarn(s, v) char *s, *v; {
   fprintf(stderr, "%s: line %d: Warning ", filename, linenum);
   fprintf(stderr, s, v);
   fprintf(stderr,"\n");
}

yyerror(s) char *s; {yerr(s, "");}

yerr(s, v) 
char *s, *v; 
{
   fprintf(stderr, "%s: line %d: ", filename, linenum);
   fprintf(stderr, s, v);
   fprintf(stderr,"\n");
   if (errorcount++ > 10) quiter("too many errors, goodby");
}

expect(str) char *str;
{  char buffer[100];

   sprintf(buffer,"Expected %%s found %s", yytext);
   yerr(buffer, str);
}

int yywrap() { return(1);}

char *alloc(size) int size;      /* allocate a block of storage */
{  char *p, *malloc();

   p = malloc( (unsigned) size);
   if (p == (char *) 0) yyerror("out of free space");
   return(p);
}

char *bincat(s1, s2)
char *s1, *s2;
{	char *p;

	p = alloc(strlen(s1) + strlen(s2) + 1);
	strcpy(p, s1);
	strcat(p, s2);
	return(p);
}
SHAR_EOF
if test 11138 -ne "`wc -c < 'parser/parser.y'`"
then
	echo shar: error transmitting "'parser/parser.y'" '(should have been 11138 characters)'
fi
fi # end of overwriting check
if test -f 'parser/uchar.c'
then
	echo shar: will not over-write existing file "'parser/uchar.c'"
else
cat << \SHAR_EOF > 'parser/uchar.c'
# include "env.h"
main() {
  int i;
  uchar c;

   i = 250;
   c = itouc(i);
   i = uctoi(c);
   if (i == 250) printf("success\n");
   else printf("failure\n");
}

SHAR_EOF
if test 164 -ne "`wc -c < 'parser/uchar.c'`"
then
	echo shar: error transmitting "'parser/uchar.c'" '(should have been 164 characters)'
fi
fi # end of overwriting check
if test -f 'parser/y.tab.c'
then
	echo shar: will not over-write existing file "'parser/y.tab.c'"
else
cat << \SHAR_EOF > 'parser/y.tab.c'
# define LITNUM 257
# define LITFNUM 258
# define LITCHAR 259
# define LITSTR 260
# define LITSYM 261
# define CLASS 262
# define ASSIGN 263
# define BINARY 264
# define PRIMITIVE 265
# define PSEUDO 266
# define UPPERCASEVAR 267
# define LOWERCASEVAR 268
# define COLONVAR 269
# define KEYWORD 270
# define LP 271
# define RP 272
# define LB 273
# define RB 274
# define PERIOD 275
# define BAR 276
# define MBAR 277
# define SEMI 278
# define UPARROW 279
# define PS 280
# define MINUS 281
# define PE 282

# line 26 "parser.y"
# include "env.h"
# include "drive.h"
# include "parser.h"

# line 31 "parser.y"
typedef union  {
	struct litlist 		*a;
	struct blockstruct 	*b;
	char 			*c;
	struct exprstruct 	*e;
	int  			 i;
	struct keylist 		*k;
	struct classstruct 	*l;
	struct methodstruct 	*m;
	struct objstruct 	*o;
	enum pseuvars 		 p;
	struct primlist 	*r;
	struct statestruct 	*s;
	struct litstruct 	*t;
	struct primstruct 	*u
	} YYSTYPE;

# line 49 "parser.y"
extern struct blockstruct *mkblock();
extern struct classstruct *mkclass();
extern struct varstruct *mkvar(), *addvlist(), *invlist();
extern struct methodstruct *mkmethod();
extern struct exprstruct *mkexpr(), *mkkey();
extern struct keylist *mkklist();
extern struct statestruct *mkstate();
extern struct objstruct *mkobj();
extern struct primstruct *mkprim();
extern struct primlist *addprim();
extern struct litstruct *mklit();
extern struct litlist *addlit();
extern char   *bincat();

struct varstruct *instvars;
struct varstruct *contextvars;

int bytetop = 0;
uchar bytearray[1000];

YYSTYPE e;
int errorcount = 0;
#define yyclearin yychar = -1
#define yyerrok yyerrflag = 0
extern int yychar;
extern short yyerrflag;
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 150
#endif
YYSTYPE yylval, yyval;
# define YYERRCODE 256

# line 348 "parser.y"

# include <stdio.h>

char *filename;
FILE *fp;
FILE *ofd;

# include "lex.yy.c"

main(argc, argv) 
int argc;
char **argv;
{	
	if (argc != 2) quiter("parser: wrong number of arguments");
	filename = argv[1];
	fp = fopen(filename, "r");
	if (fp == NULL) {
		yerr("cannot open input file %s", filename);
		quiter("parser quits");
		}
	ofd = stdout;
	return(yyparse());
}

quiter(s) char *s; {fprintf(stderr,"%s\n", s); exit(1);}

yywarn(s, v) char *s, *v; {
   fprintf(stderr, "%s: line %d: Warning ", filename, linenum);
   fprintf(stderr, s, v);
   fprintf(stderr,"\n");
}

yyerror(s) char *s; {yerr(s, "");}

yerr(s, v) 
char *s, *v; 
{
   fprintf(stderr, "%s: line %d: ", filename, linenum);
   fprintf(stderr, s, v);
   fprintf(stderr,"\n");
   if (errorcount++ > 10) quiter("too many errors, goodby");
}

expect(str) char *str;
{  char buffer[100];

   sprintf(buffer,"Expected %%s found %s", yytext);
   yerr(buffer, str);
}

int yywrap() { return(1);}

char *alloc(size) int size;      /* allocate a block of storage */
{  char *p, *malloc();

   p = malloc( (unsigned) size);
   if (p == (char *) 0) yyerror("out of free space");
   return(p);
}

char *bincat(s1, s2)
char *s1, *s2;
{	char *p;

	p = alloc(strlen(s1) + strlen(s2) + 1);
	strcpy(p, s1);
	strcat(p, s2);
	return(p);
}
short yyexca[] ={
-1, 1,
	0, -1,
	-2, 0,
	};
# define YYNPROD 119
# define YYLAST 309
short yyact[]={

  81,  79,  75,  76,  77, 127,  92,  25, 157, 141,
 124, 123, 126, 125, 131, 156, 140, 155,  36,  26,
 152,  37,  28, 130, 132,  29,  81,  79,  75,  76,
  77, 127,  89,  25, 154, 149, 124, 123, 126, 125,
 131, 120,  10, 119,  34,  26, 114,  40,  28, 130,
 132,  29,  81,  79,  75,  76,  77,  15, 105,   9,
  71,  65,  14, 116,  32,  33,  67, 146,  72, 107,
 106,  35, 107,  43,  98,  78,  80, 147,  81,  79,
  75,  76,  77,  15,  48,  42,  71,  65,  14,  54,
  99,  84,  67,  91,  72, 143,  47, 109, 108, 102,
 138,  78,  80,  81,  79,  75,  76,  77,  15,  13,
   6,  71,  65,  14,  54,  15,   5,  67, 136,  72,
  14,  69,  62, 101,  58,  52,  78,  80,  81,  79,
  75,  76,  77,  15,  53,  60,  71,  65,  14,  54,
  24,  51,  67,  93,  72,  81,  79,  75,  76,  77,
  15,  78,  80,  71,  65,  14, 116,  31,  22,  67,
  83,  72,  94,  17, 129,  45,  25, 142,  78,  80,
  21,  20,  23,  25,  70,  41,  39,  25,  26,  95,
   2,  28,   7,  27,  29,  26,  34,  90,  28,  26,
  27,  29,  28,  34,  27,  29,  88,  46,  84,  44,
  20,  49, 100,  96,  86,  87,  32,  33,  30,   4,
  63,   8,   1,  32,  33,  12,  85,  66, 121,  64,
 117, 139,  97, 122, 135, 134, 113,  50, 133,  16,
 115, 112,   3, 118,  11,  19,  74, 103, 137, 144,
 110,  82, 104, 111,  38,  61,  59,  57,  55,  56,
  18,  73,  68, 145, 150,   0, 148,   0,   0,   0,
   0,   0,   0,   0, 128,   0,   0, 122,   0,   0,
 151,   0,   0, 153,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0, 128 };
short yypact[]={

-146,-146,-1000,-214,-147,-1000,-1000,-1000, -98,-1000,
-1000,-212,-198,-1000,-1000,-1000,-256,-1000,-212,-223,
-183,-1000,-1000,-183, -87,-1000,-1000,-1000,-1000,-1000,
-1000,-172,-1000,-1000,-1000,-1000,-1000, -98,-154,-177,
-183,-1000,-1000,-1000,-1000,-1000, -63,-1000,-1000,-1000,
-243,-1000,-129,-1000,-170,-272,-1000,-1000, -91, -91,
-194,-178,-1000,-1000,-1000,-1000,-1000,-129,-1000,-1000,
-1000,-158,-211,-1000,-1000,-1000,-1000,-1000,-201,-1000,
-160,-1000, -70,-1000,-1000,-1000,-1000,-1000,-1000,-154,
-1000,-129,-1000,-224,-112,-112,-224,-112,-1000,-1000,
-229,-231,-1000,-179,-260,-1000,-1000,-162,-1000,-1000,
-1000,-1000,-1000,-1000,-112,-194,-1000, -87,-194,-1000,
-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
-204,-1000,-160,-205,-239,-179,-1000,-255,-129,-1000,
-1000,-1000,-240,-1000, -87,-257,-1000,-1000,-1000,-1000,
-1000,-267,-1000,-1000,-1000,-1000,-1000,-1000 };
short yypgo[]={

   0, 123, 252, 210, 162, 140, 251, 250, 249, 248,
 124, 135, 247, 246, 245, 244, 242, 241, 237, 236,
 235, 143, 234, 232, 163, 229, 122, 228, 227, 141,
 134, 225, 224, 118, 221, 219, 121, 218, 217, 212,
 180, 211, 209, 208, 157, 197, 196, 175, 160, 174,
 167, 164 };
short yyr1[]={

   0,  39,  39,  40,  41,  41,  23,  42,  42,  22,
  22,  22,   3,   3,  43,  43,  45,  45,  45,  25,
  25,  24,   7,   7,   7,   7,  20,  20,  47,  47,
  15,  15,  44,  44,  44,  17,  17,  48,  28,  28,
  46,  46,  29,  29,  30,  30,   9,   9,  12,  12,
  13,  13,  14,  14,   8,   8,  21,  21,  10,  10,
   4,   4,   5,   5,   5,   5,   5,  11,  11,  26,
  26,  26,  26,  26,  26,  26,  38,  27,  27,   2,
  18,  18,  16,  16,  31,  31,  33,  33,  34,  34,
  32,  32,  35,  35,  49,  36,  36,  36,  36,  36,
  36,   6,   6,  19,  19,  37,  37,  37,  37,  37,
  37,  37,  37,  51,  51,   1,   1,  50,  50 };
short yyr2[]={

   0,   1,   2,   4,   1,   1,   3,   1,   1,   1,
   2,   1,   1,   1,   0,   3,   1,   2,   1,   1,
   3,   4,   1,   2,   1,   1,   2,   3,   1,   1,
   0,   3,   1,   1,   1,   1,   2,   1,   1,   3,
   0,   1,   2,   1,   3,   1,   1,   1,   1,   2,
   1,   3,   2,   2,   1,   2,   2,   3,   1,   3,
   1,   2,   1,   1,   1,   1,   1,   1,   2,   1,
   1,   1,   1,   1,   3,   1,   4,   0,   2,   4,
   0,   2,   1,   2,   2,   1,   2,   1,   0,   1,
   2,   3,   1,   3,   2,   1,   1,   1,   1,   1,
   4,   1,   2,   1,   2,   1,   1,   1,   1,   1,
   1,   1,   3,   2,   1,   0,   2,   1,   2 };
short yychk[]={

-1000, -39, -40, -23, -42, 262, 256, -40, -41, 273,
 256, -22,  -3, 256, 267, 262, -25, -24,  -7, -20,
  -4, 268, 256, 270,  -5, 264, 276, 281, 279, 282,
 -43, -44, 276, 277, 256, 269, 274, 277, -15, -44,
 270, -47, 268, 256, -47,  -5, -45, 268, 256, -24,
 -28, -29, 279, -30, 268,  -9,  -8, -12, -10, -13,
 -11, -14, -26,  -3, -35, 266, -38, 271,  -2, -36,
 -49, 265, 273,  -6, -19, 259, 260, 261, 280, 258,
 281, 257, -17, -48, 268, -47, -44, 268, -46, 275,
 -30, 263, 278, -21,  -4, 270, -21,  -4, 268, 268,
 -30,  -1, 257, -18, -16, 269, 271, 273, 258, 257,
 -44, -48, -29, -30, 270, -11, 268, -10, -11, 272,
 272, -37, -36, 268, 267, 270, 269, 262,  -4, -51,
 280, 271, 281, -27, -31, -32, -33, -30, 279, -34,
 276, 269, -50, 257, -10,  -1, 271, 282, -26, 274,
 -33, -30, 275, -30, 274, 257, 272, 275 };
short yydef[]={

   0,  -2,   1,   0,   0,   7,   8,   2,   0,   4,
   5,  14,   9,  11,  12,  13,   0,  19,  30,  22,
   0,  24,  25,   0,  60,  62,  63,  64,  65,  66,
   6,   0,  32,  33,  34,  10,   3,   0,   0,   0,
   0,  23,  28,  29,  26,  61,   0,  16,  18,  20,
  40,  38,   0,  43,  70,  45,  46,  47,  54,  48,
  58,  50,  67,  69,  71,  72,  73,   0,  75,  92,
 115,   0,  80,  95,  96,  97,  98,  99,   0, 101,
   0, 103,   0,  35,  37,  27,  15,  17,  21,  41,
  42,   0,  52,  55,   0,   0,  49,   0,  68,  53,
   0,   0,  77,  88,   0,  82,  94,   0, 102, 104,
  31,  36,  39,  44,   0,  59,  70,  56,  51,  74,
  93, 116, 105, 106, 107, 108, 109, 110, 111, 115,
   0, 114,  64,   0,   0,  88,  85,  89,   0,  87,
  81,  83,   0, 117,  57,   0, 113,  76,  78,  79,
  84,  89,  90,  86, 100, 118, 112,  91 };
#ifndef lint
static char yaccpar_sccsid[] = "@(#)yaccpar	4.1	(Berkeley)	2/11/83";
#endif not lint

#
# define YYFLAG -1000
# define YYERROR goto yyerrlab
# define YYACCEPT return(0)
# define YYABORT return(1)

/*	parser for yacc output	*/

#ifdef YYDEBUG
int yydebug = 0; /* 1 for debugging */
#endif
YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
int yychar = -1; /* current input token number */
int yynerrs = 0;  /* number of errors */
short yyerrflag = 0;  /* error recovery flag */

yyparse() {

	short yys[YYMAXDEPTH];
	short yyj, yym;
	register YYSTYPE *yypvt;
	register short yystate, *yyps, yyn;
	register YYSTYPE *yypv;
	register short *yyxi;

	yystate = 0;
	yychar = -1;
	yynerrs = 0;
	yyerrflag = 0;
	yyps= &yys[-1];
	yypv= &yyv[-1];

 yystack:    /* put a state and value onto the stack */

#ifdef YYDEBUG
	if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
#endif
		if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
		*yyps = yystate;
		++yypv;
		*yypv = yyval;

 yynewstate:

	yyn = yypact[yystate];

	if( yyn<= YYFLAG ) goto yydefault; /* simple state */

	if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
	if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;

	if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
		yychar = -1;
		yyval = yylval;
		yystate = yyn;
		if( yyerrflag > 0 ) --yyerrflag;
		goto yystack;
		}

 yydefault:
	/* default state action */

	if( (yyn=yydef[yystate]) == -2 ) {
		if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
		/* look through exception table */

		for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */

		while( *(yyxi+=2) >= 0 ){
			if( *yyxi == yychar ) break;
			}
		if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
		}

	if( yyn == 0 ){ /* error */
		/* error ... attempt to resume parsing */

		switch( yyerrflag ){

		case 0:   /* brand new error */

			yyerror( "syntax error" );
		yyerrlab:
			++yynerrs;

		case 1:
		case 2: /* incompletely recovered error ... try again */

			yyerrflag = 3;

			/* find a state where "error" is a legal shift action */

			while ( yyps >= yys ) {
			   yyn = yypact[*yyps] + YYERRCODE;
			   if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
			      yystate = yyact[yyn];  /* simulate a shift of "error" */
			      goto yystack;
			      }
			   yyn = yypact[*yyps];

			   /* the current yyps has no shift onn "error", pop stack */

#ifdef YYDEBUG
			   if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
#endif
			   --yyps;
			   --yypv;
			   }

			/* there is no state on the stack with an error shift ... abort */

	yyabort:
			return(1);


		case 3:  /* no shift yet; clobber input char */

#ifdef YYDEBUG
			if( yydebug ) printf( "error recovery discards char %d\n", yychar );
#endif

			if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
			yychar = -1;
			goto yynewstate;   /* try again in the same state */

			}

		}

	/* reduction by production yyn */

#ifdef YYDEBUG
		if( yydebug ) printf("reduce %d\n",yyn);
#endif
		yyps -= yyr2[yyn];
		yypvt = yypv;
		yypv -= yyr2[yyn];
		yyval = yypv[1];
		yym=yyn;
			/* consult goto table to find next state */
		yyn = yyr1[yyn];
		yyj = yypgo[yyn] + *yyps + 1;
		if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
		switch(yym){
			
case 3:
# line 103 "parser.y"
{if (errorcount == 0) genclass(yypvt[-3].l, yypvt[-1].m);} break;
case 5:
# line 107 "parser.y"
{if ((yytext[0] == ':') ||
                             isalpha(yytext[0])) expect(":SuperClass");
                         else expect("open brace [");} break;
case 6:
# line 112 "parser.y"
{yyval.l = yypvt[-1].l;} break;
case 8:
# line 116 "parser.y"
{expect("keyword Class");} break;
case 9:
# line 119 "parser.y"
{yyval.l = mkclass(yypvt[-0].c, (char *) 0);} break;
case 10:
# line 120 "parser.y"
{yyval.l = mkclass(yypvt[-1].c, yypvt[-0].c);} break;
case 11:
# line 121 "parser.y"
{expect("Classname :Superclass");
                                         yyval.l = mkclass("Error", (char *) 0);} break;
case 16:
# line 133 "parser.y"
{addinst(yypvt[-0].c);} break;
case 17:
# line 134 "parser.y"
{addinst(yypvt[-0].c);} break;
case 18:
# line 135 "parser.y"
{expect("instance variable");} break;
case 20:
# line 140 "parser.y"
{yypvt[-0].m->nextmethod = yypvt[-2].m; yyval.m = yypvt[-0].m;} break;
case 21:
# line 144 "parser.y"
{deltemps(yypvt[-2].i); yyval.m = mkmethod(yypvt[-3].e, yypvt[-2].i, yypvt[-1].s);} break;
case 22:
# line 148 "parser.y"
{yyval.e = mkkey((struct exprstruct *) 0, yypvt[-0].k);} break;
case 23:
# line 150 "parser.y"
{yyval.e = mkexpr((struct exprstruct *) 0, bincmd, yypvt[-1].c, (struct exprstruct *) 0);} break;
case 24:
# line 152 "parser.y"
{yyval.e = mkexpr((struct exprstruct *) 0, uncmd, yypvt[-0].c, (struct exprstruct *) 0);} break;
case 25:
# line 153 "parser.y"
{expect("method pattern");
yyval.e = mkexpr((struct exprstruct *) 0, uncmd, "", (struct exprstruct *) 0);} break;
case 26:
# line 158 "parser.y"
{yyval.k = mkklist((struct keylist *) 0, yypvt[-1].c, (struct exprstruct *) 0);} break;
case 27:
# line 160 "parser.y"
{yyval.k = mkklist(yypvt[-2].k, yypvt[-1].c, (struct exprstruct *) 0);} break;
case 28:
# line 163 "parser.y"
{addtemp(yypvt[-0].c, argvar);} break;
case 29:
# line 164 "parser.y"
{expect("argument variable");} break;
case 30:
# line 167 "parser.y"
{yyval.i = 0;} break;
case 31:
# line 168 "parser.y"
{yyval.i = yypvt[-1].i;} break;
case 34:
# line 173 "parser.y"
{expect("| (vertical bar)");} break;
case 35:
# line 176 "parser.y"
{yyval.i = 1;} break;
case 36:
# line 177 "parser.y"
{yyval.i = yypvt[-1].i + 1;} break;
case 37:
# line 180 "parser.y"
{addtemp(yypvt[-0].c, tempvar);} break;
case 38:
# line 183 "parser.y"
{yyval.s = yypvt[-0].s;} break;
case 39:
# line 184 "parser.y"
{yypvt[-0].s->nextstate = yypvt[-2].s; yyval.s = yypvt[-0].s;} break;
case 42:
# line 191 "parser.y"
{yyval.s = mkstate(upar, (char *) 0, yypvt[-0].s);} break;
case 44:
# line 196 "parser.y"
{yyval.s = mkstate(asgn, yypvt[-2].c, yypvt[-0].s);} break;
case 45:
# line 198 "parser.y"
{yyval.s = mkstate(expr, (char *) 0, (struct statestruct *) yypvt[-0].e);} break;
case 47:
# line 202 "parser.y"
{yyval.e = mkexpr(yypvt[-0].e, semiend, 0, 0);} break;
case 49:
# line 206 "parser.y"
{yyval.e = mkkey(yypvt[-1].e, yypvt[-0].k);} break;
case 51:
# line 211 "parser.y"
{yyval.e = mkexpr(yypvt[-2].e, bincmd, yypvt[-1].c, yypvt[-0].e);} break;
case 52:
# line 214 "parser.y"
{yyval.e = mkexpr(yypvt[-1].e, semistart, 0, 0);} break;
case 53:
# line 216 "parser.y"
{yyval.e = mkexpr(yypvt[-1].e, uncmd, yypvt[-0].c, (struct exprstruct *) 0);} break;
case 54:
# line 219 "parser.y"
{yyval.e = yypvt[-0].e;} break;
case 55:
# line 220 "parser.y"
{yyval.e = mkkey(yypvt[-1].e, yypvt[-0].k);} break;
case 56:
# line 224 "parser.y"
{yyval.k = mkklist((struct keylist *) 0, yypvt[-1].c, yypvt[-0].e);} break;
case 57:
# line 226 "parser.y"
{yyval.k = mkklist(yypvt[-2].k, yypvt[-1].c, yypvt[-0].e);} break;
case 58:
# line 229 "parser.y"
{yyval.e = yypvt[-0].e;} break;
case 59:
# line 230 "parser.y"
{yyval.e = mkexpr(yypvt[-2].e, bincmd, yypvt[-1].c, yypvt[-0].e);} break;
case 60:
# line 233 "parser.y"
{yyval.c = yypvt[-0].c;} break;
case 61:
# line 234 "parser.y"
{yyval.c = bincat(yypvt[-1].c, yypvt[-0].c);} break;
case 67:
# line 245 "parser.y"
{yyval.e = mkexpr((struct exprstruct *) 0, reccmd, (char *) 0, 
					(struct exprstruct *) yypvt[-0].o);} break;
case 68:
# line 248 "parser.y"
{yyval.e = mkexpr(yypvt[-1].e, uncmd, yypvt[-0].c, (struct exprstruct *) 0);} break;
case 69:
# line 251 "parser.y"
{e.c = yypvt[-0].c; yyval.o = mkobj(classobj, &e);} break;
case 70:
# line 252 "parser.y"
{e.c = yypvt[-0].c; yyval.o = mkobj(varobj, &e);} break;
case 71:
# line 253 "parser.y"
{e.t = yypvt[-0].t; yyval.o = mkobj(litobj, &e);} break;
case 72:
# line 254 "parser.y"
{e.p = yypvt[-0].p; yyval.o = mkobj(pseuobj, &e);} break;
case 73:
# line 255 "parser.y"
{e.u = yypvt[-0].u; yyval.o = mkobj(primobj, &e);} break;
case 74:
# line 256 "parser.y"
{e.s = yypvt[-1].s; yyval.o = mkobj(exprobj, &e);} break;
case 75:
# line 257 "parser.y"
{e.b = yypvt[-0].b; yyval.o = mkobj(blockobj, &e);} break;
case 76:
# line 261 "parser.y"
{yyval.u = mkprim(yypvt[-2].i, yypvt[-1].r);} break;
case 77:
# line 264 "parser.y"
{yyval.r = (struct primlist *) 0;} break;
case 78:
# line 265 "parser.y"
{yyval.r = addprim(yypvt[-1].r, yypvt[-0].o);} break;
case 79:
# line 269 "parser.y"
{yyval.b = mkblock(yypvt[-2].i, yypvt[-1].s);
					deltemps(yypvt[-2].i);} break;
case 80:
# line 273 "parser.y"
{yyval.i = 0;} break;
case 81:
# line 274 "parser.y"
{yyval.i = yypvt[-1].i;} break;
case 82:
# line 277 "parser.y"
{addtemp(yypvt[-0].c, argvar); yyval.i = 1;} break;
case 83:
# line 278 "parser.y"
{addtemp(yypvt[-0].c, argvar); yyval.i = yypvt[-1].i + 1;} break;
case 84:
# line 281 "parser.y"
{yypvt[-0].s->nextstate = yypvt[-1].s; yyval.s = yypvt[-0].s;} break;
case 85:
# line 282 "parser.y"
{yyval.s = yypvt[-0].s;} break;
case 86:
# line 285 "parser.y"
{yyval.s = mkstate(blkupar, (char *) 0, yypvt[-0].s);} break;
case 87:
# line 286 "parser.y"
{yyval.s = mkstate(upar, (char *) 0, yypvt[-0].s);} break;
case 88:
# line 290 "parser.y"
{e.p = nilvar;
yyval.s = mkstate(expr, (char *) 0,
(struct statestruct *) mkexpr((struct exprstruct *) 0, reccmd, (char *) 0,
	(struct exprstruct *) mkobj(pseuobj, &e)));} break;
case 89:
# line 294 "parser.y"
{yyval.s = yypvt[-0].s;} break;
case 90:
# line 297 "parser.y"
{yyval.s = yypvt[-1].s;} break;
case 91:
# line 299 "parser.y"
{yypvt[-1].s->nextstate = yypvt[-2].s; yyval.s = yypvt[-1].s;} break;
case 92:
# line 302 "parser.y"
{yyval.t = yypvt[-0].t;} break;
case 93:
# line 303 "parser.y"
{e.a = yypvt[-1].a; yyval.t = mklit(arlit, &e);} break;
case 95:
# line 309 "parser.y"
{e.c = yypvt[-0].c; yyval.t = mklit(fnumlit, &e);} break;
case 96:
# line 310 "parser.y"
{e.i = yypvt[-0].i; yyval.t = mklit(numlit, &e);} break;
case 97:
# line 311 "parser.y"
{e.i = yypvt[-0].i; yyval.t = mklit(charlit, &e);} break;
case 98:
# line 312 "parser.y"
{e.c = yypvt[-0].c; yyval.t = mklit(strlit, &e);} break;
case 99:
# line 313 "parser.y"
{e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
case 100:
# line 314 "parser.y"
{bytearray[bytetop] = '\0';
                                         yyval.t = mklit(bytelit, &e);} break;
case 101:
# line 318 "parser.y"
{yyval.c = yypvt[-0].c;} break;
case 102:
# line 319 "parser.y"
{yyval.c = bincat("-", yypvt[-0].c);} break;
case 103:
# line 322 "parser.y"
{yyval.i = yypvt[-0].i;} break;
case 104:
# line 323 "parser.y"
{yyval.i = - yypvt[-0].i;} break;
case 105:
# line 326 "parser.y"
{yyval.t = yypvt[-0].t;} break;
case 106:
# line 327 "parser.y"
{e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
case 107:
# line 328 "parser.y"
{e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
case 108:
# line 329 "parser.y"
{e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
case 109:
# line 330 "parser.y"
{e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
case 110:
# line 331 "parser.y"
{e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
case 111:
# line 332 "parser.y"
{e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
case 112:
# line 333 "parser.y"
{e.a = yypvt[-1].a; yyval.t = mklit(arlit, &e);} break;
case 115:
# line 340 "parser.y"
{yyval.a = (struct litlist *) 0;} break;
case 116:
# line 341 "parser.y"
{yyval.a = addlit(yypvt[-1].a, yypvt[-0].t);} break;
case 117:
# line 344 "parser.y"
{bytetop = 0;
                                         bytearray[bytetop++] = itouc(yypvt[-0].i);} break;
case 118:
# line 346 "parser.y"
{bytearray[bytetop++] = itouc(yypvt[-0].i);} break;
		}
		goto yystack;  /* stack new state and value */

	}
SHAR_EOF
if test 20727 -ne "`wc -c < 'parser/y.tab.c'`"
then
	echo shar: error transmitting "'parser/y.tab.c'" '(should have been 20727 characters)'
fi
fi # end of overwriting check
if test -f 'parser/y.tab.h'
then
	echo shar: will not over-write existing file "'parser/y.tab.h'"
else
cat << \SHAR_EOF > 'parser/y.tab.h'
# define LITNUM 257
# define LITFNUM 258
# define LITCHAR 259
# define LITSTR 260
# define LITSYM 261
# define CLASS 262
# define ASSIGN 263
# define BINARY 264
# define PRIMITIVE 265
# define PSEUDO 266
# define UPPERCASEVAR 267
# define LOWERCASEVAR 268
# define COLONVAR 269
# define KEYWORD 270
# define LP 271
# define RP 272
# define LB 273
# define RB 274
# define PERIOD 275
# define BAR 276
# define MBAR 277
# define SEMI 278
# define UPARROW 279
# define PS 280
# define MINUS 281
# define PE 282

typedef union  {
	struct litlist 		*a;
	struct blockstruct 	*b;
	char 			*c;
	struct exprstruct 	*e;
	int  			 i;
	struct keylist 		*k;
	struct classstruct 	*l;
	struct methodstruct 	*m;
	struct objstruct 	*o;
	enum pseuvars 		 p;
	struct primlist 	*r;
	struct statestruct 	*s;
	struct litstruct 	*t;
	struct primstruct 	*u
	} YYSTYPE;
extern YYSTYPE yylval;
SHAR_EOF
if test 868 -ne "`wc -c < 'parser/y.tab.h'`"
then
	echo shar: error transmitting "'parser/y.tab.h'" '(should have been 868 characters)'
fi
fi # end of overwriting check
if test -f 'prelude/Makefile'
then
	echo shar: will not over-write existing file "'prelude/Makefile'"
else
cat << \SHAR_EOF > 'prelude/Makefile'
.SUFFIXES : .st .p
PREPATH = /usr/src/public/lsmalltalk/prelude
BINDIR = ../bin

PARSED = class.p object.p \
string.p larray.p nil.p array.p\
boolean.p true.p false.p block.p symbol.p \
magnitude.p number.p integer.p char.p float.p radian.p point.p random.p \
collection.p bag.p set.p kcollection.p dictionary.p scollection.p interval.p \
list.p acollection.p file.p bytearray.p \
semaphore.p process.p smalltalk.p

.st.p:
	$(BINDIR)/parse $(PREPATH)/$*.st >$*.p

install: standard
	-make fastsave

bundle: *.st Makefile savescript
	bundle Makefile savescript init *.st >../prelude.bundle

standard: $(PARSED)
	cat $(PARSED) init >standard

newstd: $(PARSED)
	cat $(PARSED) >newstd

fastsave: standard
	$(BINDIR)/st -m <savescript

clean:
	-rm *.p
SHAR_EOF
if test 748 -ne "`wc -c < 'prelude/Makefile'`"
then
	echo shar: error transmitting "'prelude/Makefile'" '(should have been 748 characters)'
fi
fi # end of overwriting check
if test -f 'prelude/acollection.p'
then
	echo shar: will not over-write existing file "'prelude/acollection.p'"
else
cat << \SHAR_EOF > 'prelude/acollection.p'
temp <- <primitive 110 12 >
<primitive 112 temp 1		" shallowCopy " \
	#( #[ 32 164 32 163 176 113 81 32 163 178 225 2 7 33 34 \
 32 34 177 208 243 179 242 33 243 245] \
	#(  ) ) >

<primitive 112 temp 2		" next " \
	#( #[ 16 81 192 96 16 32 163 200 247 3 32 16 177 243 245 \
] \
	#(  ) ) >

<primitive 112 temp 3		" lastKey " \
	#( #[ 32 163 243 245] \
	#(  ) ) >

<primitive 112 temp 4		" firstKey " \
	#( #[ 81 243 245] \
	#(  ) ) >

<primitive 112 temp 5		" first " \
	#( #[ 81 96 16 32 163 200 247 3 32 16 177 243 245] \
	#(  ) ) >

<primitive 112 temp 6		" do: " \
	#( #[ 81 32 163 178 225 2 8 34 96 33 32 34 177 180 243 \
 179 242 245] \
	#(  ) ) >

<primitive 112 temp 7		" deepCopy " \
	#( #[ 32 164 32 163 176 113 81 32 163 178 225 2 9 33 34 \
 32 34 177 10 20 208 243 179 242 33 243 245] \
	#(  ) ) >

<primitive 112 temp 8		" currentKey " \
	#( #[ 16 243 245] \
	#(  ) ) >

<primitive 112 temp 9		" copyFrom:to: " \
	#( #[ 34 33 193 81 192 115 32 164 35 176 116 36 81 35 32 \
 33 132 0 242 36 243 245] \
	#( #replaceFrom:to:with:startingAt:  ) ) >

<primitive 112 temp 10		" coerce: " \
	#( #[ 32 164 33 163 176 114 34 81 33 163 33 131 0 242 34 \
 243 245] \
	#( #replaceFrom:to:with:  ) ) >

<primitive 112 temp 11		" at:ifAbsent: " \
	#( #[ 33 80 200 251 4 33 32 163 204 247 3 34 165 243 242 \
 32 33 177 243 245] \
	#(  ) ) >

<primitive 112 temp 12		" = " \
	#( #[ 32 163 33 163 202 247 2 92 243 242 80 114 32 225 3 \
 14 35 33 34 81 192 241 114 177 202 247 2 92 244 243 \
 179 242 91 243 245] \
	#(  ) ) >

<primitive 98 #ArrayedCollection \
	<primitive 97 #ArrayedCollection #SequenceableCollection #/u/smalltalk/prelude/acollection.st \
	#(  #current ) \
	#( #shallowCopy #next #lastKey #firstKey #first #do: #deepCopy #currentKey #copyFrom:to: #coerce: #at:ifAbsent: #=  ) \
	temp 5 7 > >

SHAR_EOF
if test 1809 -ne "`wc -c < 'prelude/acollection.p'`"
then
	echo shar: error transmitting "'prelude/acollection.p'" '(should have been 1809 characters)'
fi
fi # end of overwriting check
if test -f 'prelude/acollection.st'
then
	echo shar: will not over-write existing file "'prelude/acollection.st'"
else
cat << \SHAR_EOF > 'prelude/acollection.st'
Class ArrayedCollection :SequenceableCollection
| current |
[
       = anArray                       | i |
                (self size ~= anArray size) ifTrue: [^ false].
                i <- 0.
                self do: [:x | (x ~= (anArray at: (i <- i + 1)))
                                ifTrue: [^ false]].
		^ true
|
        at: key ifAbsent: exceptionBlock
		((key <= 0) or: [key > self size])
			ifTrue: [^ exceptionBlock value].
                ^ self at: key
|
	coerce: aCollection		| temp |
		temp <- self class new: aCollection size.
		temp replaceFrom: 1 to: aCollection size with: aCollection.
		^ temp
|
       copyFrom: start to: stop                | size temp |
		size <- stop - start + 1.
		temp <- self class new: size.
		temp replaceFrom: 1 to: size with: self startingAt: start.
		^ temp
|
        currentKey
                ^ current
| 
	deepCopy		| newobj |
		newobj <- self class new: self size.
		(1 to: self size) do:
			[:i | newobj at: i
				put: (self at: i) copy ].
		^ newobj
|
       do: aBlock
                (1 to: self size) 
		    do: [:i | current <- i. 
				aBlock value: (self at: i)]
|
       first
                current <- 1.
                ^ (current <= self size) 
			ifTrue: [ self at: current]
|
	firstKey
		^ 1
|
	lastKey
		^ self size
|
       next
                current <- current + 1.
                ^ (current <= self size) 
			ifTrue: [ self at: current]
|
	shallowCopy		| newobj |
		newobj <- self class new: self size.
		(1 to: self size) do:
			[:i | newobj at: i 
				put: (self at: i) ].
		^ newobj
]
SHAR_EOF
if test 1564 -ne "`wc -c < 'prelude/acollection.st'`"
then
	echo shar: error transmitting "'prelude/acollection.st'" '(should have been 1564 characters)'
fi
fi # end of overwriting check
if test -f 'prelude/array.p'
then
	echo shar: will not over-write existing file "'prelude/array.p'"
else
cat << \SHAR_EOF > 'prelude/array.p'
temp <- <primitive 110 5 >
<primitive 112 temp 1		" size " \
	#( #[ 32 250 1 4 243 245] \
	#(  ) ) >

<primitive 112 temp 2		" printString " \
	#( #[ 48 113 32 250 1 4 114 34 80 204 247 21 32 34 250 \
 2 111 169 49 11 17 33 11 17 113 34 81 193 241 114 \
 242 249 26 242 50 33 11 17 243 245] \
	#( ')' ' ' '#( '  ) ) >

<primitive 112 temp 3		" at:put: " \
	#( #[ 33 81 199 251 6 33 32 250 1 4 204 247 6 32 48 \
 188 242 93 243 242 32 33 34 250 3 112 242 34 243 245 \
] \
	#( 'index error'  ) ) >

<primitive 112 temp 4		" at: " \
	#( #[ 33 81 199 251 6 33 32 250 1 4 204 247 6 32 48 \
 188 242 93 243 242 32 33 250 2 111 243 245] \
	#( 'index error'  ) ) >

<primitive 112 temp 5		" new: " \
	#( #[ 33 250 1 114 243 245] \
	#(  ) ) >

<primitive 98 #Array \
	<primitive 97 #Array #ArrayedCollection #/u/smalltalk/prelude/array.st \
	#(  ) \
	#( #size #printString #at:put: #at: #new:  ) \
	temp 3 4 > >

SHAR_EOF
if test 904 -ne "`wc -c < 'prelude/array.p'`"
then
	echo shar: error transmitting "'prelude/array.p'" '(should have been 904 characters)'
fi
fi # end of overwriting check
if test -f 'prelude/array.st'
then
	echo shar: will not over-write existing file "'prelude/array.st'"
else
cat << \SHAR_EOF > 'prelude/array.st'
Class Array :ArrayedCollection
[
	new: aValue
		^ <primitive 114 aValue>
|
	at: aNumber
		( (aNumber < 1) or: [aNumber > <primitive 4 self> ] )
			ifTrue: [ self error: 'index error'. ^nil ].
		^ <primitive 111 self aNumber >
|
	at: aNumber put: aValue
		( (aNumber < 1) or: [aNumber > <primitive 4 self> ] )
			ifTrue: [ self error: 'index error'. ^nil ].
		<primitive 112 self aNumber aValue >.
		^ aValue
|
	printString		| value i |
		value <- ')'.
		i <- <primitive 4 self>.
		[i > 0] whileTrue: 
			[ value <- <primitive 111 self i>  printString ,
					' ', value.
				    i <- i - 1].
		^ '#( ' , value
|
	size
		^ <primitive 4 self>
]
SHAR_EOF
if test 642 -ne "`wc -c < 'prelude/array.st'`"
then
	echo shar: error transmitting "'prelude/array.st'" '(should have been 642 characters)'
fi
fi # end of overwriting check
if test -f 'prelude/bag.p'
then
	echo shar: will not over-write existing file "'prelude/bag.p'"
else
cat << \SHAR_EOF > 'prelude/bag.p'
temp <- <primitive 110 8 >
<primitive 112 temp 1		" next " \
	#( #[ 17 162 247 27 17 80 204 247 9 17 81 193 97 16 171 \
 243 248 10 242 16 167 241 97 161 247 2 93 243 242 249 \
 31 242 93 243 245] \
	#(  ) ) >

<primitive 112 temp 2		" first " \
	#( #[ 16 166 241 97 161 247 2 93 243 242 17 81 193 97 16 \
 171 243 245] \
	#(  ) ) >

<primitive 112 temp 3		" occurrencesOf: " \
	#( #[ 16 33 224 2 80 243 213 243 245] \
	#(  ) ) >

<primitive 112 temp 4		" size " \
	#( #[ 16 80 226 1 4 33 34 192 243 215 243 245] \
	#(  ) ) >

<primitive 112 temp 5		" remove:ifAbsent: " \
	#( #[ 16 33 224 3 34 165 244 213 115 81 35 201 247 6 16 \
 33 11 40 248 7 242 16 33 35 81 193 208 242 245] \
	#(  ) ) >

<primitive 112 temp 6		" add:withOccurrences: " \
	#( #[ 34 224 4 32 33 189 243 183 242 33 243 245] \
	#(  ) ) >

<primitive 112 temp 7		" add: " \
	#( #[ 16 33 81 16 33 224 2 80 243 213 192 208 242 245] \
	#(  ) ) >

<primitive 112 temp 8		" new " \
	#( #[ 5 40 160 96 245] \
	#(  ) ) >

<primitive 98 #Bag \
	<primitive 97 #Bag #Collection #/u/smalltalk/prelude/bag.st \
	#(  #dict #count ) \
	#( #next #first #occurrencesOf: #size #remove:ifAbsent: #add:withOccurrences: #add: #new  ) \
	temp 4 8 > >

SHAR_EOF
if test 1200 -ne "`wc -c < 'prelude/bag.p'`"
then
	echo shar: error transmitting "'prelude/bag.p'" '(should have been 1200 characters)'
fi
fi # end of overwriting check
if test -f 'prelude/bag.st'
then
	echo shar: will not over-write existing file "'prelude/bag.st'"
else
cat << \SHAR_EOF > 'prelude/bag.st'
Class Bag :Collection
| dict count |
[
        new
                dict <- Dictionary new

|       add: newElement
                dict at: newElement 
                     put: (1 + (dict at: newElement ifAbsent: [0]))

|       add: newObj withOccurrences: anInteger
                anInteger timesRepeat: [ self add: newObj ].
                ^ newObj

|       remove: oldElement ifAbsent: exceptionBlock   | i |
                i <- dict at: oldElement 
                          ifAbsent: [ ^ exceptionBlock value].
                (1 = i) ifTrue:  [dict removeKey: oldElement]
                        ifFalse: [dict at: oldElement put: i - 1 ]

|       size
                ^ dict inject: 0 into: [:x :y | x + y]

|       occurrencesOf: anElement
                ^ dict at: anElement ifAbsent: [0]

|       first
		(count <- dict first) isNil ifTrue: [^ nil].
		count <- count - 1.
		^ dict currentKey

|       next
		[count notNil] whileTrue:
		   [ (count > 0)
		        ifTrue: [count <- count - 1. ^ dict currentKey]
			ifFalse: [(count <- dict next) isNil
					ifTrue: [^ nil] ]].
		^ nil

]
SHAR_EOF
if test 1102 -ne "`wc -c < 'prelude/bag.st'`"
then
	echo shar: error transmitting "'prelude/bag.st'" '(should have been 1102 characters)'
fi
fi # end of overwriting check
if test -f 'prelude/block.p'
then
	echo shar: will not over-write existing file "'prelude/block.p'"
else
cat << \SHAR_EOF > 'prelude/block.p'
temp <- <primitive 110 14 >
<primitive 112 temp 1		" value:value:value:value:value: " \
	#( #[ 85 250 1 140 242 245] \
	#(  ) ) >

<primitive 112 temp 2		" value:value:value:value: " \
	#( #[ 84 250 1 140 242 245] \
	#(  ) ) >

<primitive 112 temp 3		" value:value:value: " \
	#( #[ 83 250 1 140 242 245] \
	#(  ) ) >

<primitive 112 temp 4		" value:value: " \
	#( #[ 82 250 1 140 242 245] \
	#(  ) ) >

<primitive 112 temp 5		" value: " \
	#( #[ 81 250 1 140 242 245] \
	#(  ) ) >

<primitive 112 temp 6		" value " \
	#( #[ 80 250 1 140 242 245] \
	#(  ) ) >

<primitive 112 temp 7		" whileFalse: " \
	#( #[ 32 165 246 5 33 165 242 249 9 243 245] \
	#(  ) ) >

<primitive 112 temp 8		" whileFalse " \
	#( #[ 32 165 246 4 93 242 249 8 243 245] \
	#(  ) ) >

<primitive 112 temp 9		" whileTrue: " \
	#( #[ 32 165 247 5 33 165 242 249 9 243 245] \
	#(  ) ) >

<primitive 112 temp 10		" whileTrue " \
	#( #[ 32 165 247 4 93 242 249 8 243 245] \
	#(  ) ) >

<primitive 112 temp 11		" forkWith: " \
	#( #[ 32 33 11 35 10 40 242 93 243 245] \
	#(  ) ) >

<primitive 112 temp 12		" fork " \
	#( #[ 32 10 33 10 40 242 93 243 245] \
	#(  ) ) >

<primitive 112 temp 13		" newProcessWith: " \
	#( #[ 32 33 250 2 141 243 245] \
	#(  ) ) >

<primitive 112 temp 14		" newProcess " \
	#( #[ 32 250 1 141 243 245] \
	#(  ) ) >

<primitive 98 #Block \
	<primitive 97 #Block #Object #/u/smalltalk/prelude/block.st \
	#(  ) \
	#( #value:value:value:value:value: #value:value:value:value: #value:value:value: #value:value: #value: #value #whileFalse: #whileFalse #whileTrue: #whileTrue #forkWith: #fork #newProcessWith: #newProcess  ) \
	temp 6 3 > >

SHAR_EOF
if test 1632 -ne "`wc -c < 'prelude/block.p'`"
then
	echo shar: error transmitting "'prelude/block.p'" '(should have been 1632 characters)'
fi
fi # end of overwriting check
if test -f 'prelude/block.st'
then
	echo shar: will not over-write existing file "'prelude/block.st'"
else
cat << \SHAR_EOF > 'prelude/block.st'
"
	Class Block.

	Note how whileTrue: and whileFalse: depend upon the parser
	optimizing the loops into control flow, rather than message
	passing.  If this were not the case, whileTrue: would have to
	be implemented using recursion, as follows:

	whileTrue: aBlock
		(self value) ifFalse: [^nil].
		aBlock value.
		^ self whileTrue: aBlock
"
Class Block
[
	newProcess
		^ <primitive 141  self>
|
	newProcessWith: argumentArray
		^ <primitive 141  self argumentArray>
|
	fork
		self newProcess resume.
		^ nil
|
	forkWith: argumentArray
		(self newProcessWith: argumentArray) resume.
		^ nil
|
	whileTrue
		^ [self value ] whileTrue: []
|
	whileTrue: aBlock
		^ [ self value ] whileTrue: [ aBlock value ]
|
	whileFalse
		^ [ self value ] whileFalse: []
|
	whileFalse: aBlock
		^ [ self value ] whileFalse: [ aBlock value ]
|
 	value
		<primitive 140  0>
|
	value: a
		<primitive 140  1>
|
	value: a value: b
		<primitive 140  2>
|
	value: a value: b value: c
		<primitive 140  3>
|
	value: a value: b value: c value: d
		<primitive 140  4>
|
	value: a value: b value: c value: d value: e
		<primitive 140  5>
]
SHAR_EOF
if test 1111 -ne "`wc -c < 'prelude/block.st'`"
then
	echo shar: error transmitting "'prelude/block.st'" '(should have been 1111 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0