All Topics  
Reserved word

 

   Email Print
   Bookmark   Link






 

Reserved word



 
 
Reserved words (occasionally called keywords) are one type of grammatical construct in programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
s. These words have special meaning within the language and are predefined in the language’s formal specifications. Typically, reserved words include label
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 ....
s for primitive data types in languages that support a type system
Type system

In computer science, a type system may be defined as "a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute."....
, 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.






Discussion
Ask a question about 'Reserved word'
Start a new discussion about 'Reserved word'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Reserved words (occasionally called keywords) are one type of grammatical construct in programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
s. These words have special meaning within the language and are predefined in the language’s formal specifications. Typically, reserved words include label
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 ....
s for primitive data types in languages that support a type system
Type system

In computer science, a type system may be defined as "a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute."....
, 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 that uses "Object_" and their interactions to design applications and computer programs....
 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 ....
, 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. Unlike overriding predefined functions, methods, or subroutines, reserved words may not be redefined by the programmer. 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.

Comparison by language


Not all languages have the same numbers of reserved words. For example, Java (and other C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement 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 still in active use. 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 logic programming language. It is a general purpose language often associated with artificial intelligence and computational linguistics....
 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 Java and COBOL to calculate weekly earnings (reserved words are indicated in blue text):

// Calculation in Java:

if (salaried) amount = 40 * payrate; else amount = hours * payrate;



  • Calculation in COBOL:


IF Salaried THEN MULTIPLY Payrate BY 40 GIVING Amount ELSE MULTIPLY Payrate BY Hours GIVING Amount END-IF.



  • Other example of calculation in COBOL:


IF Salaried COMPUTE Amount = Payrate * 40 ELSE COMPUTE Amount = hours * payrate END-IF.



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 , several closely-related terms are used to describe the "computational power" of a computational system :Turing completenessTuring equivalence universality...
 languages.

Reserved words and language independence


Microsoft’s .NET
.NET Framework

The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software framework....
  Common Language Infrastructure (CLI)
Common Language Infrastructure

The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of a number of runtimes including the .NET Framework, Mono , and Portable.NET....
 specification allows code written in 40+ different 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 , formerly called Visual Basic .NET , is an object-oriented programming computer language that can be viewed as an evolution of Microsoft Visual Basic implemented on the .NET Framework....
 library may contain a class
Class (computer science)

In object-oriented programming, a class is a programming language construct that is used as a blueprint to create Object s. This blueprint includes Attribute s and Method s that the created objects all share....
 definition such as:

' Class Definition of This in Visual Basic.NET:

Public Class this ' This class does something... End Class

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#:

// Using This Class in C#:

this x = new this; // Won't compile!

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.

// Using This Class in C#:

@this x = new @this; // Will compile!

For consistency, this usage is also permitted in non-public settings such as local variables, parameter names, and private members.

External links