- PC - Software -
Programmering - Pascal >TurboPascal >Delphi
Reserved Words
Identifiers
Operators
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
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
Identifiers must start with a letter.
The predefined standard identifiers may be redifined (not that it is a good idea).
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
q := 27 Div 10 { q = 2 }
r := 27 Mod 10 { r = 7 }
|
| i := pred(5) { i = 4 } c := pred('c') { c = 'b') |
| i := round( 2.7) { i = 3 } i := round(-2.7) { i = -3 } |
| i := succ(5) { i = 6 } c := succ('c') { c = 'd') |
| i := trunc( 2.7) { i = 2 } i := trunc(-2.7) { i = -2 } |