pnl@hpfinote.HP.COM (Peter Lim) (04/13/90)
This doesn't exactly constitute a 'source code' so I thought I'll just post it here. To share with the general public. Below is a shell archive of 3 files to allow compiling of the recently posted Berkeley YACC with Microsoft C 5.10 under MesS-DOS. linkopt.msc and makefile.msc are addendum. Whereas defs.h replaces the one that comes with the Berkeley YACC package. A few MesS-DOS specific constants are defined in defs.h conditionally. Seems to work fine for my case. I use a UNIX-like make under MesS-DOS and did "make -f makefile.msc". Have fun, and a nice easter (could be a little late). Regards, ## Life is fast enough as it is ........ Peter Lim. ## .... DON'T PUSH IT !! >>>-------, ########################################### : E-mail: plim@hpsgwg.HP.COM Snail-mail: Hewlett Packard Singapore, : Tel: (065)-279-2289 (ICDS, ICS) | Telnet: 520-2289 1150 Depot Road, __\@/__ ... also at: pnl@hpfipnl.HP.COM Singapore 0410. SPLAT ! ps: If I'm not doing this in accordance with the netland protocol, will the authority (and only the authority) kindly inform me of the 'higher' way to do it. :-). #---------------------------------- cut here ---------------------------------- # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by Peter Lim <pnl@hpfipnl> on Thu Apr 12 17:08:15 1990 # # This archive contains: # defs.h linkopt.msc makefile.msc # # Error checking via sum(1) will be performed. LANG=""; export LANG PATH=/bin:/usr/bin:$PATH; export PATH if sum -r </dev/null >/dev/null 2>&1 then sumopt='-r' else sumopt='' fi echo x - defs.h cat >defs.h <<'@EOF' #include <assert.h> #include <ctype.h> #include <stdio.h> /* machine dependent definitions */ /* the following definitions are for the VAX */ /* they might have to be changed for other machines */ /* MAXCHAR is the largest character value */ /* MAXSHORT is the largest value of a C short */ /* MINSHORT is the most negative value of a C short */ /* MAXTABLE is the maximum table size */ /* BITS_PER_WORD is the number of bits in a C unsigned */ /* WORDSIZE computes the number of words needed to */ /* store n bits */ /* BIT returns the value of the n-th bit starting */ /* from r (0-indexed) */ /* SETBIT sets the n-th bit starting from r */ #ifdef MSDOS #define MAXCHAR 127 #define MAXSHORT 32767 #define MINSHORT -32768 #define MAXTABLE 32500 #define BITS_PER_WORD 16 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD) #define BIT(r, n) ((((r)[(n) >> 4]) >> ((n) & 15)) & 1) #define SETBIT(r, n) ((r)[(n) >> 4] |= (1 << ((n) & 15))) #else #define MAXCHAR 255 #define MAXSHORT 32767 #define MINSHORT -32768 #define MAXTABLE 32500 #define BITS_PER_WORD 32 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD) #define BIT(r, n) ((((r)[(n) >> 5]) >> ((n) & 31)) & 1) #define SETBIT(r, n) ((r)[(n) >> 5] |= (1 << ((n) & 31))) #endif /* character names */ #define NUL '\0' /* the null character */ #define NEWLINE '\n' /* line feed */ #define SP ' ' /* space */ #define BS '\b' /* backspace */ #define HT '\t' /* horizontal tab */ #define VT '\013' /* vertical tab */ #define CR '\r' /* carriage return */ #define FF '\f' /* form feed */ #define QUOTE '\'' /* single quote */ #define DOUBLE_QUOTE '\"' /* double quote */ #define BACKSLASH '\\' /* backslash */ /* defines for constructing filenames */ #ifdef MSDOS #define DEFINES_SUFFIX "_tab.h" #define OUTPUT_SUFFIX "_tab.c" #else #define DEFINES_SUFFIX ".tab.h" #define OUTPUT_SUFFIX ".tab.c" #endif #define VERBOSE_SUFFIX ".output" /* keyword codes */ #define TOKEN 0 #define LEFT 1 #define RIGHT 2 #define NONASSOC 3 #define MARK 4 #define TEXT 5 #define TYPE 6 #define START 7 #define UNION 8 #define IDENT 9 /* symbol classes */ #define UNKNOWN 0 #define TERM 1 #define NONTERM 2 /* the undefined value */ #define UNDEFINED (-1) /* action codes */ #define SHIFT 1 #define REDUCE 2 #define ERROR 3 /* character macros */ #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$') #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7') #define NUMERIC_VALUE(c) ((c) - '0') /* symbol macros */ #define ISTOKEN(s) ((s) < start_symbol) #define ISVAR(s) ((s) >= start_symbol) /* storage allocation macros */ #define FREE(x) (free((char*)(x))) #define MALLOC(n) (malloc((unsigned)(n))) #define NEW(t) ((t*)allocate(sizeof(t))) #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t)))) #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n))) /* the structure of a symbol table entry */ typedef struct bucket bucket; struct bucket { struct bucket *link; struct bucket *next; char *name; char *tag; short value; short index; short prec; char class; char assoc; }; /* the structure of the LR(0) state machine */ typedef struct core core; struct core { struct core *next; struct core *link; short number; short accessing_symbol; short nitems; short items[1]; }; /* the structure used to record shifts */ typedef struct shifts shifts; struct shifts { struct shifts *next; short number; short nshifts; short shift[1]; }; /* the structure used to store reductions */ typedef struct reductions reductions; struct reductions { struct reductions *next; short number; short nreds; short rules[1]; }; /* the structure used to represent parser actions */ typedef struct action action; struct action { struct action *next; short symbol; short number; short prec; char action_code; char assoc; char suppressed; }; /* global variables */ extern char dflag; extern char lflag; extern char tflag; extern char vflag; extern char *myname; extern char *cptr; extern char *line; extern int lineno; extern int outline; extern char *banner[]; extern char *header[]; extern char *body[]; extern char *trailer[]; extern char *action_file_name; extern char *defines_file_name; extern char *input_file_name; extern char *output_file_name; extern char *text_file_name; extern char *union_file_name; extern char *verbose_file_name; extern FILE *action_file; extern FILE *defines_file; extern FILE *input_file; extern FILE *output_file; extern FILE *text_file; extern FILE *union_file; extern FILE *verbose_file; extern int nitems; extern int nrules; extern int nsyms; extern int ntokens; extern int nvars; extern int ntags; extern char unionized; extern char line_format[]; extern int start_symbol; extern char **symbol_name; extern short *symbol_value; extern short *symbol_prec; extern char *symbol_assoc; extern short *ritem; extern short *rlhs; extern short *rrhs; extern short *rprec; extern char *rassoc; extern short **derives; extern char *nullable; extern bucket *first_symbol; extern bucket *last_symbol; extern int nstates; extern core *first_state; extern shifts *first_shift; extern reductions *first_reduction; extern short *accessing_symbol; extern core **state_table; extern shifts **shift_table; extern reductions **reduction_table; extern unsigned *LA; extern short *LAruleno; extern short *lookaheads; extern short *goto_map; extern short *from_state; extern short *to_state; extern action **parser; extern int SRtotal; extern int RRtotal; extern short *SRconflicts; extern short *RRconflicts; extern short *defred; extern short *rules_used; extern short nunused; extern short final_state; /* global functions */ extern char *allocate(); extern bucket *lookup(); extern bucket *make_bucket(); /* system variables */ extern int errno; /* system functions */ extern void free(); extern char *calloc(); extern char *malloc(); extern char *realloc(); extern char *strcpy(); @EOF set `sum $sumopt <defs.h`; if test $1 -ne 57441 then echo ERROR: defs.h checksum is $1 should be 57441 fi chmod 644 defs.h echo x - linkopt.msc cat >linkopt.msc <<'@EOF' closure.obj + error.obj + lalr.obj + lr0.obj + main.obj + mkpar.obj + output.obj + reader.obj + skeleton.obj + symtab.obj + verbose.obj + warshall.obj yacc nul; @EOF set `sum $sumopt <linkopt.msc`; if test $1 -ne 416 then echo ERROR: linkopt.msc checksum is $1 should be 416 fi chmod 644 linkopt.msc echo x - makefile.msc cat >makefile.msc <<'@EOF' DEST = . HDRS = defs.h CFLAGS = -AC LDFLAGS = /STACK:10240 LIBS = LINKER = link MAKEFILE = Makefile OBJS = closure.obj \ error.obj \ lalr.obj \ lr0.obj \ main.obj \ mkpar.obj \ output.obj \ reader.obj \ skeleton.obj \ symtab.obj \ verbose.obj \ warshall.obj PRINT = pr -f -l88 PROGRAM = yacc.exe SRCS = closure.c \ error.c \ lalr.c \ lr0.c \ main.c \ mkpar.c \ output.c \ reader.c \ skeleton.c \ symtab.c \ verbose.c \ warshall.c all: $(PROGRAM) $(PROGRAM): $(OBJS) $(LIBS) @echo -n "Loading $(PROGRAM) ... " @$(LINKER) $(LDFLAGS) @linkopt.msc @echo "done" # @$(LINKER) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROGRAM) clean:; @rm -f $(OBJS) depend:; @mkmf -f $(MAKEFILE) PROGRAM=$(PROGRAM) DEST=$(DEST) index:; @ctags -wx $(HDRS) $(SRCS) install: $(PROGRAM) @echo Installing $(PROGRAM) in $(DEST) @install -s $(PROGRAM) $(DEST) listing:; @$(PRINT) Makefile $(HDRS) $(SRCS) | lpr lint:; @lint $(SRCS) program: $(PROGRAM) tags: $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS) update: $(DEST)/$(PROGRAM) $(DEST)/$(PROGRAM): $(SRCS) $(LIBS) $(HDRS) @make -f $(MAKEFILE) DEST=$(DEST) install ### closure.obj: defs.h error.obj: defs.h lalr.obj: defs.h lr0.c: defs.h main.obj: defs.h mkpar.obj: defs.h output.obj: defs.h reader.obj: defs.h skeleton.obj: defs.h symtab.obj: defs.h verbose.obj: defs.h warshall.obj: defs.h @EOF set `sum $sumopt <makefile.msc`; if test $1 -ne 1353 then echo ERROR: makefile.msc checksum is $1 should be 1353 fi chmod 644 makefile.msc exit 0