将EBNF转换为BNF [英] Converting EBNF to BNF

查看:412
本文介绍了将EBNF转换为BNF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

距离我的计算机语言课程已有几年了,所以我忘记了BNF和EBNF的优缺点,而且我旁边没有教科书.具体来说,我忘记了如何将EBNF转换为BNF.

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.

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

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.

推荐答案

请参见以下链接,其中包含有关每个需要转换的作品的说明:

Please see the following link, it contains instructions for each production that needs to be converted:

http://lampwww.epfl. ch/teaching/archive/compilation-ssc/2000/part4/parsing/node3.html

对于构建解析器(尤其是自底向上),BNF语法通常比EBNF更好.但是将EBNF语法转换为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:

  • 将每个重复{ E }转换为新的非终止X并添加

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

X = ε | X E.

  • 将每个选项[ E ]转换为新的非终端X并添加

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

    X = ε | E.
    

    (我们可以将X = A [ E ] B.转换为X = A E B | A B.)

    将每个组( E )转换为新的非终端X并添加

    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'.变为X = E. X = E'.

    这篇关于将EBNF转换为BNF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆