B compiler

B is a programming language which was the original high-level language for Unix. Although B sees very little use today, it was the language which C evolved from; this fact, at least, makes it of historical interest. More information about B can be found starting from the Wikipedia article, http://en.wikipedia.org/wiki/B_(programming_language).

This page is concerned with a compiler I have written for B. It is implemented by compiling to machine code for a fictitious machine (actually a family of machines) which is then run by an instruction set simulator. The reason I mention a family of machines is because although it primarily supports the version of B described by Ken Thompson in his original reference manual for B on the 16-bit PDP-11 minicomputer (which I have followed as rigorously as possible), I also specifically wanted to run the following program by Brian Kernighan, which is the first known "Hello, world" program:

main( ) {
 extrn a, b, c;
 putchar(a); putchar(b); putchar(c); putchar('!*n');

a 'hell';
b 'o, w';
c 'orld';

This program was written for a 36-bit computer and requires at least 4 bytes to the machine word, hence the need for an alternative configuration. To build the utilities following Thompson's reference, the only dependencies are GNU make and a C++ compiler. Building alternative configurations, such as required to run the above program, also requires flex, bison and m4.

Smithers's B utilities v1.1:
Download source (tar.gz)