TOPS-20 PASCAL Language Manual - Bitsavers
TOPS-20 PASCAL Language Manual - Bitsavers
TOPS-20 PASCAL Language Manual - Bitsavers
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
PROCEDURES AND FUNCTIONS<br />
In the main program, the WHILE loop reads a number and a name for one<br />
student. The following procedure call allocates memory for a new<br />
student record:<br />
NEW (!3tudent) ;<br />
The new record is inserted at the beginning of the list, that is,<br />
StudentA.Next points to the previous head of the list. The value of<br />
the new student record is assigned to the Start pointer.<br />
The WRITE DATA procedure writes the name and student ID number for<br />
each stu~ent in the linked list. After writing data for one student,<br />
the procedure assigns the address of the next record in the list to<br />
Next Student. The following call deallocates memory for one student<br />
record:<br />
11 I SPOS[ (Sturjf.~nt) ;<br />
After deallocating memory, the procedure assigns the value of<br />
Next Student to Student. When the current student record points to<br />
NIL, the loop stops executing.<br />
NEW AND DISPOSE -- RECORD-WITH-VARIANTS FORM<br />
You can use the following forms of NEW and DISPOSE when manipulating<br />
dynamic variables of a record type with variants:<br />
N EW ( p , t 1 , . • • , t n )<br />
DISPOSE(p,tl, ••. ,tn)<br />
The parameter p must be a pointer variable pointing<br />
variants. The optional parameters tl through<br />
constants. They represent nested tag field values<br />
outermost variant.<br />
to a record with<br />
tn must be scalar<br />
where tl is the<br />
If you create p without specifying the tag field values, the system<br />
allocates enough memory to hold any of the variants in the recard.<br />
Sometimes, however, a dynamic variable takes values of only a<br />
particular variant. If that variant requires less memory than NEW(p)<br />
allocates, you should use the NEW(p,tl, ••. ,tn) form.<br />
For example, the following record represents a menu selection:<br />
TYPE Menu_Ptr = ~Menu_Order;<br />
Meat_T~pe = (Fish, Fowl, Beef);<br />
Beef _Po rt i on ;:;; «()z _.. 10, Oz_ .. 16, Oz_32);<br />
Menu_Order = RECORD<br />
CASE Entree : Meat_T~pe OF<br />
Fish ( F i S tL T ~ P f.~ : ( S a 1m 0 n, Cod, P (-? r c h, T T' out ) ;<br />
Lemon: BOOLEAN);<br />
Fowl (Fowl_T~pe : (Chicken, Duck, Goose);<br />
Sauce: (Orange, Cherr~, Raisin»;<br />
Beef ( Bee f._ T y p e : ( S tea k, R 0 a~; t, P rim e _.. rib) ;<br />
CASE Size : Beef_Portion OF<br />
Oz_.10, Oz_:L6 : (BeeL.. vf?~.:j : (AT'tichoke, ML·~ed»;<br />
Oz_32 : (Stomach_Cure : (Bicarbonate,<br />
Antacid,None_Needed»;<br />
END;<br />
VAR Menu_Selection<br />
6-8