I was looking into making a Bison-based parser using some BNF files I found on Github. My issue, however, is that I cannot seem to determine what variation of BNF the files are using.
Here is a link to a folder containing samples of the BNF variant.
In bnf.rkt, the author references the BNF Wikipedia page, yet his file looks nothing like it:
## The following comes from: http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form
<syntax> : <rule> | <rule> <syntax>
<rule> : <opt-whitespace> "<" <RULE-NAME> ">" <opt-whitespace> "::="
<opt-whitespace> <expression> <line-end>
<opt-whitespace> : " " <opt-whitespace> | "" ## "" is empty string, i.e. no whitespace
<expression> : <list> | <list> "|" <expression>
<line-end> : <opt-whitespace> <EOL> | <line-end> <line-end>
<list> : <term> | <term> <opt-whitespace> <list>
<term> : <literal> | "<" <RULE-NAME> ">"
<literal> : '"' <TEXT> '"' | "'" <TEXT> "'" ## actually, the original BNF did not use quotes
Here is an example (from the repo) of how this syntax is used to represent basic JSON:
;; Simple baby example of JSON structure
json: number | string
| array
| object
number: NUMBER
string: STRING
array: "[" [json ("," json)*] "]"
object: "{" [kvpair ("," kvpair)*] "}"
kvpair: ID ":" json
Does anyone have any idea of what he is using? I would like to convert this into a Bison-readable format, if possible.
Thanks in advance.
It's a kind of extended BNF, similar to that used in various parser generators, roughly based on bison syntax with the addition of brackets and regular expression operators. The documentation is here, and a summary would be:
Aside from the last point, that makes it essentially the same as the basic format used by ANTLR, for example.