r/Compilers • • 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

8 Upvotes

21 comments sorted by

View all comments

Show parent comment

1

u/kendomino Jul 12 '26 edited Jul 12 '26

I argue that this approach "crowds" the syntax for parsing. This is also probably why Parr abandoned the tree rewrite syntax. You don't need to integrate the tree-rewrite syntax in the EBNF. But, what I am suggesting is that you use a standardized notation for expressing the tree: (1) using parenthesized expressions, or (2) an indented node representation (one per line), or (3) etc.

So instead of:

abstract_syntax_tree {  
    variable_declaration {TYPE, ID, expression} -> DECL  
}

which is hard to read, you specify the tree rewrite more directly:

abstract_syntax_tree {  
    variable_declaration -> (DECL TYPE ID expression)  
}

(parenthesized expression)

Or

abstract_syntax_tree {  
    variable_declaration ->  
        DECL
            TYPE  
            ID  
            expression  
}

(indented node list)

The meaning would be: "For a variable_declaration, in its place, create a DECL node with TYPE, ID, expression as children."

With this syntax, the specification of the tree rewrite can follow the EBNF rules, as with your example, or be separated into another file.

"Actions" and "predicates" for semantics can be similarly structured, i.e., remove explicit language syntax from the EBNF.

1

u/Commercial-Drawer881 Jul 12 '26

Thanks for explaining. I will give what have shared some more thought.