Writing a BBC BASIC compiler for the CLR
Of late, I’ve picked up an interest in the CLR through learning C#. After being impressed by the performance of the .NET runtime (less so for Mono, although that’s another story) I decided that an effective way to really get to grips with the system would be to write a compiler which targets the CLR.
During a nostalgic poke around the web relating to Acorn hardware, over 12 years since my last contact with BBC BASIC, I stumbled across Richard Russell’s BBC BASIC for Windows (BB4W) which reminded me of my formative years learning to code on the BBC Model B and later various Acorn Archimedes computers under RISC OS. This led me to start down the road of implementing a BBC BASIC compiler for the CLR, although the original BBC BASIC, and BB4W are interpreted. The original BBC BASIC II resided in only 16 kB of ROM, so it can’t be that much work. Can it?
The BBC Basic for Windows implementation, from Russell actually goes to long lengths to provide good backwards compatibility with software originally developed for the Beeb or RISC OS, such as providing a Teletext MODE 7 equivalent, and ‘emulated’ sound and graphics support.
I will be taking a different tack with this project. Rather than focus on getting old code reliant on obsolete hardware features to run, I will focus on making a viable BBC BASIC compiler for the CLR, which could be used to port existing programs to .NET/Mono. It is likely that OS or machine specific functionality such as sound and graphics will be implemented in significiantly different ways compared to the originals, for example, by giving good language-level integration with the
System.Console class in .NET, rather than trying to emulate screen modes from Acorn hardware.
The toolset I settled on is as follows:
- IronPython in which to write the compiler
- PLY – the Python Lex/Yacc-a-like
- BeebEm – BBC Micro emulator with BBC BASIC II
- Arculator – Acorn Archimedes emulator with BBC BASIC V
- Documentation in the form of BBC Micro and Archimedes user manuals, and various other information and examples on the web
Mostly its an experiment, and for the fun of writing a compiler. I don’t expect anybody to start creating large software systems in BBC BASIC as a result of my efforts. Far from it; there are much better tools today. However, I must admit to a secret aim of producing the fastest BBC BASIC implementation yet!