Show HN: I improvised my own programming language from scratch
I always wanted to create my own programming language. Sometimes, when I was bored, I would open my computer and start improvising one (in C# on OnlineGDB, because Visual Studio is so heavy and I only open it for serious projects), but I always abandoned it after a few minutes when I realized I didn't even know how to begin. I didn't want to follow a tutorial or anything. I wanted to figure it out myself. I didn't know what a parser was, what a lexer was, what a syntax tree was, or even what an interpreter was. My mindset was basically: "I want to write a program that gets a string containing code and does what it says." But one of those times when I was bored, I tried again, and things just started to click. I'm not sure why it worked this time, but I succeeded in making SOMETHING. I wrote a little program that allowed me to set and print variables, and from then on (it's been a year now), I just kept improving it. At one point, I had previously written some code for coloring C# code (red strings, green comments, purple numbers...), so I just copy-pasted it into my new language project and hop - I had a lexer. Basically, the way it works is that I have `interface IOperation { void Make(); }` and `interface IReadingOperation { IValue Read(); }`, and every statement or expression gets parsed into an instance of one of these interfaces. For example, I have `class VariableDeclarationOperation(Variable v, IValue initVal) : IOperation {...}`, and when the user writes `var a = 0`, it gets parsed into an instance of this `VariableDeclarationOperation` class. Then I just iterate over these instances and execute them. Now it really looks like a real language. I use it as the scripting language for my game engine, and it's actually running simple games! It has functions, classes, attributes... and everything uses my own syntax and all. So yeah, I discover weird bugs all the time, but it works well enough to power some cool arcade games. And I've done A LOT of performance work to get it to this point. Everything is fully open source! Just wanted to share it here :)