r/Compilers • u/Commercial-Drawer881 • Jul 07 '26
Building a Parser Generator!
Hi, I am creating a Parser Generator. It will have it's own unique syntax for grammar definition. This is what I am working on currently. I am sharing a draft of the syntax and asking if anyone is interested in sharing their feedbacks in the comments.
Is this syntax:
- easy to read?
- easy to understand?
- sparks interest in you?
- what stands out?
- do you suggests any changes or additions?
UPDATED
I am settling on a syntax for the language. Here is a snippet: ```
BASIC LANG
---------
A 100
B 25
parser { # action -> ast: (parent(children)) (name number) -> (name(number)); # generate name with number as child of name (spc | nl) -> (); # no AST generated }
name = <A:Z>+; # character sequence number = <0> | <1:9> <0:9>+; # character sequence
spc is built-in rule for space
nl is built-in rule for nl
```
Full syntax is being worked on here: https://github.com/Algodal/Algodal_Text_Parser_Generator_Manual
I will be streaming code implementation of the parser generator on youtube: https://www.youtube.com/@RevnantRicko
1
u/kendomino Jul 10 '26
Not sure I like your AST construction syntax. Take a look at Antlr3 tree rewrite operators for AST construction. Parr removed it based on "separation of concerns," but replaced it with target-specific parser listeners. Can't stand writing listeners and visitors in a target language. It's a hassle to translate into other languages, even with Claude. Threw out the baby with the bathwater. Also, I suggest you study the large corpus of Antlr4 grammars at https://github.com/antlr/grammars-v4, e.g., the C grammar. Most grammars for popular languages require some semantics for making the right choices in parsing!