将 EBNF 转换为 BNF

发布于 2024-08-25 08:55:13 字数 287 浏览 12 评论 0原文

我的计算机语言课已经过去几年了,所以我已经忘记了 BNF 和 EBNF 的要点,而且我身边也没有教科书。具体来说,我忘记了如何将 EBNF 转换为 BNF。

据我所知,我知道要点之一是转换

{ term }

<term> | <many-terms>

但我不记得其他规则。我尝试在网上查找此内容,但只能找到家庭作业问题的链接,或有关用大括号转换术语的小评论。我找不到定义翻译的详尽规则列表。

It's been a few years since my computer-language class and so I've forgotten the finer points of BNF's and EBNF's and I don't have a textbook next to me. Specifically, I've forgotten how to convert an EBNF into BNF.

From what little I remember, I know that one of the main points is to convert

{ term }

into

<term> | <many-terms>

But I don't remember the other rules. I've tried to look this up online but I can only find links to either homework questions, or a small comment about converting terms with curly braces. I can't find an exhaustive list of rules that define the translation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

滴情不沾 2024-09-01 08:55:13

请参阅此页面

See this page.???? It contains instructions for each production that needs to be converted:

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'.

樱花坊 2024-09-01 08:55:13

请注意:ISO 标准中列出的 EBNF 还包括语法规则的例外情况,这些例外情况没有 BNF 等效项。 500 - 内部服务器错误给出的转换仅适用于与 RBNF/ABNF 重叠的 EBNF 部分。

Be warned: EBNF as it's listed in the ISO standard also includes exceptions to syntactic rules, which do not have a BNF equivalent. The conversion given by 500 - Internal Server Error only works for the portion of EBNF which overlaps with RBNF/ABNF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文