上下文无关语法?

发布于 2024-08-28 17:20:31 字数 349 浏览 2 评论 0原文

我遇到这个问题,我需要将以下 CFG 转换为 CNF 中的 CFG。

S-> ABa
A-> aab
B-> Ac

我知道步骤如下。

  1. 删除 epsilon 转换 - 通过以下方式完成
  2. 删除单位产生式
  3. 转换为 CNF:
    1. 为每个术语引入一个新的非终结符
    2. 用新的非终结符替换产生式规则中的终结符
    3. 引入新的非终结符以减少每个产生式右侧的长度

我对如何使用新的非终结符来做到这一点有点困惑问题如上。我主要对步骤 2 和单元制作感到困惑。

I have this problem where I need to convert the following CFG to CFG in CNF.

S-> ABa
A-> aab
B-> Ac

I know the steps are as follows.

  1. Remove epsilon transitions - Done
  2. remove unit productions
  3. convert to CNF by:
    1. introduce a new non terminal for each term
    2. replace terminals in the productions rules with the new nonterminal
    3. introduce new nonterminals to reduce the length of the right side of each production

I'm a bit confused on how I would do that with the problem above. Mostly I am confused on step 2 and unit productions.

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

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

发布评论

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

评论(2

不必你懂 2024-09-04 17:20:31

我知道步骤如下。

<块引用>

  1. 删除 epsilon 转换 - 完成
  2. 删除单位制作
  3. 通过以下方式转换为 CNF:
    1.为每个术语引入一个新的非终结符

    1. 用新的非终结符替换产生式规则中的终结符
    2. 引入新的非终结符以减少每个产生式右侧的长度

步骤 1 和 2 已经完成。所以我们只需要担心第 3 步。

开始语法:

S-> ABa
A-> aab
B-> Ac
  1. 为每个术语引入一个新的非终结符。

    <前><代码>S ->阿巴
    A->阿布
    B->乙酰胆碱
    C->一个
    D->乙
    E-> c

  2. 用新的非终结符替换产生式规则中的终结符。

    <前><代码>S -> ABC
    A-> CCD
    B-> AE
    C->一个
    D->乙
    E-> c

  3. 引入新的非终结符以减少每个产生式右侧的长度。

    <前><代码>S -> AF
    A-> CG
    B-> AE
    C->一个
    D->乙
    E-> c
    F->公元前
    G->光盘

I know the steps are as follows.

  1. Remove epsilon transitions - Done
  2. remove unit productions
  3. convert to CNF by:
    1.introduce a new non terminal for each term

    1. replace terminals in the productions rules with the new nonterminal
    2. introduce new nonterminals to reduce the length of the right side of each production

Steps 1 and 2 are already complete. So we only need to worry about step 3.

Starting Grammar:

S-> ABa
A-> aab
B-> Ac
  1. Introduce a new non terminal for each term.

    S  -> ABa
    A  -> aab
    B  -> Ac
    C  -> a
    D  -> b
    E  -> c
    
  2. Replace terminals in the productions rules with the new nonterminal.

    S  -> ABC
    A  -> CCD
    B  -> AE
    C  -> a
    D  -> b
    E  -> c
    
  3. Introduce new nonterminals to reduce the length of the right side of each production.

    S  -> AF
    A  -> CG
    B  -> AE
    C  -> a
    D  -> b
    E  -> c
    F  -> BC
    G  -> CD
    
‖放下 2024-09-04 17:20:31
S->ABa
C.N.F. is :
M->AB
Z->a
S->MZ

A->aab
C.N.F. is :
X->aa
Y->b
A->XY

B->Ac
C.N.F. is:
K->a
B->AK
S->ABa
C.N.F. is :
M->AB
Z->a
S->MZ

A->aab
C.N.F. is :
X->aa
Y->b
A->XY

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