Sub_pl: My first functionnal programming language using zig

[sub_pl]: Writing my first programming language


I’m learning about compilers and interpreters, so i decided to create my own programming language from scratch, that means no llvm (or other backends), no lexing or parsing librairies.

This is the list of things i learn (and/or did) until now with this project:

  • I implemented the lexer part of the language without allocating memory,
  • Memory management is hard, so i used an arena allocator for my ast
  • Designing my language seems as hard as implementing it
  • There is no priority of operations, expressions are group left associatives except when explicitly set with parentheses. that means p.x + 1 * 2 is parsed as (((p.x) + 1) * 2), 1 + p.x * 2 is parsed as (((1 + p).x) * 2),
  • I print human readable errors when parsing failed instead of just doing asserts and print stack trace.

I’m really new to compilers/interpreters, so any suggestion is good.

This is my first post in community server, so my style of writing can be a little bit clunky.

Also one of my next projects is going to be create a programming language using this language (sub_pl) to generate qbe ir.

Supported Zig versions

  • zig-0-15 (migrating soon to 16)

AI / LLM usage disclosure

I did not use AI to write the code or readme. I’m just an humble neovim user :slight_smile:

5 Likes

Congrats. If you haven’t read it yet I highly recommend the book Crafting Interpreters https://craftinginterpreters.com/

2 Likes

+1 for Crafting Interpreters, I’m going through that book now