berkeley yacc on DOS

Francis Wolff <wolff@alpha.ces.cwru.edu>
Mon, 13 Jul 1992 07:15:26 GMT

          From comp.compilers

Related articles
berkeley yacc on DOS lhhuang@jeeves.waterloo.edu (1992-07-11)
Re: berkeley yacc on DOS epang@sfu.ca (1992-07-13)
berkeley yacc on DOS wolff@alpha.ces.cwru.edu (Francis Wolff) (1992-07-13)
Re: berkeley yacc on DOS tom@smart.bo.open.de (1992-07-14)
berkeley yacc on DOS jar@cheops.HQ.Ileaf.COM (1992-07-20)
Re: berkeley yacc on DOS moss@cs.umass.edu (1992-07-21)
| List of all articles for this month |
Newsgroups: comp.compilers
From: Francis Wolff <wolff@alpha.ces.cwru.edu>
Organization: Computer Engineering Department, CWRU
Date: Mon, 13 Jul 1992 07:15:26 GMT
Keywords: yacc, MSDOS
References: 92-07-024

I am responding to the request if anyone has ported Byacc to the IBM pc.
The two main problems is: one, the pathdivider is backslash and not
forward slash as unix, also MSDOS cannot handle multiple periods in the
file (i.e. y.tab.c should be converted to ytab.c). The reason is MSDOS
philosophy that the period is a filetype and not just another character in
the filename, as is in Unix.


The second problem is the interpretation of "int" on the PC is 16 bits
even with Borlands Turbo C++ compiler version 3.0. (I don't know of
anyone who uses MicroSoft C compiler, the Borland debug environment is
superior to MicroSoft, and this is not a plug for it.) The size of int
can be changed in the <defs.h> file. After making these two major fixups
it worked just dandy even for an 8088 code generation. I experimented
with various segment models (small, medium, large) and found that the
"compact" model worked best (64k code & 1 Meg data).


I minimized my changes (keeping the original code intact as much as
possible) to the following files: defs.h, main.c.


Later, I also changed skeleton.c so that the y.tab.c parser can be read in
as an external file (controlled by a #define flag). This allow me to
further reduce the data size of executable file to a final 105978 bytes.


Since then I have used it for the C grammar of the gcc compiler, flex's
yacc and my own little projects, with excellent results.


In conclusion, If you would like I can e-mail the full three files,
including Borland's project & desk files which recreate my exact work
environment (i.e. model size). I would like them really to be placed at
the archive site.


Thank you,
Frank Wolff.


PS. Included is the beginning header of defs.h


#define MS_DOS


#include <assert.h>
#include <ctype.h>
#include <stdio.h>




/* machine-dependent definitions */
/* the following definitions are for the Tahoe */
/* they might have to be changed for other machines */


/* MAXCHAR is the largest unsigned 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 */


/* 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 MS_DOS
#define SKELETONFILE
#define PATHDIVIDER '\\'
#define FILEPREFIX "ytab"
#define MYNAME "yacc"
#define TEMPFORM "yacc.X"
#define TMPDIRDEFAULT ""
#define CODE_SUFFIX ".cod"
#define DEFINES_SUFFIX ".h"
#define OUTPUT_SUFFIX ".c"
#define VERBOSE_SUFFIX ".out"
#define MAXCHAR 255
#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]|=((unsigned)1<<((n)&15)))


#else
#define PATHDIVIDER '/'
#define FILEPREFIX "y"
#define MYNAME "yacc"
#define TEMPFORM "yacc.XXXXXX"
#define TMPDIRDEFAULT "/tmp"
#define CODE_SUFFIX ".code.c"
#define DEFINES_SUFFIX ".tab.h"
#define OUTPUT_SUFFIX ".tab.c"
#define VERBOSE_SUFFIX ".output"
#include <signal.h>
#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]|=((unsigned)1<<((n)&31)))
#endif
[FYI, slash works fine as a path divider in DOS programs, though it doesn't
hurt to change it to backslash. I'll try to get the diffs for the compilers
archive. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.