问题描述
我不太清楚上下文无关语法中的歧义概念。如果有人可以帮助我并解释这个概念或提供很好的资源,我将不胜感激。
T * U;
这是指针声明还是乘法?在知道真正的 之前,您无法知道。 p>
因此,表达式的语法取决于表达式的语义(含义)。那不是上下文无关的-在上下文无关的语言中,那只能是一件事,而不是两件事。 (这就是为什么他们不让这样的表达式成为中的有效语句。)
另一个示例:
T< U> V;
是模板用法还是大于或小于操作? (这就是为什么他们在-括号仅具有一种用途,而插入号具有另一种用途。)
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.)
这篇关于什么是模棱两可的上下文无关文法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!