v13i047: Boolean expression array evaluator

Rich Salz rsalz at bbn.com
Thu Feb 18 13:43:51 AEST 1988


Submitted-by: jim frost <madd at bucsb.bu.edu>
Posting-number: Volume 13, Issue 47
Archive-name: bool-eval

[  Change the calls to the cget() macro to use int, rather than char.
   See build() in build.c  --r$  ]

Enclosed is the source to a program that I wrote called "bool".  It is
a boolean expression array evaluator and is somewhat useful in
designing PALs (programmed array logic chips) and also if you're an
engineering student who has to develop truth tables for arrays of
functions.  A complete description is enclosed in the file bool.1,
which is a standard format man page.

I have linted the source and it appears to be as clean as it can get
(only real error is that EOF is defined as -1 and it's compared to a
char -- lint says "nonportable" but we've ported it to a variety of
machines with no problem and I can't really fix it anyway since it's a
definition in <stdio.h>).

Sample boolean files are also enclosed.  The whole deal has been
pretty well tested (even though the version numbers are recent we have
dumped a variety of actual tests through it and have not had a mistake
since the last revision).

Cheers,

jim frost
madd at bucsb.bu.edu
..!harvard!bu-cs!madd

-- cut here --
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Copyright Makefile alloc.c bool.1 bool.c bool.h build.c
#   eval_file.c eval_func.c misc.c sample1.b sample2.b sample3.b
#   sample4.b sample5.b token.c

PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Copyright -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Copyright\"
else
echo shar: Extracting \"Copyright\" \(2062 characters\)
sed "s/^X//" >Copyright <<'END_OF_Copyright'
X/* (c) copyright 1987 jim frost
X * all rights reserved
X *
X * this program is copyrighted material.  the author gives permission
X * to duplicate and redistribute this program provided the following
X * conditions are met:
X *   - this copyright notice is not removed.
X *   - all duplicate copies or distributions contain full source
X *     and documentation, including copyright notices.
X *   - duplicate copies or distributions outside a single site are
X *     original distributions without modifications.  (this is to keep
X *     bastardized versions from showing up all over thie place.)
X *
X * this program source may be modified provided the following
X * conditions are met:
X *   - modified source is not distributed to other sites.
X *   - modifications (including, but not limited to, bug fixes) are
X *     sent to the author if the modifications are to be distributed.
X *     no modified source is to be distributed unless done so by the
X *     author.
X *
X * no warranty, either express or implied, is given for this program.
X * the author makes no guarantees of fitness for any use of this
X * program.  the author is not responsible for damages resulting from
X * the use of this program for any purpose.
X *
X * 'site' refers to one or more computers under a single management.
X * 'author' refers to the copyright holder, jim frost.
X * 'source' refers to all files related to this program.
X * 'documentation' refers to non-compilable files in the distribution.
X *
X * basically this notice is to keep me out of trouble should anything
X * go wrong (i really *do* test these things though) and to make sure
X * that the distribution of code is centralized.  makes bug fixes and
X * enhancements much easier.
X *
X * thank you for your attention to this copyright notice.  if everyone
X * follows this, you may find this a useful tool that is pretty well
X * supported.
X *
X * author information:
X *   jim frost                    permanent usnail address:
X *   madd at bucsb.bu.edu            75 washington street
X *   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
X */
END_OF_Copyright
if test 2062 -ne `wc -c <Copyright`; then
    echo shar: \"Copyright\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(2426 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X# (c) copyright 1987 jim frost
X# all rights reserved
X#
X# this program is copyrighted material.  the author gives permission
X# to duplicate and redistribute this program provided the following
X# conditions are met:
X#   - this copyright notice is not removed.
X#   - all duplicate copies or distributions contain full source
X#     and documentation, including copyright notices.
X#   - duplicate copies or distributions outside a single site are
X#     original distributions without modifications.  (this is to keep
X#     bastardized versions from showing up all over thie place.)
X#
X# this program source may be modified provided the following
X# conditions are met:
X#   - modified source is not distributed to other sites.
X#   - modifications (including, but not limited to, bug fixes) are
X#     sent to the author if the modifications are to be distributed.
X#     no modified source is to be distributed unless done so by the
X#     author.
X#
X# no warranty, either express or implied, is given for this program.
X# the author makes no guarantees of fitness for any use of this
X# program.  the author is not responsible for damages resulting from
X# the use of this program for any purpose.
X#
X# 'site' refers to one or more computers under a single management.
X# 'author' refers to the copyright holder, jim frost.
X# 'source' refers to all files related to this program.
X# 'documentation' refers to non-compilable files in the distribution.
X#
X# basically this notice is to keep me out of trouble should anything
X# go wrong (i really *do* test these things though) and to make sure
X# that the distribution of code is centralized.  makes bug fixes and
X# enhancements much easier.
X#
X# thank you for your attention to this copyright notice.  if everyone
X# follows this, you may find this a useful tool that is pretty well
X# supported.
X#
X# author information:
X#   jim frost                    permanent usnail address:
X#   madd at bucsb.bu.edu            75 washington street
X#   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
X#
XCFLAGS= -O
X
Xall:		bool
X
Xbool:		alloc.o bool.o build.o eval_file.o eval_func.o misc.o token.o
X		cc $(CFLAGS) -o bool alloc.o bool.o build.o eval_file.o eval_func.o misc.o token.o
X
Xclean:
X		rm -f *.o
X
X*.c.o:
X		cc -c $(CFLAGS) $*
X
Xalloc.o:	bool.h alloc.c
Xbool.o:		bool.h bool.c
Xbuild.o:	bool.h build.c
Xeval_file.o:	bool.h eval_file.c
Xeval_func.o:	bool.h eval_func.c
Xmisc.o:		bool.h misc.c
Xtoken.o:	bool.h token.c
END_OF_Makefile
if test 2426 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f alloc.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"alloc.c\"
else
echo shar: Extracting \"alloc.c\" \(3725 characters\)
sed "s/^X//" >alloc.c <<'END_OF_alloc.c'
X/* (c) copyright 1987 jim frost
X * all rights reserved
X *
X * this program is copyrighted material.  the author gives permission
X * to duplicate and redistribute this program provided the following
X * conditions are met:
X *   - this copyright notice is not removed.
X *   - all duplicate copies or distributions contain full source
X *     and documentation, including copyright notices.
X *   - duplicate copies or distributions outside a single site are
X *     original distributions without modifications.  (this is to keep
X *     bastardized versions from showing up all over thie place.)
X *
X * this program source may be modified provided the following
X * conditions are met:
X *   - modified source is not distributed to other sites.
X *   - modifications (including, but not limited to, bug fixes) are
X *     sent to the author if the modifications are to be distributed.
X *     no modified source is to be distributed unless done so by the
X *     author.
X *
X * no warranty, either express or implied, is given for this program.
X * the author makes no guarantees of fitness for any use of this
X * program.  the author is not responsible for damages resulting from
X * the use of this program for any purpose.
X *
X * 'site' refers to one or more computers under a single management.
X * 'author' refers to the copyright holder, jim frost.
X * 'source' refers to all files related to this program.
X * 'documentation' refers to non-compilable files in the distribution.
X *
X * basically this notice is to keep me out of trouble should anything
X * go wrong (i really *do* test these things though) and to make sure
X * that the distribution of code is centralized.  makes bug fixes and
X * enhancements much easier.
X *
X * thank you for your attention to this copyright notice.  if everyone
X * follows this, you may find this a useful tool that is pretty well
X * supported.
X *
X * author information:
X *   jim frost                    permanent usnail address:
X *   madd at bucsb.bu.edu            75 washington street
X *   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
X */
X/* alloc.c:
X *
X * this file contains memory allocation and freeing routines
X */
X
X#include "bool.h"
X
Xextern FUNC_LIST  *f_list;
Xextern TOKEN_LIST *t_list;
Xextern int        max_token,
X                  err;
X
XFUNC_LIST *new_func(name)
Xchar *name;
X{ FUNC_LIST *f,*g;
X
X  if ((f= (FUNC_LIST *)malloc(sizeof(FUNC_LIST))) == NULL) {
X    perror("\nMemory allocation error");
X    exit(1);
X  }
X  if (!f_list)
X    f_list= f;
X  else {        /* append to list and check for duplicates */
X    if (!strcmp(name,f_list->func)) {
X      printf("\nDuplicate function name.\n");
X      exit(1);
X    }
X    g= f_list;
X    while (g->next) {
X      if (!strcmp(name,g->func)) {
X        printf("\nDuplicate function name.\n");
X        exit(1);
X      }
X      g= g->next;
X    }
X    g->next= f;
X  }
X  strcpy(f->func,name);
X  f->bool_exp= NULL;
X  f->next= NULL;
X  return(f);
X}
X
X/*
X * this function creates a new token
X */
X
XTOKEN_LIST *new_token(s)
Xchar *s;
X{ TOKEN_LIST *t;
X
X  if ((t= (TOKEN_LIST *)malloc(sizeof(TOKEN_LIST))) == NULL) {
X    perror("\nMemory allocation error");
X    exit(1);
X  }
X  strcpy(t->token,s);
X  t->number= max_token++;
X  t->next= NULL;
X  return(t);
X}
X
X/*
X * this function creates a new BOOL_EXP node
X */
X
XBOOL_EXP *newbnode()
X{ BOOL_EXP *t;
X
X    if ((t= (BOOL_EXP *)malloc(sizeof(BOOL_EXP))) == NULL) {
X      err= 1;
X      perror("\nMemory allocation error");
X      return(NULL);
X    }
X    t->opcode= UNDEF;
X    t->value= UNDEF;
X    t->b1=
X    t->b2= NULL;
X    t->n1=
X    t->n2= 0;
X    return(t);
X}
X
X/*
X * this function free()s up a boolean tree.
X */
X
Xvoid free_tree(b)
XBOOL_EXP *b;
X{
X  if (!b)
X    return;
X  free_tree(b->b1);
X  free_tree(b->b2);
X  free((char *)b);
X}
END_OF_alloc.c
if test 3725 -ne `wc -c <alloc.c`; then
    echo shar: \"alloc.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f bool.1 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"bool.1\"
else
echo shar: Extracting \"bool.1\" \(5993 characters\)
sed "s/^X//" >bool.1 <<'END_OF_bool.1'
X.TH BOOL 1
X.SH NAME
Xbool \- boolean function array evaluator
X.SH SYNOPSIS
X.B bool
X[
X.B -noprint -DEBUG
X] file.b [file2.b ...]
X.SH DESCRIPTION
XThis program reads boolean expressions from a file and produces output
Xindicating the results of every possible input to the expression.  Its
Xtheoretical input limit is unlimited, although the actual limit
Xdepends on the amount of resources your machine will allow.  Multiple
Xoutputs may be done by use of one equation per output.  An infinite
Xnumber of outputs may be done (well, limited by your machine again) by
Xplacing one boolean expression after another.  They will be evaluated
Xin the order they are read.  Expressions may be broken between lines.
XSpaces, tabs, returns, and newlines are ignored.
X
XExpression format accepted by
X.I bool:
X.nf
X
X  <equation> = <token> = <expr>;
X  <expr>     = <expr> <opr> <expr> | (<expr>) | <not> <expr> |
X               <expr> | <token> | <constant>
X  <not>      = '!' | '~' | '/'
X  <constant> = '1' | '0'
X  <token>    = <alpha>[<alphanum>[<alphanum>...]]
X  <alpha>    = 'a' .. 'z' | 'A' .. 'Z'
X  <alphanum> = <alpha> | '0' .. '9'
X  <opr>      = '|' | '+' | '*' | '&' | '^'
X
X  Operator Operation
X  -------- ---------
X     '+'      OR
X     '|'      OR
X     '*'      AND
X     '&'      AND
X     '/'      NOT
X     '!'      NOT
X     '~'      NOT
X     '^'      XOR
X.fi
X.PP
XThe following are two examples of valid equations:
X.nf
X
X  o1= /i5 * (i4 * (i3 + /i3 * i2)) + i5;
X  o2= !i5 & (i4 & (i3 | !i3 & i2)) | i5;
X.fi
X.PP
XThese expressions are identical.
X.SH PRECEDENCE OF OPERATORS
X.PP
XOperators have higher precedence as you move left in the equation.
XPrecedence may be forced by using parentheses.  Expressions within
Xparentheses are evaluated before those outside of parentheses.  For
Xexample:
X.nf
X
X  e1= x + y * z = (x + y) * z; [output of x OR y AND'ed with z]
X  e2= x + (y * z) = y * z + x; [output of y AND z OR'ed with x]
X.fi
X.SH TOKENS
X.PP
XTokens are either inputs to an equation or equation identifiers.
XTokens must start with an alphabetic character or an underscore.
XSubsequent characters may include numerics.  Tokens may be any length
Xbut only the first thirty-one characters or so are significant.
X.PP
XEquation identifiers are handled independently of inputs, so you may
Xhave an equation identifier of the same name as an input.
X.SH COMMENTS
X.PP
XComments may be
Xincluded in the file; they are any characters surrounded by '[' and
X']' or '{' and '}'.
X.SH ERRORS
X.PP
XErrors in source files will be reported when they are discovered and
X.B bool
Xwill stop evaluating the file.  Usually a relevant error message
Xwill be printed.
X.SH FLAGS
X.PP
X-DEBUG causes
X.B bool
Xto print out additional information on how an
Xequation was parsed.  This includes all parentheses (including
Ximplicit parentheses) and errors if there were any.
X.PP
X-noprint suppresses the printing of the source file while it's being
Xread.
X.PP
XAll files passed to
X.B bool
Xshould end in .b or they will be rejected by
X.B bool.
XThis was done to make it harder to pass garbage to
X.B bool.
X.SH PROBLEMS
X.PP
XAny problems you have with
X.B bool
Xshould be sent to madd at bucsf.bu.edu.
X.B Bool
Xhas built in problem checking -- if it discovers an
Xinconsistency, it will print out a big irritating message to let you
Xknow.  While debugging
X.B bool
Xthis message never once appeared, so I
Xdon't expect that it will.  If it does, report it to me immediately
Xand include the source file that caused the error.
X.SH WHO NEEDS IT?
X.PP
XIn case you may be wondering what a boolean equation array evaluator
Xis useful for, here's why I made it.  A friend of mine, who works for
Xa relatively large company that produces a lot of electronic
Xequipment, needed some way to determine every possible output from a
Xseries of inputs to a PAL chip.  With 20 inputs and outputs, this is a
Xpain to do by hand.  So he inquired if I could make an evaluator and
Xhere it is.
X.SH CHANGES
X.PP
XIf you make changes to the source code, please follow the instructions
Xin the copyright.  I'd be interested in any improvements or bug fixes
Xyou might make.
X.SH AUTHOR
X.nf
Xjim frost
Xmadd at bucsb.bu.edu
X.fi
X.SH NOTICE
X.nf
X(c) copyright 1987 jim frost
Xall rights reserved
X
X.fi
Xthis program is copyrighted material.  the author gives permission
Xto duplicate and redistribute this program provided the following
Xconditions are met:
X.nf
X  - this copyright notice is not removed.
X  - all duplicate copies or distributions contain full source
X    and documentation, including copyright notices.
X  - duplicate copies or distributions outside a single site are
X    original distributions without modifications.  (this is to keep
X    bastardized versions from showing up all over thie place.)
X.fi
X.PP
Xthis program source may be modified provided the following
Xconditions are met:
X.nf
X  - modified source is not distributed to other sites.
X  - modifications (including, but not limited to, bug fixes) are
X    sent to the author if the modifications are to be distributed.
X    no modified source is to be distributed unless done so by the
X    author.
X.fi
X.PP
Xno warranty, either express or implied, is given for this program.
Xthe author makes no guarantees of fitness for any use of this
Xprogram.  the author is not responsible for damages resulting from
Xthe use of this program for any purpose.
X.nf
X
X\'site\' refers to one or more computers under a single management.
X\'author\' refers to the copyright holder, jim frost.
X\'source\' refers to all files related to this program.
X'documentation' refers to non-compilable files in the distribution.
X.fi
X.PP
Xbasically this notice is to keep me out of trouble should anything
Xgo wrong (i really *do* test these things though) and to make sure
Xthat the distribution of code is centralized.  makes bug fixes and
Xenhancements much easier.
X.PP
Xthank you for your attention to this copyright notice.  if everyone
Xollows this, you may find this a useful tool that is pretty well
Xsupported.
X.SH FILES
X.nf
Xsample?.b - sample source files
X.fi
X.SH BUGS
X.PP
XNone so far.
END_OF_bool.1
if test 5993 -ne `wc -c <bool.1`; then
    echo shar: \"bool.1\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f bool.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"bool.c\"
else
echo shar: Extracting \"bool.c\" \(3685 characters\)
sed "s/^X//" >bool.c <<'END_OF_bool.c'
X/* (c) copyright 1987 jim frost
X * all rights reserved
X *
X * this program is copyrighted material.  the author gives permission
X * to duplicate and redistribute this program provided the following
X * conditions are met:
X *   - this copyright notice is not removed.
X *   - all duplicate copies or distributions contain full source
X *     and documentation, including copyright notices.
X *   - duplicate copies or distributions outside a single site are
X *     original distributions without modifications.  (this is to keep
X *     bastardized versions from showing up all over thie place.)
X *
X * this program source may be modified provided the following
X * conditions are met:
X *   - modified source is not distributed to other sites.
X *   - modifications (including, but not limited to, bug fixes) are
X *     sent to the author if the modifications are to be distributed.
X *     no modified source is to be distributed unless done so by the
X *     author.
X *
X * no warranty, either express or implied, is given for this program.
X * the author makes no guarantees of fitness for any use of this
X * program.  the author is not responsible for damages resulting from
X * the use of this program for any purpose.
X *
X * 'site' refers to one or more computers under a single management.
X * 'author' refers to the copyright holder, jim frost.
X * 'source' refers to all files related to this program.
X * 'documentation' refers to non-compilable files in the distribution.
X *
X * basically this notice is to keep me out of trouble should anything
X * go wrong (i really *do* test these things though) and to make sure
X * that the distribution of code is centralized.  makes bug fixes and
X * enhancements much easier.
X *
X * thank you for your attention to this copyright notice.  if everyone
X * follows this, you may find this a useful tool that is pretty well
X * supported.
X *
X * author information:
X *   jim frost                    permanent usnail address:
X *   madd at bucsb.bu.edu            75 washington street
X *   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
X */
X/* bool.c:
X *
X * this program evaluates boolean equations and builds truth tables from
X * the equations.
X *
X * history:
X *   9.29.87    original version.
X *   10.19.87   single expression (no operator) bugs fixed.  it couldn't
X *              handle a single expression.  FALSE constant bug fixed.
X *              returned TRUE by mistake.  typo.  changes made to output
X *              to make it more readable.  bug in centering function of
X *              the evaluation print routine fixed.  forgot to follow the
X *              evaluated number by a space.
X *   10.20.87   duplicate function declaration error fixed.  wouldn't
X *              find duplicate function name if the duplicate was the
X *              first in the function list.
X */
X
X#include "bool.h"
X
Xint debug_mode,
X    no_print;
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{ FILE *f;
X  int a;
X
X  debug_mode= 0; /* no debugging mode unless -D */
X  no_print= 0;   /* print unless -n */
X
X  if (argc == 1) {
X    printf("Usage: %s [-DEBUG -noprint] filename [filename ...]\n",PROG);
X    exit(1);
X  }
X
X/*
X * evaluate switches
X */
X
X  for (a= 1; *argv[a] == '-'; a++) {
X    if ((!strcmp(argv[a]+1,"DEBUG")) || (!strcmp(argv[a]+1,"D")))
X      debug_mode= 1;
X    else if ((!strcmp(argv[a]+1,"noprint")) || (!strcmp(argv[a]+1,"n")))
X      no_print= 1;
X  }
X
X/*
X * evaluate for every file on command line
X */
X
X  for (; a < argc; a++) {
X    if (strcmp(argv[a]+strlen(argv[a])-2,".b"))
X      printf("%s: not %s source file\n",argv[a],PROG);
X    else if ((f= fopen(argv[a],"r")) != NULL) {
X      eval_file(f);
X      fclose(f);
X    }
X    else
X      perror(argv[a]);
X  }
X}
END_OF_bool.c
if test 3685 -ne `wc -c <bool.c`; then
    echo shar: \"bool.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f bool.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"bool.h\"
else
echo shar: Extracting \"bool.h\" \(3766 characters\)
sed "s/^X//" >bool.h <<'END_OF_bool.h'
X/* (c) copyright 1987 jim frost
X * all rights reserved
X *
X * this program is copyrighted material.  the author gives permission
X * to duplicate and redistribute this program provided the following
X * conditions are met:
X *   - this copyright notice is not removed.
X *   - all duplicate copies or distributions contain full source
X *     and documentation, including copyright notices.
X *   - duplicate copies or distributions outside a single site are
X *     original distributions without modifications.  (this is to keep
X *     bastardized versions from showing up all over thie place.)
X *
X * this program source may be modified provided the following
X * conditions are met:
X *   - modified source is not distributed to other sites.
X *   - modifications (including, but not limited to, bug fixes) are
X *     sent to the author if the modifications are to be distributed.
X *     no modified source is to be distributed unless done so by the
X *     author.
X *
X * no warranty, either express or implied, is given for this program.
X * the author makes no guarantees of fitness for any use of this
X * program.  the author is not responsible for damages resulting from
X * the use of this program for any purpose.
X *
X * 'site' refers to one or more computers under a single management.
X * 'author' refers to the copyright holder, jim frost.
X * 'source' refers to all files related to this program.
X * 'documentation' refers to non-compilable files in the distribution.
X *
X * basically this notice is to keep me out of trouble should anything
X * go wrong (i really *do* test these things though) and to make sure
X * that the distribution of code is centralized.  makes bug fixes and
X * enhancements much easier.
X *
X * thank you for your attention to this copyright notice.  if everyone
X * follows this, you may find this a useful tool that is pretty well
X * supported.
X *
X * author information:
X *   jim frost                    permanent usnail address:
X *   madd at bucsb.bu.edu            75 washington street
X *   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
X */
X/* bool.h:
X *
X * definition file for ttable.c
X */
X
X#include <stdio.h>
X
X#define PROG     "bool"    /* our name */
X#define MAXTOKEN 32        /* maximum length of a token */
X
Xtypedef struct bool_exp {
X  int opcode,          /* operation code/constant/token */
X      value;           /* token number/opcode char */
X  char n1,             /* unary "not" indicators */
X       n2;
X  struct bool_exp *b1, /* boolean expressions */
X                  *b2;
X} BOOL_EXP;
X
X/*
X * opcode field values
X */
X
X#define UNDEF -1 /* undefined operation */
X#define TRUE   0
X#define FALSE  1
X#define TOKEN  2
X#define OR     3
X#define AND    4
X#define XOR    5
X
Xtypedef struct token_list {
X  char token[MAXTOKEN];    /* character representation of the token */
X  int  number,             /* numeric token representation */
X       value;              /* current value of token */
X  struct token_list *next; /* next token in list */
X} TOKEN_LIST;
X
Xtypedef struct func_list {
X  char func[MAXTOKEN];     /* name of this function */
X  BOOL_EXP *bool_exp;      /* boolean expression */
X  struct func_list *next;  /* next function in list */
X} FUNC_LIST;
X
XBOOL_EXP   *build(),
X           *newbnode();
XFUNC_LIST  *new_func();
XTOKEN_LIST *new_token();
Xvoid       eval_file(),
X           eval_func(),
X           free_tree(),
X           panic(),
X           print_token(),
X           print_tree();
Xint        begtok(),
X           eval_tree(),
X           get_token(),
X           intok(),
X           token_val();
Xchar       *malloc(),
X           *strcpy();
X
X#define cget(F,C) if (!feof(F)) {\
X                    C= fgetc(F);\
X                    if ((!no_print) && (C != EOF))\
X                      printf("%c",C);\
X                  } else
END_OF_bool.h
if test 3766 -ne `wc -c <bool.h`; then
    echo shar: \"bool.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f build.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"build.c\"
else
echo shar: Extracting \"build.c\" \(6997 characters\)
sed "s/^X//" >build.c <<'END_OF_build.c'
X/* (c) copyright 1987 jim frost
X * all rights reserved
X *
X * this program is copyrighted material.  the author gives permission
X * to duplicate and redistribute this program provided the following
X * conditions are met:
X *   - this copyright notice is not removed.
X *   - all duplicate copies or distributions contain full source
X *     and documentation, including copyright notices.
X *   - duplicate copies or distributions outside a single site are
X *     original distributions without modifications.  (this is to keep
X *     bastardized versions from showing up all over thie place.)
X *
X * this program source may be modified provided the following
X * conditions are met:
X *   - modified source is not distributed to other sites.
X *   - modifications (including, but not limited to, bug fixes) are
X *     sent to the author if the modifications are to be distributed.
X *     no modified source is to be distributed unless done so by the
X *     author.
X *
X * no warranty, either express or implied, is given for this program.
X * the author makes no guarantees of fitness for any use of this
X * program.  the author is not responsible for damages resulting from
X * the use of this program for any purpose.
X *
X * 'site' refers to one or more computers under a single management.
X * 'author' refers to the copyright holder, jim frost.
X * 'source' refers to all files related to this program.
X * 'documentation' refers to non-compilable files in the distribution.
X *
X * basically this notice is to keep me out of trouble should anything
X * go wrong (i really *do* test these things though) and to make sure
X * that the distribution of code is centralized.  makes bug fixes and
X * enhancements much easier.
X *
X * thank you for your attention to this copyright notice.  if everyone
X * follows this, you may find this a useful tool that is pretty well
X * supported.
X *
X * author information:
X *   jim frost                    permanent usnail address:
X *   madd at bucsb.bu.edu            75 washington street
X *   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
X */
X/* build.c:
X *
X * this reads in a file from a pointer and builds an evaluation tree.
X */
X
X#include "bool.h"
X
Xextern int err,   /* syntax error detected */
X           paren, /* parenthesis depth counter */
X           no_print;
X
X/*
X * this function checks a BOOL_EXP for syntax errors and sets "err"
X * accordingly.
X */
X
Xstatic void check_syn(t)
XBOOL_EXP *t;
X{
X  switch (t->opcode) {
X    case FALSE :
X    case TRUE :
X    case TOKEN :
X      return;
X    case AND :
X    case OR :
X    case XOR :
X      if ((!t->b1) && (!t->b2)) {
X        err= 1;
X        printf("\nNull expression.\n");
X      }
X      else if (!t->b2) {
X        err= 1;
X        printf("\nMissing expression.\n");
X      }
X      return;
X    case UNDEF :
X      if ((t->b1) && (!(t->b2))) { /* single expression */
X        check_syn(t->b1);
X        return;
X      }
X      err= 1;
X      printf("\nMissing operator.\n");
X      t->value= '?';
X      return;
X    default :
X      panic("check_syn");
X  }
X}
X
XBOOL_EXP *build(f)
XFILE       *f;            /* file we are getting input from */
X{ int      a;
X  char     c,             /* current char we are reading */
X           tok[MAXTOKEN]; /* current token we are reading */
X  BOOL_EXP *t,*u;         /* current tree node and child tree node */
X
X/*
X * if eof then make SURE we return null.  this will force a synerr
X * during syntax checking above or an indicative error message from
X * top level.
X */
X
X  if (feof(f))
X    return(NULL);
X
X/*
X * get a new BOOL_EXP node to build with
X */
X
X  t= newbnode();
X
X/*
X * loop through the entire file.  a syntax error will automatically
X * drop out of this loop and back up through the tree.  exiting is
X * also done depending on conditions found in the source.
X */
X
X  c= ' ';
X  while (!feof(f))  {
X
X    if (c == ';') {
X      check_syn(t);
X      return(t);
X    }
X    if ((c == ' ') || (c == '\011') || (c == '\n') || (c == '\r')) {
X      cget(f,c);
X      continue;
X    }
X/*
X * end subexression evaluation.  do syntax error checking at current
X * node to be sure it's ok.  return status to caller.
X */
X
X    if (c == ')') {
X      if (!paren--) {
X        err= 1;
X        printf("\nMismatched parenthesis.\n");
X      }
X      else
X        check_syn(t);
X      return(t);
X    }
X
X/*
X * if structure is full then we have to make it a substruct.  note
X * that changing this can alter precedence determination from left
X * to right or right to left.
X */
X
X    if (t->b2) {
X      u= t;
X      t= newbnode();
X      t->b1= u;
X    }
X
X    if (begtok(c)) { /* found a token so evaluate it */
X
X/*
X * loop for token name
X */
X
X      a= 0;
X      do {
X        if (a < MAXTOKEN) /* truncate overlong tokens */
X          tok[a]= c;
X        a++;
X        if (feof(f))
X          break;
X        cget(f,c);
X      } while (intok(c));
X      tok[a]= '\0';
X
X/*
X * build node for token
X */
X
X      u= newbnode();
X      u->opcode= TOKEN;
X      u->value= get_token(tok);
X      if (t->b1)
X        t->b2= u;
X      else
X        t->b1= u;
X    }
X    else {
X      switch (c) {
X
X/*
X * comments.  this doesn't have a possible backslash preceeding it because
X * I really don't care if you want to put special chars in your comments.
X * two different comment types are used to allow you to comment out whole
X * sections of code, which IS useful.
X */
X
X        case '[' :
X          while (c != ']') {
X            if (feof(f)) {
X              err= 1;
X              return(t);
X            }
X            cget(f,c);
X          }
X          break;
X        case '{' :
X          while (c != '}') {
X            if (feof(f)) {
X              err= 1;
X              return(t);
X            }
X            cget(f,c);
X          }
X          break;
X
X/*
X * true or false
X */
X
X        case '1' :
X        case '0' :
X          u= newbnode();
X          if (t->b1)
X            t->b2= u;
X          else
X            t->b1= u;
X          if (c == '0')
X            u->opcode= FALSE;
X          else
X            u->opcode= TRUE;
X          break;
X          
X/*
X * subexpressions begin with a paren
X */
X
X        case '(' :
X          paren++;
X          if (t->b1)
X            t->b2= build(f);
X          else
X            t->b1= build(f);
X          if (err)
X            return(t);
X          break;
X
X/*
X * handle each unary operation
X */
X
X        case '!' : /* not */
X        case '~' :
X        case '/' :
X          if (t->b1)
X            t->n2= c;
X          else
X            t->n1= c;
X          break;
X
X/*
X * handle each of the binary operators
X */
X
X        case '&' : /* and */
X        case '*' :
X          t->opcode= AND;
X          t->value= c;
X          break;
X        case '|' : /* or */
X        case '+' :
X          t->opcode= OR;
X          t->value= c;
X          break;
X        case '^' : /* xor */
X          t->opcode= XOR;
X          t->value= c;
X          break;
X        default :
X          err= 1;
X          printf("\nIllegal character '%c'\n",c);
X          return(t);
X      }
X      cget(f,c);
X    }
X  }
X  check_syn(t); /* check for syntax errors before leaving */
X  return(t);
X}
END_OF_build.c
if test 6997 -ne `wc -c <build.c`; then
    echo shar: \"build.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f eval_file.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"eval_file.c\"
else
echo shar: Extracting \"eval_file.c\" \(5560 characters\)
sed "s/^X//" >eval_file.c <<'END_OF_eval_file.c'
X/* (c) copyright 1987 jim frost
X * all rights reserved
X *
X * this program is copyrighted material.  the author gives permission
X * to duplicate and redistribute this program provided the following
X * conditions are met:
X *   - this copyright notice is not removed.
X *   - all duplicate copies or distributions contain full source
X *     and documentation, including copyright notices.
X *   - duplicate copies or distributions outside a single site are
X *     original distributions without modifications.  (this is to keep
X *     bastardized versions from showing up all over thie place.)
X *
X * this program source may be modified provided the following
X * conditions are met:
X *   - modified source is not distributed to other sites.
X *   - modifications (including, but not limited to, bug fixes) are
X *     sent to the author if the modifications are to be distributed.
X *     no modified source is to be distributed unless done so by the
X *     author.
X *
X * no warranty, either express or implied, is given for this program.
X * the author makes no guarantees of fitness for any use of this
X * program.  the author is not responsible for damages resulting from
X * the use of this program for any purpose.
X *
X * 'site' refers to one or more computers under a single management.
X * 'author' refers to the copyright holder, jim frost.
X * 'source' refers to all files related to this program.
X * 'documentation' refers to non-compilable files in the distribution.
X *
X * basically this notice is to keep me out of trouble should anything
X * go wrong (i really *do* test these things though) and to make sure
X * that the distribution of code is centralized.  makes bug fixes and
X * enhancements much easier.
X *
X * thank you for your attention to this copyright notice.  if everyone
X * follows this, you may find this a useful tool that is pretty well
X * supported.
X *
X * author information:
X *   jim frost                    permanent usnail address:
X *   madd at bucsb.bu.edu            75 washington street
X *   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
X */
X/* eval_file.c:
X *
X * this function calls each of the necessary routines to build and
X * evaluate a tree.
X */
X
X#include "bool.h"
X
Xint err,
X    paren,
X    max_token,
X    print_err;
X
Xextern int debug_mode,
X           no_print;
X
Xstatic char *line= "----------------------------------------------------";
X
XTOKEN_LIST *t_list;
XFUNC_LIST  *f_list;
X
X/*
X * this function processes each boolean equation
X */
X
Xvoid eval_file(f)
XFILE *f;
X{ FUNC_LIST  *fn;
X  TOKEN_LIST *t;
X  char       func[MAXTOKEN],
X             c;
X  int        a;
X
X  paren= 0;
X  max_token= 0;
X  t_list= NULL;
X  f_list= NULL;
X
X/*
X * loop through file to build all functions
X */
X
X  func[0]= '\0';
X  c= ' ';
X  while (!feof(f)) {
X    if (blank(c)) {
X      cget(f,c);
X    }
X    else if (begtok(c)) {
X      a= 0;
X      do {
X        func[a++]= c;
X        cget(f,c);
X      } while(intok(c));
X      func[a]= '\0';
X    }
X
X/*
X * when we hit an '=', start building a function
X */
X
X    else if ((c == '=') && strlen(func)) {
X      fn= new_func(func);
X      fn->bool_exp= build(f);
X
X/*
X * if we got a syntax error, explain that we're printing the function
X * as evaluated up to the error.  otherwise, print out the header and
X * do the tree evaluation.
X */
X
X      if (err) {
X        if (debug_mode) {
X          printf("Parsed function up to error:\n");
X          print_err= 0;
X          printf("%s= ",func);
X          print_tree(fn->bool_exp);
X          printf("\n");
X        }
X        exit(1);
X      }
X      if (debug_mode) {
X        printf("\n\nFunction parsed as:\n");
X        printf("%s= ",func);
X        print_tree(fn->bool_exp);
X        printf(";\n");
X      }
X      func[0]= '\0';    /* reset for next run */
X      cget(f,c);
X    }
X    else switch (c) {
X      case '[' :
X        do
X          cget(f,c);
X        while ((!feof(f)) && (c != ']'));
X        cget(f,c);
X        break;
X      case '{' :
X        do
X          cget(f,c);
X        while ((!feof(f)) && (c != '}'));
X        cget(f,c);
X        break;
X      case '=' :
X        printf("\nMissing equation declaration.\n");
X        exit(1);
X      case EOF :
X        printf("\nUnexpected end of file.\n");
X        exit(1);
X      default :
X        printf("\nIllegal character (possibly missing equation definition).\n");
X        exit(1);
X    }
X  }
X  printf("\n");
X  t= t_list;
X  while (t) {
X    printf("%s ",t->token);
X    t= t->next;
X  }
X  printf("| ");
X  fn= f_list;
X  while (fn) {
X    printf("%s ",fn->func);
X    fn= fn->next;
X  }
X  printf("\n");
X  t= t_list;
X  while (t) {
X    printf("%*.*s",strlen(t->token)+1,strlen(t->token)+1,line);
X    t= t->next;
X  }
X  printf("+-");
X  fn= f_list;
X  while (fn) {
X    printf("%*.*s",strlen(fn->func)+1,strlen(fn->func)+1,line);
X    fn= fn->next;
X  }
X  printf("\n");
X  eval_func(t_list); /* dump output */
X
X/*
X * because bool can be run on a lot of files each execution, we have
X * to free up memory allocated for each file.  while we're at it, we
X * print out lists of stuff used in the file if we're in debug mode.
X * might be useful to somebody.
X */
X
X  if (debug_mode) {
X    printf("\n\nFunctions Defined\n");
X    printf("-----------------\n");
X  }
X  while (f_list) {
X    if (debug_mode)
X      printf("%s\n",f_list->func);
X    fn= f_list;
X    f_list= f_list->next;
X    free_tree(fn->bool_exp);
X    free((char *)fn);
X  }
X  if (debug_mode) {
X    printf("\n\nTokens Defined\n");
X    printf("--------------\n");
X  }
X  while (t_list) {
X    if (debug_mode)
X      printf("%s\n",t_list->token);
X    t= t_list;
X    t_list= t_list->next;
X    free((char *)t);
X  }
X}
END_OF_eval_file.c
if test 5560 -ne `wc -c <eval_file.c`; then
    echo shar: \"eval_file.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f eval_func.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"eval_func.c\"
else
echo shar: Extracting \"eval_func.c\" \(3865 characters\)
sed "s/^X//" >eval_func.c <<'END_OF_eval_func.c'
X/* (c) copyright 1987 jim frost
X * all rights reserved
X *
X * this program is copyrighted material.  the author gives permission
X * to duplicate and redistribute this program provided the following
X * conditions are met:
X *   - this copyright notice is not removed.
X *   - all duplicate copies or distributions contain full source
X *     and documentation, including copyright notices.
X *   - duplicate copies or distributions outside a single site are
X *     original distributions without modifications.  (this is to keep
X *     bastardized versions from showing up all over thie place.)
X *
X * this program source may be modified provided the following
X * conditions are met:
X *   - modified source is not distributed to other sites.
X *   - modifications (including, but not limited to, bug fixes) are
X *     sent to the author if the modifications are to be distributed.
X *     no modified source is to be distributed unless done so by the
X *     author.
X *
X * no warranty, either express or implied, is given for this program.
X * the author makes no guarantees of fitness for any use of this
X * program.  the author is not responsible for damages resulting from
X * the use of this program for any purpose.
X *
X * 'site' refers to one or more computers under a single management.
X * 'author' refers to the copyright holder, jim frost.
X * 'source' refers to all files related to this program.
X * 'documentation' refers to non-compilable files in the distribution.
X *
X * basically this notice is to keep me out of trouble should anything
X * go wrong (i really *do* test these things though) and to make sure
X * that the distribution of code is centralized.  makes bug fixes and
X * enhancements much easier.
X *
X * thank you for your attention to this copyright notice.  if everyone
X * follows this, you may find this a useful tool that is pretty well
X * supported.
X *
X * author information:
X *   jim frost                    permanent usnail address:
X *   madd at bucsb.bu.edu            75 washington street
X *   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
X */
X/* eval_func.c:
X *
X * this contains boolean expression evaluation routines.
X */
X
X#include "bool.h"
X
Xextern FUNC_LIST  *f_list;
Xextern TOKEN_LIST *t_list;
Xextern int        line;
X/*
X * this function evaluates a boolean expression tree
X */
X
Xint eval_exp(b)
XBOOL_EXP *b;
X{ int e1, e2;
X
X  if (b->opcode > TOKEN) {
X    e1= eval_exp(b->b1);
X    e2= eval_exp(b->b2);
X    if (b->n1)
X      e1= !e1;
X    if (b->n2)
X      e2= !e2;
X  }
X  switch(b->opcode) {
X    case UNDEF : /* single expressions have undefined opcodes */
X      if (b->n1)
X        return(!eval_exp(b->b1));
X      else
X        return(eval_exp(b->b1));
X    case TRUE :
X      return(1);
X    case FALSE :
X      return(0);
X    case TOKEN :
X      return(token_val(b->value));
X    case OR :
X      return(e1 || e2);
X    case AND :
X      return(e1 && e2);
X    case XOR :
X      return((e1 || e2) && (!(e1 && e2)));
X  }
X}
X
X/*
X * this routine evaluates a function for all possible values of all tokens
X */
X
Xvoid eval_func(t)
XTOKEN_LIST   *t;
X{ FUNC_LIST  *f;
X  TOKEN_LIST *u;
X  int        l1,l2;
X
X  if (t == NULL) { /* end of list so do evaluations */
X
X/*
X * print out values of each token
X */
X
X    u= t_list;
X    while (u) {
X      l1= l2= strlen(u->token)/2;
X      if (!(strlen(u->token) % 2))
X        l1--;
X      printf("%*.*s%d%*.*s ",l1,l1,"",u->value,l2,l2,"");
X      u= u->next;
X    }
X    printf("| ");
X
X/*
X * print out values of each tree
X */
X
X    f= f_list;
X    while(f) {
X      l1= l2= strlen(f->func)/2;
X      if (!(strlen(f->func) % 2))
X        l1--;
X      printf("%*.*s%d%*.*s ",l1,l1,"",eval_exp(f->bool_exp),l2,l2,"");
X      f= f->next;
X    }
X    printf("\n");
X    return;
X  }
X
X/*
X * this section handles value setting to evaluate for all possible
X * token values.
X */
X
X  t->value= 0;
X  eval_func(t->next);
X  t->value= 1;
X  eval_func(t->next);
X}
END_OF_eval_func.c
if test 3865 -ne `wc -c <eval_func.c`; then
    echo shar: \"eval_func.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f misc.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"misc.c\"
else
echo shar: Extracting \"misc.c\" \(3754 characters\)
sed "s/^X//" >misc.c <<'END_OF_misc.c'
X/* (c) copyright 1987 jim frost
X * all rights reserved
X *
X * this program is copyrighted material.  the author gives permission
X * to duplicate and redistribute this program provided the following
X * conditions are met:
X *   - this copyright notice is not removed.
X *   - all duplicate copies or distributions contain full source
X *     and documentation, including copyright notices.
X *   - duplicate copies or distributions outside a single site are
X *     original distributions without modifications.  (this is to keep
X *     bastardized versions from showing up all over thie place.)
X *
X * this program source may be modified provided the following
X * conditions are met:
X *   - modified source is not distributed to other sites.
X *   - modifications (including, but not limited to, bug fixes) are
X *     sent to the author if the modifications are to be distributed.
X *     no modified source is to be distributed unless done so by the
X *     author.
X *
X * no warranty, either express or implied, is given for this program.
X * the author makes no guarantees of fitness for any use of this
X * program.  the author is not responsible for damages resulting from
X * the use of this program for any purpose.
X *
X * 'site' refers to one or more computers under a single management.
X * 'author' refers to the copyright holder, jim frost.
X * 'source' refers to all files related to this program.
X * 'documentation' refers to non-compilable files in the distribution.
X *
X * basically this notice is to keep me out of trouble should anything
X * go wrong (i really *do* test these things though) and to make sure
X * that the distribution of code is centralized.  makes bug fixes and
X * enhancements much easier.
X *
X * thank you for your attention to this copyright notice.  if everyone
X * follows this, you may find this a useful tool that is pretty well
X * supported.
X *
X * author information:
X *   jim frost                    permanent usnail address:
X *   madd at bucsb.bu.edu            75 washington street
X *   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
X */
X/* misc.c:
X *
X * any miscellaneous functions that i didn't think belonged anywhere
X * else.
X */
X
X#include "bool.h"
X
Xextern int print_err;
X
Xint blank(c)
Xchar c;
X{
X  return((c == ' ') || (c == '\011') || (c == '\n') || (c == '\r'));
X}
X
X/*
X * this function prints out the tree.  if the tree is incomplete, it
X * just stops.
X */
X
Xvoid print_tree(b)
XBOOL_EXP *b;
X{ if (b == NULL) {
X    if (!print_err) {
X      printf("?");
X      print_err= 1;
X    }
X    return;
X  }
X  switch (b->opcode) {
X    case FALSE :
X      printf("0");
X      break;
X    case TRUE :
X      printf("1");
X      break;
X    case TOKEN :
X      print_token(b->value);
X      break;
X    case UNDEF :    /* all of these have a char stored in b-value */
X      if ((b->b1) && (!b->b2)) {
X        if (b->n1)
X          printf("!");
X        print_tree(b->b1);
X      }
X      else
X        print_err= 1;
X      break;
X    case OR :
X    case AND :
X    case XOR :
X      printf("(");
X      if (b->n1)                     /* left not */
X        printf("%c",b->n1);
X      print_tree(b->b1);             /* left tree */
X      printf(" %c ",(char)b->value); /* operator */
X      if (b->n2)                     /* right not */
X        printf("%c",b->n2);
X      print_tree(b->b2);             /* right tree */
X      if (b->b2)                     /* only print if not syntax err */
X        printf(")");
X      break;
X    default :
X      panic("print_tree");
X  }
X}
X
X
X/*
X * we got a real serious error
X */
X
Xvoid panic(s)
Xchar *s;
X{
X  printf("\n\nPANIC!!  Internal program error in %s\n",s);
X  printf("This error should not have happened.  Please contact you distributer\n");
X  printf("and keep a sample of the data that caused this crash.\n");
X  exit(1);
X}
X
END_OF_misc.c
if test 3754 -ne `wc -c <misc.c`; then
    echo shar: \"misc.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f sample1.b -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"sample1.b\"
else
echo shar: Extracting \"sample1.b\" \(358 characters\)
sed "s/^X//" >sample1.b <<'END_OF_sample1.b'
X[* this is a bool sample source file.  it's really simple but it shows
X * the format of a bool source file and shows how the different types
X * of comment delimiters can be used. ]
X
Xtest= a + b * !c; [ first equation ]
X
X{ we decided we didn't like this equation:
Xmissing= a ^ b;   [ equation that we are taking out ]
X}
X
Xtest2 = a | c;    [ second equation ]
END_OF_sample1.b
if test 358 -ne `wc -c <sample1.b`; then
    echo shar: \"sample1.b\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f sample2.b -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"sample2.b\"
else
echo shar: Extracting \"sample2.b\" \(147 characters\)
sed "s/^X//" >sample2.b <<'END_OF_sample2.b'
X[* this is a sample bool source file.  it demonstrates precedence forcing. ]
X
Xfoo   = this & !is | (a + little) ^ test;
Xfubar = little | test ^ 1;
END_OF_sample2.b
if test 147 -ne `wc -c <sample2.b`; then
    echo shar: \"sample2.b\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f sample3.b -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"sample3.b\"
else
echo shar: Extracting \"sample3.b\" \(305 characters\)
sed "s/^X//" >sample3.b <<'END_OF_sample3.b'
X[* this is a sample bool source file.  it contains an error -- the expression
X * following the operator '&' is missing.  it demonstrates the kind of error
X * trapping that bool does.  you might want to try using the -DEBUG flag to
X * see the equation that bool thought this was. ]
X
Xexplode= this + !is &;
END_OF_sample3.b
if test 305 -ne `wc -c <sample3.b`; then
    echo shar: \"sample3.b\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f sample4.b -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"sample4.b\"
else
echo shar: Extracting \"sample4.b\" \(509 characters\)
sed "s/^X//" >sample4.b <<'END_OF_sample4.b'
X[* this is a bool sample source file.  it was an actual assignment that
X * a couple of friends of mine had and it pointed out a series of bugs
X * that i had missed.]
X
Xf0= !y | (w & !x & !z);        [ y' + wx'z' ]
Xf1= x & !y;                    [ xy' ]
Xf2= !x & !z;                   [ x'z' ]
Xf3= (x & z) | (w & !x & !y);   [ xz + wx'y' ]
Xf4= !w;                        [ w' ]
Xf5= w ^ x ^ y ^ z;             [ w xor x xor y xor z ]
Xf6= !x & y & !z;               [ x'yz' ]
Xf7= 1;                         [ 1 ]
END_OF_sample4.b
if test 509 -ne `wc -c <sample4.b`; then
    echo shar: \"sample4.b\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f sample5.b -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"sample5.b\"
else
echo shar: Extracting \"sample5.b\" \(431 characters\)
sed "s/^X//" >sample5.b <<'END_OF_sample5.b'
X[* this is a really big example in an attempt to see what will happen.
X]
X
Xf1= a ^ b ^ c ^ d ^ e ^ f ^ g ^ h ^ i ^ j ^ k ^ l ^ m ^ n ^ o ^
X   p ^ q ^ r ^ s ^ t ^ u ^ v ^ w ^ x ^ y ^ z;
Xf2= !a ^ !b ^ !c ^ !d ^ !e ^ !f ^ !g ^ !h ^ !i ^ !j ^ !k ^ !l ^ !m ^ !n ^ !o ^
X   !p ^ !q ^ !r ^ !s ^ !t ^ !u ^ !v ^ !w ^ !x ^ !y ^ !z;
Xf3= a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + 
X   p + q + r + s + t + u + v + w + x + y + z;
END_OF_sample5.b
if test 431 -ne `wc -c <sample5.b`; then
    echo shar: \"sample5.b\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f token.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"token.c\"
else
echo shar: Extracting \"token.c\" \(3916 characters\)
sed "s/^X//" >token.c <<'END_OF_token.c'
X/* (c) copyright 1987 jim frost
X * all rights reserved
X *
X * this program is copyrighted material.  the author gives permission
X * to duplicate and redistribute this program provided the following
X * conditions are met:
X *   - this copyright notice is not removed.
X *   - all duplicate copies or distributions contain full source
X *     and documentation, including copyright notices.
X *   - duplicate copies or distributions outside a single site are
X *     original distributions without modifications.  (this is to keep
X *     bastardized versions from showing up all over thie place.)
X *
X * this program source may be modified provided the following
X * conditions are met:
X *   - modified source is not distributed to other sites.
X *   - modifications (including, but not limited to, bug fixes) are
X *     sent to the author if the modifications are to be distributed.
X *     no modified source is to be distributed unless done so by the
X *     author.
X *
X * no warranty, either express or implied, is given for this program.
X * the author makes no guarantees of fitness for any use of this
X * program.  the author is not responsible for damages resulting from
X * the use of this program for any purpose.
X *
X * 'site' refers to one or more computers under a single management.
X * 'author' refers to the copyright holder, jim frost.
X * 'source' refers to all files related to this program.
X * 'documentation' refers to non-compilable files in the distribution.
X *
X * basically this notice is to keep me out of trouble should anything
X * go wrong (i really *do* test these things though) and to make sure
X * that the distribution of code is centralized.  makes bug fixes and
X * enhancements much easier.
X *
X * thank you for your attention to this copyright notice.  if everyone
X * follows this, you may find this a useful tool that is pretty well
X * supported.
X *
X * author information:
X *   jim frost                    permanent usnail address:
X *   madd at bucsb.bu.edu            75 washington street
X *   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
X */
X/* token.c:
X *
X * this file contains token creation, insertion, print, and value funcs.
X */
X
X#include "bool.h"
X
Xextern TOKEN_LIST *t_list;
X
X/*
X * these functions return a boolean value dependent on whether or
X * not a char is a legal char inside a token.
X */
X
Xint begtok(c)
Xchar c;
X{
X  return(((c >='@') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) ||
X         (c == '_'));
X}
X
Xint intok(c)
Xchar c;
X{
X  return(begtok(c) || ((c >='0') && (c <='9')));
X}
X
X/*
X * this looks through the token list and returns token values.  if no
X * token exists, it is added.
X */
X
Xint get_token(s)
Xchar *s;
X{ TOKEN_LIST *t, *u;
X
X  if (!t_list)
X    return((t_list= new_token(s))->number); /* null list so make one */
X
X/*
X * try to find token in list
X */
X
X  t= t_list;
X  for (;;) {                 /* we should always return() out of this */
X    if (!strcmp(t->token,s)) /* found it so return its number */
X      return(t->number);
X    else if (t->next)        /* if not end of list, keep looking */
X      t= t->next;
X    else {                   /* end of list so make new token */
X      if (strcmp(s,t_list->token) < 0) {
X        t= new_token(s);
X        t->next= t_list;
X        t_list= t;
X        return(t_list->number);
X      }
X      else {
X        for (t= t_list; (t->next) && (strcmp(s,t->next->token) > 0); t= t->next);
X        u= t->next;
X        t->next= new_token(s);
X        t->next->next= u;
X        return(t->next->number);
X      }
X    }
X  }
X}
X
Xvoid print_token(tok)
Xint tok;
X{ TOKEN_LIST *t;
X
X  t= t_list;
X  while (t) {
X    if (t->number == tok) {
X      printf("%s",t->token);
X      return;
X    }
X    t= t->next;
X  }
X
X/*
X * if we get down this far, it's screwed.
X */
X
X  panic("print_token");
X}
X
Xint token_val(tok)
Xint tok;
X{ TOKEN_LIST *t;
X
X  t= t_list;
X  while (t) {
X    if (t->number == tok)
X      return(t->value);
X    t= t->next;
X  }
X  panic("token_val");
X}
END_OF_token.c
if test 3916 -ne `wc -c <token.c`; then
    echo shar: \"token.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
For comp.sources.unix stuff, mail to sources at uunet.uu.net.



More information about the Comp.sources.unix mailing list