Building a Compiler - Experimental Error Handling and Cleanup | Live Rust Programming
Vložit
- čas přidán 27. 08. 2024
- In this stream I try to make error reporting better, then realize that it's a big fish to try to catch! I do some great brainstorming but hit a lot of dead ends. I do end up improving my function body parser quite a lot! Then on to a LOT of misc cleanup :D
Stream date: 2024-07-11
Support the stream: ko-fi.com/tomm...
Source: github.com/phy...
Streamed live @ / tommarkstalkscode
Follow me at coding.tommark...
Email: tom@tommarks.xyz
Predictive parsers are very nice to work with. My current parser is entirely predictive, and never backtracks. It has its downsides (for example, I had to change struct-initializer expressions so they wouldn't conflict with the condition of an if expression) but if you can make your grammar predictable, your parser will FLY!
And, yeah, re-synchronizing the parser after an error is difficult. I think, usually, people advance until the next recognizable bit of syntax (the ending brace, bracket, parenthesis, semicolon, any kind of terminator) and skip the errored code.
I have a vague plan for how to incorporate a "continuable" error into my errors, and I probably shouldn't leave that too long because the errors are already so hard to read 😅 I've only parsed lisps/s-expressions before so the complexity here is very new to me
@@TomMarksTalksCodeLIVE I feel you. Conventional algebraic PLs have so much more syntax than a Lisp, and proper error recovery only makes it more difficult. You're doing good work.
Something I like doing is to not return an Error result, but rather always return a valid AST node. This could mean returning an error node. This allows me to parse the entire input and check for any errors further down. If I encounter an error, I use a diagnostic emitter to send the error either to a channel (prefer that) or if you wanna go simple just append it to a list. Works like a charm tbh
My current plan is to have some "continuable" errors return a valid state, so rather than just bubbling up with a `?` I can have some helper that matches on the error and possibly continues. Ultimately I think my state needs to maybe accumulate these errors, plus some other metadata, to make error reporting sensible.
Or well, maybe not an error node but a default node (maybe a default statement or sth) and tag it with some information either on the node directly or in a side table.
Just got a simple program running in a VM im writing in zig. Gotta work on a memory iterator to make program execution smoother. I've decided not to separate registers from general memory, but it's working well so far
I would love to do some Zig streams one day!
It's fun to mess around with, I haven't done anything huge in it yet, but I'm heading that way lol. I love meta programming and have tried a lot of languages and I honestly like zig the best for that