MLHA - PC - Software - Programmering - Pascal >TurboPascal >Delphi
downx.gif (830 bytes)Reserved Wordsdownx.gif (830 bytes)Identifiersdownx.gif (830 bytes)Operatorsdownx.gif (830 bytes)Structures: Program, Branch, Loop

Pascal, udviklet af Niklaus Wirth 1968-70, blev i 1973 defineret med følgende reserverede ord og standard identifiers - beskrevet i bogen:
Kathleen Jensen & Niklaus Wirth: Pascal - User Manual and Report [Springer-Verlag 1975]

 

http://www.merlyn.demon.co.uk/pascal.htm
http://www.freepascal.org/fpc.html : Free Pascal
http://www.soft32.com/download_19187.html : Irie Pascal

 

Reserved words

And, Array, Begin, Case, Const, Div, Do, Downto, Else, End, File, For, Function, Goto, If, In, Label, Mod, Nil, Not, Of, Or, Packed, Procedure, Program, Record, Repeat, Set, Then, To, Type, Until, Var, While, With
 

Standard Identifiers

Identifiers must start with a letter.
The predefined standard identifiers may be redifined (not that it is a good idea).

Constants
false, true, maxint
Types
integer, boolean, real, char, text
Functions
abs, arctan, chr, cos, eof, eoln, exp, ln, odd, ord, pred, round, sin, sqr, sqrt, succ, trunc
Procedures
get, new, pack, page, put, read, readln, reset, rewrite, unpack, write, writeln
 

Program Structure
v Minimal program: Hello World

program programname;
const
  const1 = value;
var
  var1: type;
label
  label1, label2;
  
procedure pname(param1: type, param2: type)
begin
  { statements }
end;
  
function fname(param1: type, param2: type): type
begin
  { statements }
  fname := value;  { function return value }
end;
  
begin
  { statements: program execution starts here }

label1: 

  goto label1;
end.

Program example:

program example;
const
  pi = 3.1416; 
  sep = '---------';
var
  radius, height : real;
  count : integer;
label
  1, 2;
  
function surface(r: real, h: real): real
var disk, cyl : real;
begin
  disk := pi * r * r;
  cyl : h * r;
  surface := 2 * disk + cyl;
end;
  
procedure line(str : array [] of char)
begin
  writeline(sep, ' ', str, ' ', sep);
end;
  
begin
  line ('start')
  count := 0; height := 5;
  writeline('Height: ', height);
1: 
  if count = 10 goto 2;
  count := count + 1;
  write('Radius: ', count);
  writeline(' - Surface area: ', surface(count, height));
  goto 1;
2:
  line ('End')
end.

Minimal program: 'Hello World':

program hello;
begin
  writeln('Hello World');
end.

 

Structure: Branch, Loop
> Program structure: Goto

If
x
Case
x
For
x
Repeat
x
While
x
   

Constants

false, true
false < true
>Types: boolean
>Operators: And, Or, Not
maxint
= 32767 in PC systems
 

Types

integer
>Operators: Div, Mod
>Functions: round, trunc
boolean
>Constants: false, true
>Operators: And, Or, Not, In, relational
>Functions: odd, eof, eoln
real
>Functions: sin, cos, arctan, ln, exp, sqrt
char
'a'..'z', 'A'..'Z', '0'..'9', ' ', '*', etc
>Functions: Chr, Ord
text
 

Operators

+, -, *, /
=, <>, <, >, <=, >= { relational operators }
>Types: boolean
in
>Types: boolean
And, Or, Not
>Types: boolean
Div, Mod
Div : Divide & Truncate
Mod: Division remainder
q := 27 Div 10  { q = 2 }
r := 27 Mod 10  { r = 7 }
>Types: integer
 

Functions

abs (x)
The absolute value of x
 
arctan (x) : real
 
chr (x: integer) : char
>Ord
 
cos (x) : real
>Sin
 
eof (f: file) : boolean
end-of-file
 
eoln (f: file) : boolean
end-of-line
 
exp (x) : real
 
ln (x) : real
 
odd (x: integer) : boolean
True if x = 1, 3, 5, etc
 
ord (x: char) : integer
>Chr
 
pred (x: integer | char)
i := pred(5)   { i = 4 }
c := pred('c') { c = 'b')
>succ
 
round (x: real) : integer
x rounded
i := round( 2.7)  { i =  3 }
i := round(-2.7)  { i = -3 }
>trunc
 
sin (x) : real
>Cos
 
sqr (x)
x squared (x * x)
 
sqrt (x) : real
The square root of x
 
succ (x: integer | char)
i := succ(5)   { i = 6 }
c := succ('c') { c = 'd')
>pred
 
trunc (x: real) : integer
x truncated (the whole part)
i := trunc( 2.7)  { i =  2 }
i := trunc(-2.7)  { i = -2 }
>round
 

Procedures

get
new
pack
page
put
read
readln
reset
rewrite
unpack
write
writeln