BASIC1

I’ve recently been looking at BASIC for Windows. What I wanted was something that captured the simplicity of CP/M or early MSDOS days, was small in size and had a reasonably useful set of functionality. TinyBASIC was a fairly good compromise but it lacked a few things …

My main regret with TinyBASIC was the lack of LOAD and SAVE commands. Without those, you’re not far from a programmable calculator with volatile memory. You have to type your program in every time.

Another sore point was needing to use Ctrl-C to get out of the program. It’s not a big issue; but it’s not a great look either.

A little more functionality and a little more of the language would be nice. I think I did see a comment at some point that some implementations of TinyBASIC did include LOAD / SAVE so others must have thought the same.

BASIC to Assembler and Binary

The idea of functionality brought up the question of, “what is the standard for BASIC?” i.e, “what functionality should be in it?” Fortunately, I came across a compiler by John Gatewood Ham on sourceforge.net and he’d spent some time researching the language and then implementing it. It is a very good page for both the language and for the trials that arise when implementing one. One of the jewels was the story of ECMA-55 which is the only publicly available standard for the language of the late 1970s. He has links to the document of his site.

ECMA-55 is an interesting standard. It explains a lot of what we saw that was common across the different dialects of BASIC. If you were using BASIC in those days, you’ll no doubt remember that every version of BASIC was different and you had to choose which flavour of BASIC to write for each time. Whenever a new BASIC compiler or interpreter was released, it would differ in some way from all of its predecessors. The positive to that was “bigger and better”. The negative was, your old programs wouldn’t run. ECMA-55 was the missing link (for me at the time) that explained what the essence of BASIC actually was.

It wasn’t closely followed as many had slight variations to core functionality and many added things to the core; but it does show what they were all hovering around. It is a good read and is fairly short.

A Standards Compliant BASIC Interpreter

John mentions on the sourceforge page that there is a recent implementation of the as-defined language in bas55. That one is neat, compact and comprehensive. The executable is only 75 KB which is very good.

If you look through the source code for bas55, you’ll see that it used Bison or a later derivative to translate the BASIC grammar into a series of tables that the program then uses. It is a good approach and tools like that result in significant savings in development time and also produce fast compilers / interpreters. For John’s purposes, he wanted to avoid teaching additional tools and allow his students to focus on how simple compilers work. Both approaches have their merits.

Basic1

I wanted something that came close to the standard; but would be fairly easily extended.

I wanted both the simplicity and development speed of a tool generated grammar recogniser; but also the simplicity of “pure code” so I could see what was being done, instead of just staring dumbly at a page of state / transition numbers.

After about two weeks of pretty busy evenings and weekends, I am pleased to provide another (mostly) ECMA-55 compliant BASIC interpreter. My grammar code is less efficient that Jorge’s bas55 so my executable is 120 KB. It’s probably also slower but it should serve as a good starting point for adding features. It’s not perfect but I think you’ll like it. It does have some additions already; such as: TRON / TROFF and a simple immediate mode (? expr) so you can try things out whilst thinking through the next line of code. I also like how smoothly the HELP system turned out.

You can download a copy of basic1. It is free to use and doesn’t have any time limits on it. Whilst my executable is 120 KB, the download includes the help file too and so, as a single ZIP file, the download is only 40 KB in total!

It is version 0.00 for now. You should see the version number go up over the next few weeks as I add things. It does already have the ability to load and run a BASIC program directly from the OS prompt (see HELP STARTUP).

*** Update 10 Jun 2018 ***
Basic1 version 0.02 has been done. This corrects a few more things and adds most of the functions that were prevalent in the late 1970s and early 1980s. It now successfully runs a number of programs from that era with minimal tweaks. See HELP CHANGES for more info.

*** Update 03 Jun 2018 ***
Basic1 version 0.01 has been done. This makes variable names case-insensitive and corrects the grammar to make subtraction left-to-right associative (10-2-1 now =7, like it should). There are a number of other additions, see HELP CHANGES for more info.

This is part of the CP/M topic.
See the Basic1 page for the latest and other versions.

It's only fair to share...Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUponDigg thisPin on PinterestEmail this to someone

One thought on “BASIC1”

  1. A couple of “gotchas” with version 0.00 :

    1. Variables are case sensitive, so don’t expect the following to exit

    20 if R>5 then 60
     ...
    40 r=r+1,
    50 goto 20
    

    2. Arithmetic is right associative (it should be left to right)
    10-2-1 should be 7; but is
    10-(2-1) = 9

    You can work around the variables by using the same case (upper OR lower). You can work around the second one by using brackets – but you shouldn’t have to.

    Clearly these are a couple of priorities for Ver 0.01, and here’s proof you can’t do something this big in a couple of weeks part time without missing something. Sorry.

Leave a Reply

Your email address will not be published. Required fields are marked *