Retro is a concatenative, stack based language with roots in Forth.

It is designed to be small, easily learned, and easily modified to meet specific needs, it has been developed and refined through continual use by a small community over the last decade.


This blog is written in Retro and has served as my primary means of posting things concerning Retro since 2010. The core code for Corpse is included in the Retro releases and can be freely studied and deployed.

The most recent posts are shown below. You can also view a list of all posts.

Post 98 of 215

2011-06-02

A BASIC Compiler

With the successful completion of a BrainF*** compiler, I'm moving on to a more difficult target: BASIC. For this, I have to deal with some actual syntax, keywords, and such.

I've chosen to model this after some of the really old BASIC systems I used many years ago. Certainly not the most flexible approach, but it makes the actual implementation much easier. The basic concepts:

  • Line numbers
  • Simple syntax forms
  • Small set of keywords: CLS, PRINT, INPUT, LET, IF, GOTO, END, and RUN
  • Simple variable names: strings are a$ to z$, numbers are a# to z#

Given these constraints, an initial implementation has taken about an hour to write and test. It'll appear in the playground fossil in a day or two as lang/basic.rx, but for now I'm still working on handling expressions in LET. Apart from that, things seem to work ok though.

In use, this looks like:

0001 CLS
0002 PRINT "HELLO, WORLD\\n"
0003 LET a# = 101
0004 LET b# = 101
0005 IF a# = b# THEN PRINT "match\\n"
0006 IF a# <> b# THEN PRINT "no_match\\n"
0007 END
4000 RUN

Is this useful? Not really. But experimentation does serve to provide more material that may be helpful in implementing actual applications, and this could certainly be expanded into a usable BASIC dialect with a moderate amount of effort.


View comments for this article