An integer is a signed 16-bit integer with wrapping semantics, stored as two bytes.
A byte is an unsigned 8-bit integer with wrapping semantics, stored as one byte. They can be used interchangeably with integers, except when passed as parameters.
A real is a floating point value with 11 digits of mantissa, stored as six bytes. Underflowing will cause a result of zero. Overflowing will cause an error, halting the program.
A boolean can have a value of True or False, and is stored as one byte.
A char is a character in the ASCII character set, stored as one byte. Chars are ordered by ASCII value.
Valid characters are a-z, A-Z, 0-9, and each of +-*/=^<>()[]{}.,:;'#$. (. and .) are substitutes for [ and ]. (* and *) are substitutes for { and }.
Language elements are delimited by a blank, an end-of-line, or a comment. The maximum length of a program line is 127 characters, with excess characters being ignored.
String literals are delimited with single quotes, as in 'This is a string'. Single quotes can be included in a string by using two consecutive single quotes, as in 'You''re' or ''''. Single-character string literals are stored as a char.
There are two formats for including control characters in a string: a # followed by an integer literal, as in #10 or #$1B, or a ^ followed by a single character, as in ^G or ^[. Control characters can be concatenated with each other or with strings by placing them directly adjacent.
The declaration part of the body contains sections for label declarations, constant definitions, type definitions, variable declarations, and procedure/function declarations. Turbo Pascal allows these sections to occur in any number and in any order.
Label declarations are given as a comma-separated list of label identifiers. Numbers can be used as label identifiers. Any statement in the program may be prefixed with a label (label:), which can then be used by a goto statement.
The statement part specifies the actions to be executed by the program, and takes the form of a compound statement (begin, followed by a list of semicolon-separated statements, followed by end), followed by a period or semicolon.
to increments, downto decrements. The range is inclusive of the end value. The component statement of a for statement must not contain assignments to the control variable.
Strings are declared with a maximum length. The length of string cannot exceed 255.
typeFileName=string[14];
ScreenLine=string[80];
String variables occupy a number of bytes equal to the maximum length, plus a length byte. Characters are indexed starting from 1.
Strings are concatenated with + or Concat(a,b,...). If the result exceeds 255 characters, a run-time error occurs.
Strings can be compared with the relational operators.
If a string exceeding the maximum length of a string variable is assigned to the variable, the excesss will be truncated.
Strings can be indexed into using subscript notation, as String[3]. The length of a string can be accessed and modified via String[0]. The length must not be increased beyond the maximum length of the variable. When the length is increased, the added characters will be random.
Delete(string, index, count) Removes count characters from string, starting from index.
Insert(object, string, index) Inserts the string object into string at index.
Str(number, string) Converts number into a string, stores the result into string. number is a write parameter (like a format string, see p111).
Val(string, variable, code) Converts string to a number and stores the result in variable. Leading and trailing whitespace is forbidden. code is an integer variable that will be set to 0 on success, or the index of the first erroneous character on error.
The notation array[Suit,1..13] of Card is equivalent to array[Suit] of array[1..13] of Card, and the notation Deck[Hearts,10] is equivalent to Deck[Hearts][10].
Turbo Pascal provides two predefined arrays of type Byte, called Mem and Port. These are used to access CPU memory and data ports (see chapters 20, 21, and 22).
The Mark(var) procedure assigns the value of the heap pointer to the pointer variable var. The Release(var) procedure sets the heap pointer to the address contained in var, where var is a pointer variable previously set by Mark. The type of the pointer variable is arbitrary, as long as it’s a pointer. Release discards all heap-alocated variables above this address. The function MemAvail returns the available space on the heap.
Pointers are dereferenced with a trailing ^:
WriteLn(Person^.Name)
The heap can also be allocated and freed by the Dispose(var) procedure, which will deallocate only the referenced value, leaving a hole that can be filled by a small enough type in the future. This must never be used in conjunction with Mark/Release.
GetMem and FreeMem are more advanced ways of allocating and freeing blocks of specific sizes.
The top-left corner is (0,0). Draw operations are clipped to the screen. Activating or reactivating a graphics mode will clear the screen. Graphics can be mixed with text. The system should be returned to text mode with the TextMode procedure before the program closes.
The HiRes graphics mode gives a 640x200 monochrome pixel screen. The background colour is black, and the foreground colour is set by HiResColor(colour). Colour 15 is white.
Plot(x, y, colour) will draw a pixel, with colour referencing a colour from the active palette. Draw(x0, y0, x1, y1, colour) will draw a line.
absolute* external* nil shl*
and file not shr*
array forward overlay* string*
begin for of then
case function or type
const goto packed to
div inline* procedure until
do if program var
downto in record while
else label repeat with
end mod set xor*