| 1 |
EX06: An example in which Pascal program text is rearranged to form an ADT. |
| 2 |
This example achieves what EX05 does, but without additive macros. |
| 3 |
|
| 4 |
@!****************************** |
| 5 |
|
| 6 |
@O@<ex06.out@>==@{@- |
| 7 |
program adt(input,output); |
| 8 |
@<Types@> |
| 9 |
@<Variables@> |
| 10 |
@<Procedures@> |
| 11 |
begin startproc; end. |
| 12 |
@} |
| 13 |
|
| 14 |
@$@<Types@>==@{@- |
| 15 |
@<Buffer type@> |
| 16 |
@<Complex type@> |
| 17 |
@} |
| 18 |
|
| 19 |
@$@<Variables@>==@{@- |
| 20 |
@<Buffer variable@> |
| 21 |
@} |
| 22 |
|
| 23 |
@$@<Procedures@>==@{@- |
| 24 |
@<Buffer procedures@> |
| 25 |
@<Complex procedures@> |
| 26 |
@} |
| 27 |
|
| 28 |
@!****************************** |
| 29 |
|
| 30 |
@$@<Buffer type@>==@{@- |
| 31 |
type buffer_type = record |
| 32 |
length : integer; |
| 33 |
buf : array[1..100] of char; |
| 34 |
end; |
| 35 |
@} |
| 36 |
|
| 37 |
@$@<Buffer variable@>==@{@- |
| 38 |
bigbuf : buffer_type; |
| 39 |
@} |
| 40 |
|
| 41 |
@$@<Buffer procedures@>==@{@- |
| 42 |
procedure buf_init(var b : buffer_type) {Body of buf_init} |
| 43 |
procedure buf_add(var b : buffer_type; ch : char) {Body of buf_add} |
| 44 |
procedure buf_get(var b : buffer_type; var ch : char) {Body of buf_get} |
| 45 |
@} |
| 46 |
|
| 47 |
@!****************************** |
| 48 |
|
| 49 |
@$@<Complex type@>==@{@- |
| 50 |
type complex_type = record r,i : real; end; |
| 51 |
@} |
| 52 |
|
| 53 |
@$@<Complex procedures@>+=@{@- |
| 54 |
procedure cm_set(var c: complex_type; a,b : real) {Body of cm_set} |
| 55 |
procedure cm_add(a,b : complex_type; var c: complex_type) {Body of cm_add} |
| 56 |
{Other procedures and functions} |
| 57 |
@} |