K2yfi

joined 1 year ago
[โ€“] K2yfi@programming.dev 6 points 1 year ago* (last edited 1 year ago)

https://www.hedycode.com/ might be exactly what you are looking for. It's designed to teach python to children by starting with a super simplified version of the language, and then gradually adding in syntax and features until it's full python. Here's a great talk by its creator: https://youtu.be/fmF7HpU_-9k?si=pa7jkOELQ5X7xeuu

[โ€“] K2yfi@programming.dev 8 points 1 year ago (3 children)

As someone who's spent way too much time languishing over picking the perfect parsing technique for my own language, I'm actually gonna go against the norm and recommend figuring out the parser later. Instead you should start with building your language's ASTs directly in memory and then from there, either build a backend for converting ASTs to LLVM IR, or what I'd actually do first is just start with an interpreter executing directly on the ASTs. This way you figure out the mechanics of your language, and then when they're well established, you can worry about your syntax, and how to parse it into ASTs. There's a lot you learn about your language by doing it this way that you don't necessarily think about if you just start from the parser. It also let's you see real progress/output sooner which I think is key for staying motivated on these kinds of projects.

When it comes time to actually write the parser, I recommend either just hand crafting a parser directly, or using an existing parser generator tool like gnu bison, etc. I do not recommend trying to write your own parser generator (e.g. LR(k), LALR, LL(k), etc.) unless your language's syntax is particularly simple. Speaking from experience, real languages have many common syntax features we take for granted that are hard to deal with in parser generators. In my case, I spent years bogged down exploring/implementing several state of the art parser algorithms (I'm a fan of generalized parsing, so Earley, GLR, SRNGLR, GLL, etc), and really only recently made any decent progress when I decided to trash them and just hand write a dumb recursive-descent-esque parser. Once things are working, it's pretty easy to go back and swap out the parser if you want something more fancy.