[英]How should “or” be treated in a BNF production rule?
I'm looking at the BNF grammar for SVG path data, and one of the derivation rules is: 我正在查看SVG路径数据的BNF语法,派生规则之一是:
digit-sequence ::= digit | digit digit-sequence
Is there a sematic difference beween this rule and: 该规则与以下内容之间是否存在语义差异:
digit-sequence ::= digit digit-sequence | digit
Exactly what does the |
究竟什么是
|
mean in a BNF grammar? BNF语法是什么意思? Should the first match be selected, or the one that consumes most of the input?
应该选择第一个匹配项,还是选择消耗大部分输入的匹配项?
| | in a BNF grammar means alternation, ie if the current token matches one alternative or another it must be accepted.
BNF中的语法表示交替,即,如果当前令牌匹配一个替代或另一个替代,则必须接受。 Here is a tutorial on BNF.
这是有关BNF的教程。
However, the rule you quoted is recursive (note digit-sequence is on both the left- and the right-hand sides of the rule) so that rule means a sequence of digits, eg [0-9]+ in regex. 但是,您引用的规则是递归的(请注意,数字顺序位于规则的左右两侧),因此规则表示数字序列,例如正则表达式中的[0-9] +。
BTW, parsing SVG path data seems to be an untrivial task so that a general BNF parser was once used to parse path data in combination with XML parser — https://metacpan.org/release/MarpaX-Languages-SVG-Parser 顺便说一句,解析SVG路径数据似乎是一项艰巨的任务,因此曾经有一个通用的BNF解析器与XML解析器结合使用来解析路径数据— https://metacpan.org/release/MarpaX-Languages-SVG-Parser
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.