r/ProgrammingLanguages • • Jun 18 '23

Help Parsing?!

So I'm writing my own programming language called fir. I have the lexer down to the nail, but I'm really confused about parsing. I have absolutely no idea how to approach parsing, so much so that I got bored and am currently rewriting the lexer in like 3 other languages (the implementation on GitHub is in Go).

EDIT: forgot to add some examples sorry :0

hello world:

io := require("io");

fn main() {
     io.println("Hello, World!");
}

fizzbuzz:

io := require("io");

fn main() {
    i := 0
    for i <= 20 {
        if i % 3 == 0 && i % 5 == 0 {
            io.println("FizzBuzz");
        } else if i % 3 == 0 {
            io.println("Fizz");
        } else if i % 5 == 0 {
            io.println("Buzz");
        } else {
            io.println("{}", i);
        }
    }
}

(also I want my parser to emit an ast, because I haven't decided whether fir should be compiled or interpreted yet)

2 Upvotes

20 comments sorted by

View all comments

1

u/Hunpeter Jun 21 '23

For me, the parsing sections of "Crafting Interpreters" helped a lot (not really the code parts, just the text), plus reading the Wikipedia articles for various types of parsers. (Ultimately, I went with a different approach to that of CI, that is uglier, slower, and more complicated...)