检查语法歧义

编程入门 行业动态 更新时间:2024-10-26 10:27:40
本文介绍了检查语法歧义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下是一段语法的摘录,我正在尝试查看它是否模棱两可.

The following is the extract of a piece of grammar that I'm trying to see whether it is ambiguous or not.

Y->b Y->Z Z->bW W->d W->ϵ

当我计算第一组语法时,我偶然发现Y的第一个不规则性.

When I compute the first set of the grammar I stumble upon this irregularity for first of Y.

First(Y) = {b,First(Z)} First of Z = b so I have the set First(Y)={b,b}.

我想知道的是,足以证明给定该证据的语法是否模棱两可.还是应该将其设置为First(Y) = {b}.

What I want to know is that sufficient enough to prove that the grammar given this evidence is ambigious or not. Or should the set be First(Y) = {b}.

推荐答案

要证明语法是模棱两可的,您只需要证明至少有两种方法可以得出结果.

To prove a grammar is ambiguous, you simply need to prove that there's at least two different ways to reach a result.

考虑示例并考虑修改,您确实有一个模棱两可的语法,因为您可以通过以下方式导出表达式b:

Considering your example, and considering your edit, you do have an ambiguous grammar, since you're be able to derive the expression b by:

Y -> b Y -> Z Z -> bW Y -> d W -> ϵ

第一种方式:

Y -> b

第二种方式:

Y -> Z Y -> Z -> bW Y -> Z -> bW -> bϵ Y -> Z -> bW -> bϵ -> b

这是一个模棱两可的语法.

This is an ambiguous grammar.

更多推荐

检查语法歧义

本文发布于:2023-11-07 06:48:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565808.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:歧义   语法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!