【问题标题】:Extended BNF problems扩展 BNF 问题
【发布时间】:2013-07-21 05:51:25
【问题描述】:

我对扩展 BNF 有一些疑问。

(* Extended BNF grammar *)
min = 5;
max = 10;
value = integer; (* How can I set the range rule: `min <= value <= max`? *)

第二个问题:

name = letter, { letter | decimal digit };
(* The common length of the comment line must be not more than 128 characters. 
But I don't know the name's length. How can I set this restriction? *)
        comment line = ';', name, ' ', 128 * [ character ], new line;

我已完整阅读 ISO/IEC 14977:1996(E),但没有找到答案。

谢谢。

【问题讨论】:

    标签: syntax grammar bnf ebnf


    【解决方案1】:

    据我所知,您不能单独使用 BNF/EBNF 解析器,但可以结合一些后处理来完成。

    诀窍是通过 EBNF 规则解析文本而不考虑约束。稍后,当您获得抽象语法树 (AST) 时,您使用 Javascript(或您用于解析的任何语言)并逐个节点地遍历它,并测试它的约束。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多