【发布时间】:2014-11-17 01:25:49
【问题描述】:
我正在考虑使用我在 Github 上找到的一些 BNF 文件来制作基于 Bison 的解析器。然而,我的问题是我似乎无法确定文件使用的 BNF 变体。
Here is a link 到包含 BNF 变体样本的文件夹。
在bnf.rkt 中,作者引用了BNF Wikipedia page,但他的文件看起来一点也不像:
## 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
以下是如何使用此语法表示基本 JSON 的示例 (from the repo):
;; Simple baby example of JSON structure
json: number | string
| array
| object
number: NUMBER
string: STRING
array: "[" [json ("," json)*] "]"
object: "{" [kvpair ("," kvpair)*] "}"
kvpair: ID ":" json
有人知道他在用什么吗?如果可能的话,我想把它转换成 Bison 可读的格式。
提前致谢。
【问题讨论】: