【问题标题】:How to understand this EBNF Pascal Definition如何理解这个 EBNF 帕斯卡定义
【发布时间】:2019-01-15 00:28:57
【问题描述】:

我正在从 EBNF defintion 实现一个 Pascal 解析器。以下规范中有一些我不明白的地方:

variable
   entire-variable | component-variable | referenced-variable 

entire-variable
   variable-identifier | field-identifier

component-variable
   indexed-variable | field-designator | file-buffer

field-designator
   record-variable "." field-identifier 

假设我们想在a.b[0] 上应用variable 产生式。由于a 符合entire-variable 产生式,这将阻止component-variable 检测到field-designator a.b,因此a 后面的. 将停止解析器。

【问题讨论】:

  • 我面前没有 Pascal 规范,但我可以做一些观察。当解析器看到“a”时,它应该已经知道“a”的定义是什么。解析器也可以提前看到'.'。
  • 这个问题的读者可能还想看看How to define Pascal variables in PetitParser

标签: pascal ebnf


【解决方案1】:

由于 EBNF 没有有序选择,因此通常使用最长匹配来确定适用哪些规则。

【讨论】:

  • 感谢乌兰。这是有道理的。我不知道选择没有顺序。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-27
相关资源
最近更新 更多