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
2
u/Commercial-Drawer881 Jul 09 '26
Thank you for your thorough feedback! I will answer your questions:
Why building a parser generator?
Because
I want to create a parser generator that is
How will achieve this?
Cleaner Syntax ?
Yes I have refined the syntax a bit so far and made it more EBNF like.
I see you suggest more regrex features in your example - I will consider this.
Regarding languages like Python, I think processing the token before passing them along to analyzed is the best approach. I also don't want the parser generator to force the user to write external code, though I may consider allowing the user to write their own external processors or even their own external lexer.
Sample of python approach:
An a suggested approach for users writing their own lexers and the parser generator handles abstract syntax tree generation for them
To answer the question about
one/two pass:The reason I am going with LR instead of LL is to allow for the syntactical analysis and the tokenization to occur at the same time. For example, 1 token spits out, an AST starts building with that token. Then the next token, that is added to the AST. The idea this would make the parser go as fast as possible. This is what would be one pass. Then two pass would be all the tokens generated up front (the most common way) and then the AST is built.
Regarding to your
Listeneridea. Once the parser is generated and then that parser runs on your text and generates your AST. You will have API (provided by the parser generator library) to help with easy manipulation of the AST tree. You listener idea is good, I can consider that too.The way my parser generator ecosystem will be structured is that the parser will be a binary of code which will run over a vm. This allows for portability and zero dependence*. So I want the syntax of the parser language to avoid any dependence on external languages.