Bs (programming language)


bs is a programming language and a compiler/interpreter for modest-sized programs on UNIX systems. The bs command can be invoked either for interactive programming or with a file containing a program, optionally taking arguments, via a Unix shell, e.g., using a Shebang #!/usr/bin/bs.
An early man page states, " is a remote descendant of Basic and SNOBOL4, with a little C thrown in."

History

The bs command appears in UNIX System III Release 3.0, first released outside of Bell Labs in 1982. It was written by Dick Haight circa 1978, who recounts it as follows:
The Release 3.0 manual mentions bs prominently on page 9 :
While not released outside prior to System III, the bs command was present internally in UNIX/TS 1.0, PWB/UNIX 2.0, and CB UNIX editions 2.1 and 2.3.
The bs command does not appear in some earlier internal releases, e.g., the UNIX Support Group’s March 1977 release, nor the PWB/UNIX manual dated May, 1977, suggesting its creation circa 1978. It does not appear in any version of Research Unix nor the Berkeley Software Distribution.
Subsequently and into the 1990s, bs was included in a variety of System III-derived or System V-derived commercial operating systems including, but not limited to: PC/IX; UNIX System V Releases 2 & 3: SVR2, SVR3, SVR3.2 ; HP-UX; AIX; and A/UX.
Occasionally, bs was touted as one of the primary programming languages for development under UNIX. However, bs is not included in the POSIX.1 commands and utilities nor in the Single UNIX Specification and is not provided with most contemporary operating systems. For example in Linux, similar syntax and functionality is provided by bc, Perl, and POSIX shell.
In the 21st century, bs is present in, at least, HP-UX Release 11i, as well as AIX versions 6.1 and 7.2, likely due to their UNIX System V heritage.

Design and features

The bs man page, ostensibly the programming language's only specification, characterizes it as follows:
A bs program is compiled and executed differently from programs written in the other principal Unix programming languages of the time: C, FORTRAN, and assembly language, whose respective commands compile program source code to executable assembler output. Instead, a bs program is, first, converted by the bs command to an internal reverse Polish intermediate representation and then executed by the command's internal virtual stack machine. The bs language, thus, is a hybrid interpreter and compiler and a divergence in Unix programming from Ancient Unix.
The bs language shares some features and syntax with BASIC, SNOBOL, and C, the two former presumably inspiring its name. Like BASIC, it can be used interactively, either executing statements immediately or collecting them into a program to be executed subsequently. Like in SNOBOL4, the assignment operator is used for I/O and bs can execute code in strings, using its eval function. It also includes SNOBOL's interrogation operator used to test whether an expression evaluation succeeds or not. The built-in format function, limited to one argument, supports a subset of C's printf format conversion specifiers, e.g., "%f".
The language has some conspicuous elements. For instance, its program functions are defined using the fun ... nuf syntax and its functions can have local variables. Also, bs can operate in two modes, either interpreting statements and programs or compiling them, and switching between the two using compile and stop. Otherwise, its functionality is unique only collectively, since individual features are redundant with those of coexisting tools, such as the Unix Shell, e.g., file I/O and loops, and AWK, e.g., associative arrays and Regular expression matching.
The bs language was meant for convenient development and debugging of small, modular programs. It has a collection of syntax and features from prior, popular languages but it is internally compiled, unlike a Shell script. As such, in purpose, design, and function, bs is a largely unknown, modest predecessor of hybrid interpreted/compiled languages such as Perl and Python.

Syntax Examples

The following examples are derived from an A/UX bs man page.
This example uses bs as a calculator:
This example is the outline of a typical bs program:
This example demonstrates I/O:

Sample Program

The following is a sample bs program that emits the words to the song 99 Bottles of Beer using /usr/bin/bs.