18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>SIMSCRIPT</strong> <strong>II.5</strong> <strong>Programming</strong> <strong>Language</strong><br />

The utility and application of this feature are best described in a series of examples.<br />

1. It can be used to construct a "ragged table," a two-dimensional array with a different number<br />

of elements in each row. The construction follows:<br />

(a) Set up a base pointer and an array of row pointers:<br />

reserve TABLE(*,*) as 5 by *<br />

This statement assigns an array of five elements, each of which contains an unassigned pointer, to<br />

the base pointer TABLE(*,*). The asterisk in the array assignment clause 5 by * indicates that<br />

only pointers, not data values, are to be stored. After execution of this statement, the structure<br />

shown in figure 6-4 exists in memory. The base pointer points to the array of row pointers. The<br />

row pointers do not yet point to anything because arrays have not been assigned to them.<br />

ROW POINTERS<br />

⎧<br />

TABLE(1,*)<br />

BASE POINTER ⎪ TABLE(2,*)<br />

TABLE(*,*) ⎨ TABLE(3,*)<br />

⎪<br />

TABLE(4,*)<br />

⎩<br />

TABLE(5,*)<br />

Figure 6-4. Memory Structure After Reserve Statement<br />

(b) Assign data arrays to each of the row pointers. A dimension must be given for each<br />

row, by reading a data value for each row. For example:<br />

for I = 1 to 5,<br />

do<br />

read D<br />

reserve TABLE(I,*) as D<br />

loop<br />

The reserve statement assigns an array of D elements to each of the row pointers TABLE(I,*),<br />

as I varies from 1 to 5. If the values of D read are 4, 2, 6, 1, and 3, respectively, the final ragged<br />

table structure appears as shown in figure 6-5.<br />

The ragged array TABLE(I,J) may be used in the same way as any rectangular array, with the only<br />

restriction that care must be taken not to reference a nonexistent array element, as, for example,<br />

TABLE(4,3) in figure 6-5.<br />

2. The pointer mechanism may be used to make the processing of multiple-dimensioned arrays<br />

more efficient, eliminating the recomputation of unchanging subscripts when processing<br />

elements of a single dimension in some regular fashion. For example, the program<br />

segment described in (a) below can be made more efficient by rewriting it as shown in (b).<br />

252

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!