Lily is a programming language that I've been working on by myself for about 5 years now. I'd like to show you what I've done, get feedback, and answer any questions you might have.

If you're looking to make a language, it helps to study other languages for their syntax and their ideas. But that's more if you're trying to be serious about it. If you're trying to develop a language for fun, then I'd suggest checking out either lisp or forth. A lisp can be pretty regular (few special forms), and forth is a nice, easy stack-based language to make.

Actually doing the interpreting comes in a few stages. You'd start off by making a lexer. That'll take a file, and will spit it out as various tokens. This is a word, that's an open parenth, that's a close parenth, etc. The lexer's the hardest part at first because you have to remember what position you're at in the string, and being off can result in the wrong thing coming back. Once you get a feel for it though, it's pretty easy though.

You'll need a parser. That's your brain. It'll take what it gets from the lexer and create variables, classes, and any other stuff you have. You can have a symtab too if you want, to hold that stuff. Symtab, in my own setup, just does registering and finding of the above items. It's not concerned with anything much deeper.

At some point you'll need to run code. That's where you make an ast. I forgot where, but there's plenty of literature about how to make a syntax tree around. I literally started off by searching things like "how to make an ast in C", started with something I found on a .edu site, and then carried on from there. It's most likely going to be that each tree can have a parent, a left, a right, and a next child. You can use either left/right as the first part of a call. It doesn't matter, so much as it's a good idea to make an ast because it helps make sure you have a regular grammar.

From there, you can make an emitter. The bytecode can be whatever you want it to be. A simple start would be 5, 0, 1, 2. You can define 5 as add, and the other values as specific registers. Or maybe you want to make a stack-based vm. That's not something I'm as familiar with.

So then you get to the vm. Your vm can work by just having an array of values, with the bytecode specifying spots in the array. The vm knows how many instructions wide that an op is, and can use that to move to the next instruction. That's roughly how it goes, from start to finish.

/r/programming Thread Parent Link - jesserayadkins.github.io