Self-hosting PL/0 to C compiler to teach basic compiler construction from a practical, hands-on perspective.
> Using the character constants in the code as in expect('+') or whatever is clearer.
That's not how it works, TOK_* represent whole elements, the element may happen to be a single character, but it can be a word. It would be highly confusing to pass single characters to expect() as you wouldn't know at first sight whether it expects a simple character or an element. The TOK_* could as well be assigned a random number as you say in your following sentence. And they were until yesterday :-) I guess it is easier to debug with mnemonic characters.
a custom language construction kit
What few seem to realize is that it's perfectly possible to abstract out some of the work and create an extensible foundation for manual parsers.
Since it's all regular code, you can use the full power of the host language to deal with the problem.
Appwrite - The open-source backend cloud platform. The open-source backend cloud platform for developing Web, Mobile, and Flutter applications. You can set up your backend faster with real-time APIs for authentication, databases, file storage, cloud functions, and much more!
An adaptation of the interpreter from the book 'Crafting Interpreters' by Robert Nystrom written in F# (by BazookaMusic)
The code isn't perfect, it's a learning project and still WIP, but you can check the code for a parser for the LOX language ( c-like) from 'Crafting Interpreters' in this project. 'Ast.fs' and 'Parser.fs' should be enough to get an idea of what it's doing.You can also google the grammar of the language which is quite simple:
The Super Tiny Compiler
3 projects | news.ycombinator.com | 2 Mar 2023
single pass compilers (basic questions)
3 projects | /r/Compilers | 20 Feb 2022
I wrote the least-C C program I could
3 projects | news.ycombinator.com | 20 Feb 2022
List of (open source) C compilers
3 projects | news.ycombinator.com | 11 Apr 2023
What should be included in a history of the Rust language?
5 projects | /r/rust | 1 Dec 2022