Why does a programming language need keywords?

c, identifier, keyword

Solution

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

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

Should it actually break? Or should it treat it as `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.

Problem

For example (in C): ``` int break = 1; int for = 2; ``` Why will the compiler have any problems at all in deducing that `break` and `for` are variables here? So, we need keywords because - 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.

Original source

Related problems