Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi reserved words and identifiers

Declaring variables in Delphi brought me to consider a thing that I can't understand.

The question is this: declaring strings, one can observe that string is a reserved word, while declaring other data types, say integers, the data type qualifier is not a reserved word but an identifier (i.e. Integer, the capital I tells so).

In fact, Delphi lets you go to the definition of Integer, which you discover it is contained within the System unit, but it is only representative, because there is a comment stating that some constants (like True), identifiers (like Integer), functions and procedures are directly built into the compiler.

I can't figure out the reasons behind this choice.

Could someone help?


A little explanation of the difference between string and Integer types. The next code

type
  Integer = Char;

var
  I: Integer;

begin
  I:= 'A';
  ShowMessage(I);
end;

is correct and works as expected, while the next line

type
  string = Integer;

gives compile-time error.

like image 631
Federico Zancan Avatar asked Jan 03 '12 14:01

Federico Zancan


People also ask

What is an identifier in Delphi?

A declaration defines an identifier (such as the name of a function or variable) that can be used in expressions and statements, and, where appropriate, allocates memory for the identifier. This topic introduces the Delphi language character set, and describes the syntax for declaring: Identifiers.

Are identifiers reserved words?

In a computer language, a reserved word (also known as a reserved identifier) is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". This is a syntactic definition, and a reserved word may have no user-defined meaning.

What are the reserved words used in Pascal?

Reserved Words in Pascal For example, the words, program, input, output, var, real, begin, readline, writeline and end are all reserved words.

Are keywords the same as reserved words?

Keywords have a special meaning in a language, and are part of the syntax. Reserved words are words that cannot be used as identifiers (variables, functions, etc.), because they are reserved by the language. In practice most keywords are reserved words and vice versa.


1 Answers

As far i know string is a reserved word since the Turbo Pascal times. So the reason to keep it in this way must be for compatibility.

Pascal -> Turbo Pascal - > Object Pascal -> Delphi.

Check these resources.

  • The Pascal Programming Language (this shows the original reserved word of Pascal, without string)
  • Turbo_Pascal Version 6.0 Programmers Guide (this shows how the string is a reserved word)
like image 96
RRUZ Avatar answered Oct 23 '22 05:10

RRUZ