From: Philip A. Nelson <phil@cs.wwu.edu>
Subject:  v01i041:  GNU_bc - numeric processing language, Part00/07
Newsgroups: comp.sources.reviewed
Approved: csr@calvin.dgbt.doc.ca

Submitted-by: Philip A. Nelson <phil@cs.wwu.edu>
Posting-number: Volume 1, Issue 41
Archive-name: GNU_bc/part00

Environment: UNIX (BSD, System V, MINIX, POSIX)

Tested Environments:
	DECstation 3100, Ultrix 4.2
	DECstation 3000 (p/max), Ultrix 4.2
	sun4, SunOS 4.1.1
	sun3, SunOS 4.1.1
	Sequent/Symmetry, Dynix/ptx 1.2.4.
	80386, ESIX System 5.3.2 Rev D

Dates:
	Submission Received: Oct 29 1991
	Reviews Returned: Nov 21 1991
	Revised Version Received: Nov 26 1991
	Accepted: Dec 16 1991

	
Author's Summary:
-----------------

Program:  GNU bc
Author:   Philip A. Nelson
E-mail:   phil@cs.wwu.edu
OS:       UNIX (BSD, System V, MINIX, POSIX)
Copying:  GNU GPL version 2
Copyright holder: Free Software Foundation, Inc.
Version:  bc version 1.01
Required: vsprintf and vfprintf routines.
Machines: It has been compiled and run on the following environments:
	BSD4.3 (VAX 11)
	MINIX 1.5 (IBM PC, both K&R and ANSI compilers)
	MINIX 1.5 (pc532)
	SUN-OS 4.1 (SUN 3 and SUN 4)
	SVR3V5 (Motorola 68K)
	SVR3.2 (3B2)
	SVR4.0.2 (a 386 box)
	ULTRIX 4.1 (DEC 5000)
	UTS (Amdahl)

bc is an arbitrary precision numeric processing language.  Syntax is
similar to C, but differs in many substantial areas.  It supports
interactive execution of statements.  bc is a utility included in the
POSIX P1003.2/D11 draft standard.  

This version was written to be a POSIX compliant bc processor with
several extensions to the draft standard.  Option flags are available
to cause warning or rejection of the extensions to the POSIX standard.
For those who want only POSIX bc with no extensions, a grammar is
provided for exactly the language described in the POSIX document.
The grammar (sbc.y) comes from the POSIX document.  The Makefile
contains rules to make sbc.  (for Standard BC)

Since the POSIX document does not specify how bc must be implemented,
this version does not use the historical method of having bc be a
compiler for the dc calculator.  This version has a single executable
that both compiles the language and runs the a resulting "byte code".
The "byte code" is NOT the dc language.

Also, included in the initial distribution is the library file
vfprintf.c for MINIX systems.  My minix 1.5 did not have this file.
Also, you should verify that vsprintf.c works correctly on your
system.

The extensions add some features I think are missing.  The major
changes and additions for bc are (a) names are allowed to be full
identifiers ([a-z][a-z0-9_]*), (b) addition of the &&, ||, and !
operators, (c) allowing comparison and boolean operations in any
expression, (d) addition of an else clause to the if statement, (e)
addition of a new standard function "read()" that reads a number from
the standard input under program control, (f) passing of arrays as
parameters by variable, (g) addition of the "halt" statement that is
an executable statement unlike the quit (i.e.  "if (1 == 0) quit" will
halt bc but "if (1 == 0) halt" will not halt bc.), and (h) the
addition of the special variable "last" that is assigned the value of
each print as the number is printed.


Reviewers' Comments:
--------------------

This version of `bc' does essentially the same thing as the plain unix
`bc', but better and faster.  The program is an interpreter for a
programming language that resembles C, though most people will simply
use it as a desk (window) calculator.  It provides trig functions,
variables (the names can be longer than one character!) for storing
results, recursion, and limited input/output of numbers.  Though the
enclosed 'configure' script does much of the work of adapting the
program to your system, some manual modifications of the Makefile may be
required.

------------------------------------------------------------------------------

The bc package is easy to compile and install.  It is in most respects
faster than the regular bc/dc.  For those people that care about speed
or the POSIX compliance, this is the package to use.

------------------------------------------------------------------------------

This implementation of the indefinite-precision calculator utility `bc`
bases itself on the POSIX draft standard.  I encountered no problems
while building this in the default SunOS 4.1.1 environments; all the
functionality seems to be there.  Extensions, such as variable names
with more than one letter and boolean operators, make this
implementation more useful as a basic tool than a straight POSIX
implementation.  It compares favorably (in terms of time and space) to
the vendor implementations of bc(1) that I tested against, which compile
bc scripts down to dc(1) commands.

I did encounter one problem with interrupts during calculations.  This
seems to be more of an annoyance than anything else.

------------------------------------------------------------------------------

bc is a text oriented interactive calculator.  It can compute with
arbitrary precision, and includes common mathematical operations.  It
is compatible with the "bc" program that has been included with UNIX
for years.  This version is considerably faster than the traditional
implementations, and includes some nice extensions.





exit 0 # Just in case...
