Hacks, science and curiosities

A ZX Spectrum BASIC Compiler

– 🕓 1 min read

I'm currently programming a ZX Spectrum BASIC cross compiler in my (little) spare time. It's entirely written in python, and almost finished (hope to release V1.0 this month). It's a three stage retargeable compiler. The backend outputs Z80 code, so it should be easily portable to other Z80 micros such as AMSTRAD or MSX. Porting to other architectures, or even to .NET or Java it's also possible by changing the backend module could also be implemented.

Regarding to the language, It's not the ZX Spectrum original BASIC but a dialect very close to that of FreeBasic which allows function definitions and more complex control-flow structures. The URL contains an almost complete specification, although not all of them has been implemented in the ZX for obvious reasons.

Some features:

  • Function definitions with local variable scopes and parameters by reference or value
  • Multidimensional arrays of any data type
  • Strings passed by value or reference
  • Dynamic memory heap
  • Inline ASM code
  • Completely extensible with your own functions

You can download current alpha builds or visit the forum for suggestions, comments, etc.

Update: I've just finished it! Visit the compiler page for more information.