Okay, so I want to write my own scripting language.
As daunting as that sounds, I can do this. I have a book I bought many many years ago that talks about all the nitty-gritty about building a language parser and compiler. It's probably a bit old fashioned in some ways, but that suits me right down to the ground. And I have read it, probably not long after I got it. But I do need to read it again. The book is Crafting A Compiler in C. I'm amused to see it's freely available now.
What this is good for is teaching all the way from string scanners, up through lexing (lexical analysis), parsing, and beyond. That's perfect. I don't want further than hoiw to get to the parse tree.
I learnt programming in the early 1980s on popular home computers of the era. Which meant I learnt home computer BASIC. I still remember classes in high school where we were learning how to program on TRS-80 Model I computers. So BASIC has a bit of a fond place in my heart and, to be honest, I miss some of its quirks. I never did own a TRS-80 - they were expensive and in the early 1980s were getting eclipsed by other machines with colour and sound, with cheaper hardware as prices plummeted, and which where generally just faster. This was also the rise of the home computer magazines, with programs for keen people to type in. Magic.
BASIC has a certain simplicity. And even though programming language parsing tools were developed in the 1970s, just as the home computer market began, I have often wondered how many of these parsing algorithms were implemented by these BASICs. Because the vast majority of BASIC interpreters were hand-coded in assembler. This was the only way to get their size down to the limited amount of space most home computers had, for a long time 8K or 16K - that's kilobytes. Even so, it was common and expected for them to have things like proper arithmetic expression parsing with correct handling of mathematical order-of-operations. Impressive.
But I digress. My goal was to figure out how to translate a line of bash-like scripting into something
more BASIC-like. I want to type I = I + 1 instead of i=$(($i + 1)). Or
PRINT CHR$(27) & "[7m" & OUT$ & CHR$(27) & "[0m" instead of echo -ne
"\033[7m${out}\033[0m". Okay, that last one is a bit naff. I have been refining this idea for a while,
after all. What I actually prefer to use for that last example is more like PRINT ^[ "[7m" out$ ^[ "[0m"
Meanwhile, there are a lot of other things that home computer BASICs never fully acquired before most
programmers moved on to other languages and other hardware. Things like proper structured programming -
think WHILE loops and subprograms or procedures - and even new things like proper lists
and hashmaps. Or even objects. More modern BASICs got those, of course, but I have a issues with
how they did them.
So what's next? Well, there were other things to address first.