3 ms·
I really like the railroad diagram style, it can easily be understood and then converted into code. Thats something BNF and kin just don't let you do.
by mikewarot 3y ago
I really like the railroad diagram style, it can easily be understood and then converted into code. Thats something BNF and kin just don't let you do.
- mrkeen 3y agoIn parsing, BNF lines up almost exactly with its implementation in parser combinators.
- Jtsummers 3y agoAnd not even just parsing as most people interpret it. Most practical custom data types can be expressed using a BNF grammar or something close to it (formally in the language, or informally by understanding the language and its representations). The structure of the code falls out of that in many situations (though certainly not all) as it determines what can be done at any particular point.
- vidarh 3y agoOh, how I wish more protocols in particular had been defined in something like BNF, and asked themselves for very good reasons why they insist on something that makes that hard. So many abominations of data structure and protocol designs have come out of people not bothering to write down a grammar of any type until after they'd already come up with something broken.
- vidarh 3y agoIn fact, I'm hacking on a Ruby implementation where just operator overloading and some simple methods is sufficient to get a BNF variant written as code to return a structure encoding parser combinators on execution. (There's nothing new about that, it's been done before, other than perhaps the sick and twisted levels of abuse of the Ruby syntax I'm toying with thanks to a newish feature (refinements) to make it look closer to plain BNF). And if course, automatically "compiling" bnf into parser combinators is easy.
- mort96 3y agoBNF and railroad diagrams contain the exact same info though... one BNF rule translates 1:1 to one railroad segment. I wrote a program[1] to convert BNF directly to railroad diagrams, and there are many others like it. [1] https://github.com/mortie/bnf-railroad-generator https://github.com/mortie/bnf-railroad-generator