Keyword (programming)

from Wikipedia, the free encyclopedia

The term keyword (English keyword ) or reserved word denotes a word (English token ) in a programming language , which has a meaning determined by the definition of this programming language, and which may not be used as the name of variables or functions . All reserved words are known to the programming language compiler and are used in lexical analysis .

Keywords are the "vocabulary" of any programming language . Therefore one tries to keep the number low in the sense of learnability. You can find an overview, a so-called reference table, for almost every language in appropriate programming textbooks or on the Internet .

It should be noted that the practically infinite variety of programs and applications can be implemented using such a relatively small language range of rarely more than 50 key words.

definition

A keyword is a word that “looks” like a normal word, that is, fulfills the usual lexical syntax of identifiers - for example a sequence of letters - but may not be used as an identifier. For example, the word if is usually a keyword, while x is generally not one, so x = 1 is a valid assignment but if = 1 is not.

Keywords have different uses. Keywords in most programming languages can be grouped into different categories:

If you compare their references with programming languages such as C and their extension C ++ or other high-level programming languages , you can see that there are a number of similarities.

Extensions of programming languages ​​in particular naturally fall back on the language range of the predecessor and expand it if necessary. Another reason for a large number of keywords being used over and over again can be found in the history of programming languages .

The different definitions are clear when a programming language is analyzed by a combination of a tokenizer and a parser and the syntax of the language is generated by a lexical grammar for the words and a context-free grammar of the production rules for the phrases. This is common in the analysis of modern programming languages, and in this case keywords are a subset of reserved words because they must be distinguished from identifiers at the word level in order to be parsed differently at the phrase level.

In this case, keywords are defined as part of the lexical grammar and each marked as a separate type that differs from identifiers . In conventional notation, the keywords if and then are tokenized as types IF and THEN , respectively , while x and y are both tokenized as type identifiers.

See also

Individual evidence

  1. Microsoft Docs: C # Keywords
  2. Microsoft Docs: Keywords (C ++)
  3. Oracle: Java Language Keywords
  4. http://wwwuser.gwdg.de/~kboehm/ebook/30_anh_b_w6.html Keyword overview for C ++ and C