为什么一个编程语言需要的关键字? [英] Why does a programming language need keywords?

查看:253
本文介绍了为什么一个编程语言需要的关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如(在C):

int break = 1;
int for = 2;

为什么编译器有任何问题,都在演绎的是变量在这里?

因此​​,我们需要的关键字,因为

So, we need keywords because


  • 我们想要的程序是可读

  • 我们不想今天已经很复杂的编译器
  • 的工作过度复杂化
  • ,但最重要的是,语言是很多更强大,如果一些key'words保留一些特殊的操作。然后,语言能想到的在更高层次上是有用的,而不是在试图实现在一个明确的方式循环死亡。

  • we want the programs to be readable
  • we do not want to over-complicate the job of already complex compilers of today
  • but most importantly, a language is lot more powerful if some 'key'words are reserved for some special actions. Then, the language can think of being useful at a higher level rather than dying in trying to implement a for loop in an unambiguous way.

推荐答案

那么会出现什么计算机做的时候就遇到如下语句:

Then what will the computer do when it comes across a statement like:

while(1) {
  ...
  if (condition)
    break;
}

如果它实际上打破?还是应该把它当作 1;

语言将成为在某些情况下模糊的,或者你必须创建一个非常聪明的解析器,可以推断出微妙的语法,这只是不必要的额外工作。

The language would become ambiguous in certain cases, or you'd have to create a very smart parser that can infer subtle syntax, and that's just unnecessary extra work.

这篇关于为什么一个编程语言需要的关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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