Completing a new BASIC interpreter in 2025 (strings, math funcs, cassette)

https://news.ycombinator.com/rss Hits: 15
Summary

Completing a BASIC language interpreter in 2025 This is a follow-up to my previous article Developing a BASIC language in 2025, where I describe how I got inspired to start coding a new BASIC interpreter for the 1983 Mattel ECS add-on for Intellivision. Although my interpreter was already pretty fast and with enough statements to build games, I wasn't satisfied because it still missed one thing that the ECS BASIC implements: strings. Only two, A$ and B$, with GET and PUT, for things like getting a name from the keyboard or showing a name. I thought about strings for four days, then I decided to code things like I know what I was doing. I added a string stack pointer bas_strptr where any created string is added. The first thing to implement was an array for the string variables (>A$-Z$) each one pointing to the current string contained (or zero if none). I modified the whole of the expression parser to insert the type in the Carry flag (Clear = it is a number, Set = it is a string), then I made the first string support in the language where it detects if a string name appears (letter plus the $ sign) and reads it and copies it to a new string on the stack, returning this pointer as expression value (and of course the carry flag set) The next step was assigning string variables, it simply took the pointer and stored it into the respective string variable pointer. Of course, I was afraid that I was creating a monster because I wasn't planning for the garbage collector. Then I went full-steam ahead and put support in INPUT, PRINT, and added the concatenation of strings using the plus operator, also the functions ASC, CHR$, LEN, LEFT$, RIGHT$, MID$, INSTR, VAL, and STR$. Now I had string support in my BASIC language for the ECS, but at some point in the execution it would fill up the stack, and crash with an "Out of Memory" error. Garbage collection It was kind of crazy having a BASIC with string support but no garbage collection. I needed a way to copy strings into arra...

First seen: 2025-10-12 20:20

Last seen: 2025-10-13 10:22