什么是模棱两可的上下文无关文法? [英] what is an ambiguous context free grammar?

查看:141
本文介绍了什么是模棱两可的上下文无关文法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太清楚上下文无关语法中的歧义概念。如果有人可以帮助我并解释这个概念或提供很好的资源,我将不胜感激。

解决方案

  T * U; 

这是指针声明还是乘法?在知道真正的 之前,您无法知道。 p>

因此,表达式的语法取决于表达式的语义(含义)。那不是上下文无关的-在上下文无关的语言中,那只能是一件事,而不是两件事。 (这就是为什么他们不让这样的表达式成为 D 中的有效语句。)



另一个示例:

  T< U> V; 

是模板用法还是大于或小于操作? (这就是为什么他们在T!(U)V 的原因。 nofollow> D -括号仅具有一种用途,而插入号具有另一种用途。)


I'm not really very clear on the concept of ambiguity in context free grammars. If anybody could help me out and explain the concept or provide a good resource I'd greatly appreciate it.

解决方案

T * U;

Is that a pointer declaration or a multiplication? You can't tell until you know what T and U actually are.

So the syntax of the expression depends on the semantics (meaning) of the expression. That's not context-free -- in a context-free language, that could only be one thing, not two. (This is why they didn't let expressions like that be valid statements in D.)

Another example:

T<U> V;

Is that a template usage or is that a greater-than and less-than operation? (This is why they changed the syntax to T!(U) V in D -- parentheses only have one use, whereas carets have another use.)

这篇关于什么是模棱两可的上下文无关文法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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