从我的计算机语言类(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-terminalX
and addX = ε | X E.
Convert every option
[ E ]
to a fresh non-terminalX
and addX = ε | E.
(We can convert
X = A [ E ] B.
toX = A E B | A B.
)Convert every group
( E )
to a fresh non-terminalX
and addX = E.
We can even do away with alternatives by having several productions with the same non-terminal.
X = E | E'.
becomesX = E. X = E'.
关于language-agnostic - 将EBNF转换为BNF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2466484/