18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Figure 2-5c illustrates a more complex situation in which a main routine and three subprograms<br />

interact. Subprograms 1 and 2 are both called and calling routines: They are called by the main<br />

routine and, in turn, they call on subprogram 3. The call of subprogram 1 or 2 by the main routine<br />

is the first level of calling. The call of subprogram 3 by subprograms 1 and 2 while under the control<br />

of the main routine is a second level. In general, there can be any level of calling in effect within<br />

a program at any time. The calling rules do not change from level to level. Control always passes<br />

from a calling to a called program and back again. Whether there are many intermediate calls and<br />

returns between an original call on a subprogram and a return to its calling program is insignificant.<br />

If A calls B and B calls C, then C must return control to B before B can return to A. A subprogram<br />

cannot return control to any routine other than the one that called it. For example, C cannot return<br />

control directly to A.<br />

MAIN PROGRAM<br />

SUBPROGRAM1<br />

SUBPROGRAM 3<br />

SUBPROGRAM SUBPROGRAM 2 3<br />

END<br />

Figure 2-5c. Program Consisting of Three Subprograms and a Main Routine<br />

2.10 Routine Definition<br />

A <strong>SIMSCRIPT</strong> <strong>II.5</strong> program may be composed of several program sections: a preamble (data declaration)<br />

section, a main routine, and a number of subprograms. Statements are needed to delimit<br />

these program components. As already noted, the variable declaration section is headed by the<br />

word preamble and terminated by the word end.<br />

The statements that make up the main routine should be preceded by the one-word statement:<br />

main<br />

This is not strictly necessary. Since all other sections of a program must have a heading, it is possible<br />

to omit the main statement and assume that statements belong to the main routine if not otherwise<br />

labeled. Nevertheless, it is good programming practice to label program sections fully. Each<br />

54

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

Saved successfully!

Ooh no, something went wrong!