Reserved word
Encyclopedia
Reserved words are one type of grammatical construct in programming language
s. These words have special meaning within the language and are predefined in the language’s formal specifications. Typically, reserved words include labels
for primitive data types in languages that support a type system
, and identify programming constructs such as loops, blocks, conditionals, and branches.
The list of reserved words in a language are defined when a language is developed. Occasionally, depending on the flexibility of the language specification, vendors implementing a compiler may extend the specification by including non-standard features. Also, as a language matures, standards bodies governing a language may choose to extend the language to include additional features such as object-oriented
capabilities in a traditionally procedural language. Sometimes the specification for a programming language will have reserved words that are intended for possible use in future versions. In Java
,
The "Java Language
Specification" uses the term "keyword".
The ISO 9899 standard for the C programming language uses the term "keyword".
derivatives) has a rather sparse complement of reserved words—approximately 50 – whereas COBOL
has approximately 400. At the other end of the spectrum, pure Prolog
has none at all.
The number of reserved words in a language has little to do with how “powerful” a language is. COBOL was designed in the 1950s as a business language and was made to be self-documenting using English-like structural elements such as verbs, clauses, sentences, sections and divisions. C, on the other hand, was written to be very terse (syntactically) and to get more text on the screen. For example, compare the equivalent blocks of code from C and COBOL to calculate weekly earnings:
Pure Prolog logic is expressed in terms of relations, and execution is triggered by running queries over these relations. Constructs such as loops are implemented using recursive relationships.
All three of these languages can solve the same types of “problems” even though they have differing numbers of reserved words. This “power” relates to their belonging to the set of Turing-complete
languages.
Common Language Infrastructure (CLI)
specification allows code written in 40+ different programming languages to be combined together into a final product. Because of this, identifier/reserved word collisions can occur when code implemented in one language tries to execute code written in another language. For example, a Visual Basic.NET
library may contain a class
definition such as:
If this is compiled and distributed as part of a toolbox, a C# programmer, wishing to define a variable of type “
A similar issue arises when accessing members, overriding virtual methods, and identifying namespaces.
In order to work around this issue, the specification allows the programmer to (in C#) place the at-sign before the identifier which forces it to be considered an identifier rather than a reserved word by the compiler.
For consistency, this usage is also permitted in non-public settings such as local variables, parameter names, and private members.
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
s. These words have special meaning within the language and are predefined in the language’s formal specifications. Typically, reserved words include labels
Label (programming language)
A label in a programming language is a sequence of characters that identifies a location within source code. In most languages labels take the form of an identifier, often followed by a punctuation character . In many high level programming languages the purpose of a label is to act as the...
for primitive data types in languages that support a type system
Type system
A type system associates a type with each computed value. By examining the flow of these values, a type system attempts to ensure or prove that no type errors can occur...
, and identify programming constructs such as loops, blocks, conditionals, and branches.
The list of reserved words in a language are defined when a language is developed. Occasionally, depending on the flexibility of the language specification, vendors implementing a compiler may extend the specification by including non-standard features. Also, as a language matures, standards bodies governing a language may choose to extend the language to include additional features such as object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
capabilities in a traditionally procedural language. Sometimes the specification for a programming language will have reserved words that are intended for possible use in future versions. In Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
,
const
and goto
are reserved words — they have no meaning in Java but they also cannot be used as identifiers. By "reserving" the terms, they can be implemented in future versions of Java, if desired, without "breaking" older Java source code. Reserved words may not be redefined by the programmer, unlike predefined functions, methods, or subroutines, which can often be overridden in some capacity. The name of a predefined function, method, or subroutine is typically categorized as an identifier instead of a reserved word.Reserved word vs. keyword
A keyword is a word that is special only in certain contexts but a reserved word is a special word that cannot be used as a user-defined name.The "Java Language
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
Specification" uses the term "keyword".
The ISO 9899 standard for the C programming language uses the term "keyword".
Comparison by language
Not all languages have the same numbers of reserved words. For example, Java (and other CC (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
derivatives) has a rather sparse complement of reserved words—approximately 50 – whereas COBOL
COBOL
COBOL is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....
has approximately 400. At the other end of the spectrum, pure Prolog
Prolog
Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics.Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is declarative: the program logic is expressed in terms of...
has none at all.
The number of reserved words in a language has little to do with how “powerful” a language is. COBOL was designed in the 1950s as a business language and was made to be self-documenting using English-like structural elements such as verbs, clauses, sentences, sections and divisions. C, on the other hand, was written to be very terse (syntactically) and to get more text on the screen. For example, compare the equivalent blocks of code from C and COBOL to calculate weekly earnings:
Pure Prolog logic is expressed in terms of relations, and execution is triggered by running queries over these relations. Constructs such as loops are implemented using recursive relationships.
All three of these languages can solve the same types of “problems” even though they have differing numbers of reserved words. This “power” relates to their belonging to the set of Turing-complete
Turing completeness
In computability theory, a system of data-manipulation rules is said to be Turing complete or computationally universal if and only if it can be used to simulate any single-taped Turing machine and thus in principle any computer. A classic example is the lambda calculus...
languages.
Reserved words and language independence
Microsoft’s .NET.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...
Common Language Infrastructure (CLI)
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft and standardized by ISO and ECMA that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...
specification allows code written in 40+ different programming languages to be combined together into a final product. Because of this, identifier/reserved word collisions can occur when code implemented in one language tries to execute code written in another language. For example, a Visual Basic.NET
Visual Basic .NET
Visual Basic .NET , is an object-oriented computer programming language that can be viewed as an evolution of the classic Visual Basic , which is implemented on the .NET Framework...
library may contain a class
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
definition such as:
If this is compiled and distributed as part of a toolbox, a C# programmer, wishing to define a variable of type “
this
” would encounter a problem: 'this'
is a reserved word in C#. Thus, the following will not compile in C#:A similar issue arises when accessing members, overriding virtual methods, and identifying namespaces.
In order to work around this issue, the specification allows the programmer to (in C#) place the at-sign before the identifier which forces it to be considered an identifier rather than a reserved word by the compiler.
For consistency, this usage is also permitted in non-public settings such as local variables, parameter names, and private members.