BCPL - an even simpler compiler?

Rising to Ed’s challenger over here: B -- A Simple Interpreter Compiler

I thought I’d say something about BCPL …

It’s recorded that BCPL is the fore-runner to C, but the recent B thread seems to suggest that there was an intermediate step; B - probably initially written in BCPL, then in B itself. Whatever - The resurrected B is so close to BCPL as to make little difference, so who knows.

BCPL (Basic combined Programming Language) emerged in Cambridge in the mid 60’s but the first implementation was at MIT by Martin Richards the languages creator. Then (and now), it compiles into an intermediate code which is relatively efficient to interpret on different systems, although in recent years there is another intermediate code it can compile to which is easier to translate to native machine codes.

Think of BCPL as C without types. There is just one type: The Word. You can declare words, or vectors (arrays) of words. and you can word or byte address these vectors. initially a 16-bit system, today it’s a 32 (and 64) bit system, but still more or less compatible with the old 16-bit systems.

My experience is with the BBC Micro in the early 80’s - I wanted something a bit better than Basic (even though BBC Basic is the best old school 8-bit basic there is - I’d been doing a lot of C by then), so BCPL it was. It’s also about 3 times faster than Basic and compiles to a denser code than basic, so the programs could be a little bigger. My project was a flexible manufacturing system with independent/autonomous stations controlled by a BBC Micro using a network (Econet) for communications.

BCPL is still in-use today (a lot of Fords manufacturing systems in Europe is written in it apparently) and Martin Richards got the whole thing running on the Raspberry Pi a few years back in an effort to kindle interest. (I think the Python brigade won that battle though)

The compiler is of-course written in BCPL and takes a second or 3 to compile itself on my desktop i3 Linux system (Yes, really, 2-3 seconds). compare that to gcc, etc. …

Personally I feel it’s an ideal higher level language than Basic for those who want a bit more out of their 8-bit micro - it’s also very capable of being self-hosting. I can compile, edit and debug BCPL programs directly on a BBC Micro, or equivalent.

It was also used as the early OS on the Amiga - in the form of Tripos (Another Cambridge university project) which is a single user, cooperatively multitasking operating system

Current BCPL systems use 32 or 64 bit words - which poses a small problem with floating point… It was never really designed for floating point use - the BBC Micro implementation did come with the “calculations package” which used small vectors of 6 bytes to hold a FP number and library calls to do things like floating point add, multiply and so on, however the current versions do support floating point - but only as big as the underlying word, so if you want double precision, 64-bit numbers, then you need to run your code on a 64-bit (Linux) system…

Ever wonder where the byte and word indirection operators come from in BBC Basic? (rather than peek or poke) Well, that’s the product of the computing science and BCPL taught in Cambridge university as they’re right out of BCPL…

Hello world in BCPL:

get "libhdr"
let start() be
{
  writes ("Hello, world*n")
}

Personally I think BCPL is an ideal language for lesser able systems - retro 8 (and maybe 16) bit computers. The compile can easily be self-hosting on a modest 32KB BBC Micro, the code efficient and compact, but on todays higher speed systems? C…

-Gordon

5 Likes

BCPL was, and still is, mostly unknown in the US. Outside it’s use in Multics it was hardly used. I believe Richards brought it to the Multics project directly, which may explain its use there. Apparently Ken Thompson liked it enough to copy it for B. To paraphrase Dennis Richie, B was BCPL stripped down to bare essentials and filtered through Thompson’s brain.
BCPL became a bit more known and got something of a boost in the US when the Amiga came out. But it quickly faded away again. It’s too bad. BCPL is a rather nice language from what I’ve seen.

1 Like

That is indeed what Ritchie said, but Thompson himself told a different story at VCF East this year, surprising us all. It’s here:

1 Like

Note that though BCPL was ported to Multics and used for some applications at Bell Labs, Multics itself was implemented in PL/1 which was also used for most of its applications.

CPL (known initially officially as “Cambridge Programming Language” and to Christopher Strachey’s students as “Christopher’s Programming Language”, later renamed to “Combined Programming Language” when Manchester joined the project) was a paper design that was never implemented. When one of Christopher’s students implemented a practical subset it was naturally called Basic CPL.

2 Likes

That’s interesting! Thanks for the details.

And here is a bunch of info, including several compilers and compiler kits.
http://www.nordier.com/software/bcpl.html

2 Likes

That’s a good page of links there. I’ve always stuck with the Martin Richards stuff directly off his Cambridge uni pages. I regard that as the canonical sources for my own work.

One thing that is missing though is the sources for the BCPL implementation on the BBC Micro that was produced in the early 80’s. I have spoken to Martin about this, but it appears to all have been lost. I was particularly interested in the assembler to see if I could upgrade it to handle the 65816, but I’ve started to write one from scratch to fill that gap.

-Gordon

2 Likes

Here is a link to Martin Richards’ page:
https://www.cl.cam.ac.uk/~mr10/

1 Like