26

Does anyone know where I could get a good B compiler? I have searched for a B compiler for some time now, but have been having some difficulty finding anything complete for a Windows or Linux system.

Here is an example of B:

main( ) {
auto a, b, c, sum;
a = 1; b = 2; c = 3;
sum = a+b+c;
putnumb(sum);
}
Triang3l
  • 1,230
  • 9
  • 29
Anthony
  • 261
  • 3
  • 3
  • 11
    Sort of like stack overflow could be cloned in a July 4th weekend? ;) – Oorang Nov 16 '09 at 20:02
  • https://github.com/sergev/b has some B related stuff, especially some PDFs. –  Jan 08 '16 at 02:13
  • 1
    My apologies to Anthony, and anyone who might have been discouraged by my earlier comment. It was disrespectful, inappropriate, and didn't actually provide any useful information. – Pavel Minaev Mar 24 '16 at 07:14
  • ... maybe move this question to https://retrocomputing.stackexchange.com ... ??? –  Aug 02 '17 at 17:54
  • —▶ https://github.com/davidgiven/ack –  Dec 08 '17 at 10:52

2 Answers2

19

Prompted by this question, there is now a B compiler available from here: https://github.com/Leushenko/ybc

Runs on Windows, Linux, and OSX (binaries provided; in the spirit of the question it is written in an obscure language), where it produces very poor quality x86-32 assembly. Should be GCC-compatible. It is reconstructed out of the available reference material on B, and almost certainly does not reflect the language as it really was in the 1960s. Notably, in the absence of type information (B is untyped), the &a[b] == &*(a + b) rule can not hold on x86, meaning that this task is effectively impossible (without resorting to an interpreter).

Apart from that, Pavel Minaev's comment is right: the language as described is extremely small, far smaller than C, and an experienced/competent compiler programmer could likely write one for you in an afternoon.

Unfortunately this is only a partial answer, as I couldn't tell you where to find a good B compiler.

Alex Celeste
  • 12,824
  • 10
  • 46
  • 89
  • 3
    Cool! With `.` being a valid identifier in B, perhaps we can at last confuse some of the BrainF*ck types over on code golf :) – 500 - Internal Server Error Oct 08 '14 at 01:08
  • 1
    This is excellent. I was able to implement a fizzbuzz in B. Thanks! https://github.com/jurgemaister/fizzbuzz/blob/master/fizzbuzz.b – Jørgen R Apr 16 '15 at 09:46
  • 1
    @500-InternalServerError: How is `.` a valid identifier in B? According to [the B manual](http://cm.bell-labs.com/cm/cs/who/dmr/kbman.pdf), an identifier is an *alpha* followed by 0 to 7 *alphas* or *digits*. "The syntactic variable 'alpha' is not defined. It represents the characters A to Z, a to z, _ and backspace." (I have no clue why backspace is included.) – Keith Thompson Aug 29 '15 at 21:10
  • 2
    @KeithThompson `.` is listed among the alphabetic characters in "User's reference to B on MH-TSS", which describes a very slightly different version of the language from Thompson's manual (B wasn't standardized; I assume the designers added features as-and-when). – Alex Celeste Aug 30 '15 at 17:51
  • 3
    Re `&a[b] == &*(a + b) ` not being true on x86: that's actually easy to fix. Remember that B is *word* addressed, not *byte* addressed. Adding one to a pointer doesn't increment it to the next byte, it increments it to the next word --- on non-word-addressed platforms like the x86, you need to multiply by the pointer by the word size whenever you dereference it. (B can't address bytes at all.) – David Given Nov 26 '16 at 18:08
  • @DavidGiven interesting idea. Does presumably mean that you can't actually store or pass pointers by (true) value anywhere though? Which would make interop with the rest of the system difficult. – Alex Celeste Nov 27 '16 at 03:50
  • 1
    Unfortunately, that's true. It also means that you need to make sure that all variables in memory that contain addresses contain the shifted form of the address, and most linkers can't do that, which means complex startup sequences. The language itself is beautifully simple, but this bit isn't. – David Given Nov 27 '16 at 20:19
12

Do you have a Honeywell 6050 running GCOS to run it on? Or maybe an emulator? I know that IBM's 360 and 370 have been emulated but I haven't yet heard of a Honeywell 6000 emulator.

At the University of Waterloo in 1974-76 timeframe I remember writing CS assignments in B rather than Algol-60 which most people in the class were using. I went on to write an emulator for an HP 2100A minicomputer, but that code is long since lost.

As far as I know, B was only implemented on the Honeywell with its 36-bit word length, 9-bit ASCII, etc. And since it's successor C, was hitting the universities at the same time, it didn't last long.

If I remember correctly, Trevor Thompson, one of the founders of MKS, wrote a standard I/O library for B and also wrote a 3D chess game in it. If you can manage to track him down, he is someone who, at one time, had his hands on a B compiler. I just had a look at LinkedIn and I found him. He is one of the owners of Satori Solutions.

If you have a machine running GCOS, or a Honeywell series 60 emulator running GCOS, then you could use the B compiler included in the UW Tools Package from Thinkage. It supports both batch and TSS programs.

Michael Dillon
  • 31,973
  • 6
  • 70
  • 106