language-agnostic - 将EBNF转换为BNF

标签 language-agnostic computer-science bnf ebnf recursive-descent

从我的计算机语言类(class)开始已经过去了几年,所以我忘记了BNF和EBNF的优缺点,而且我旁边没有教科书。具体来说,我忘记了如何将EBNF转换为BNF。
从我所记得的很少,我知道要点之一就是

{ term }
进入
<term> | <many-terms>
但我不记得其他规则。我试图在网上查找此内容,但只能找到指向家庭作业问题的链接,或者有关用花括号转换术语的小注释。我找不到定义翻译的详尽规则列表。

最佳答案

参见this page🕗它包含需要转换的每个产品的说明:

From EBNF to BNF


For building parsers (especially bottom-up) a BNF grammar is often better, than EBNF. But it's easy to convert an EBNF Grammar to BNF:

  • Convert every repetition { E } to a fresh non-terminal X and add

    X = ε | X E.
    
  • Convert every option [ E ] to a fresh non-terminal X and add

    X = ε | E.
    

    (We can convert X = A [ E ] B. to X = A E B | A B.)

  • Convert every group ( E ) to a fresh non-terminal X and add

    X = E.
    
  • We can even do away with alternatives by having several productions with the same non-terminal.

    X = E | E'. becomes X = E. X = E'.

关于language-agnostic - 将EBNF转换为BNF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2466484/

相关文章:

java - 什么是测试BNF语法的好工具?

algorithm - 命名该技术(它可能被称为 'piggybacking' )

algorithm - "Path planning"和 "Pathfinding"之间有区别吗?

regex - 正则表达式在理论上足够强大有什么用?

python - 使用 Python 的分配算法

elisp - 使用 Emac 的 SMIE 来解析带有可选的语​​言;用于语句终止

java - 是否需要参数

language-agnostic - 作为初次契约(Contract)程序员要知道什么?

linq 样式,链接 where 子句与和运算符

algorithm - 在有向加权图中找到两个节点之间的最短路径