HACKER Q&A
📣 kstenerud

Please help me by reviewing KBNF


Hi everyone! Merry Christmas and happy new year!

I'm making a modernized BNF-style metalanguage that supports grammars for text and binary formats, but unless there's some kind of outside review, I won't find any blind spots I have until long after release.

If you have experience in grammars or protocols (text or binary), could you take a quick look?

Note: I'm not aiming for perfect expressivity; just 80-90% of use cases without making things overcomplicated so that it can be used descriptively in documentation.

https://github.com/kstenerud/kbnf/blob/master/kbnf.md

Some examples of it in use:

* Internet Prodocol, version 4: https://github.com/kstenerud/kbnf/blob/master/ipv4.kbnf

* Concise Text Encoding: https://github.com/kstenerud/concise-encoding/blob/master/cte.kbnf

* Concise Binary Encoding: https://github.com/kstenerud/concise-encoding/blob/master/cbe.kbnf

* The KBNF grammar itself: https://github.com/kstenerud/kbnf/blob/master/kbnf.md#the-kbnf-grammar-in-kbnf


  👤 richardjam73 Accepted Answer ✓
It looks ok but I think you would need to try and implement something in it to see if there are any problems. I was a bit wary of the programmatic parts at first but I see where they can be used to cut down on repitition in the grammar. I thought that the functions should be more different than the rules/identifiers for instance.

part = @bind(number, @uint(8,~)) & @uint(16,~) & number

Because if you are writing the grammar for a language you may have similar constructs.