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
View all comments
Show parent comment
1
u/Commercial-Drawer881 Jul 11 '26
Thank you very much for you insightful feedback!
You referenced ANTLR v3 inline tree manipulation
I found this example from my research:
I think the point you make is good, however, I argue that this approach "crowds" the syntax for parsing. I think the approach I present, while more verbose, is more effective because you read what is being parse more easier likewise you can more easier read how the AST is being generated.
My current suggestion for my language syntax will look like this:
Regarding your point Most grammars for popular languages require some semantics for making the right choices in parsing! I have never thought of this before. My thought process was that the user would parse a generic AST and then in their project code, when interpreting the AST, they would manually add more context where it is missing. In hindsight, I found this to be tedious and made interpreting parser results painful! Having the parser itself add the context while parsing may be a more effective approach. I think this approach has a shortfall, however, where the context must be provided before the case being parsed (like declarations in C) but this could be a unique case that my parser generator solves! I will look into this in more details.
From my research of ANTLR v4 I found this example:
I agree with you, my language need Semantic Predicates!