现代编程语言的语法是上下文无关的还是上下文敏感的? [英] Are the grammars of modern programming languages context-free or context-sensitive?

查看:104
本文介绍了现代编程语言的语法是上下文无关的还是上下文敏感的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++,C#或Java语言是上下文无关的还是上下文敏感的?

Are the C++, C# or Java languages context-free or context-sensitive?

推荐答案

由于

C++ is neither context-free nor context-sensitive, since the template system is Turing-complete and determining whether a piece of C++ code is legal C++ is undecidably hard. For example, I could define a template class that simulates a TM on a string and then creates a constant with value 1 if the machine accepts and 0 if it does not. If I did that, then the following code would be legal iff the TM halted on the given input:

int myArray[TMTemplate</* ... args ... */>::value];

由于TM拒绝,因此会创建大小为0的数组,这是不允许的.

Since if the TM rejects, this creates an array of size 0, which is not allowed.

C#和Java都不是上下文无关的,因为众所周知,检查变量是否在特定范围内正确且一致地使用并不是上下文无关的(证明很复杂,并且依赖于

Neither C# nor Java is context-free, because checking of whether a variable is used correctly and consistently throughout a particular scope is known not to be context-free (the proof is complex and relies on Ogden's lemma). However, I'm not sure whether or not they are context-sensitive.

希望这可以部分回答您的问题!

Hope this gives a partial answer to your questions!

这篇关于现代编程语言的语法是上下文无关的还是上下文敏感的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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