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 />

define OPCODE as an integer variable<br />

read OPERAND1, OPERAND2, OPCODE<br />

go to OP.LABEL(OPCODE)<br />

'OP.LABEL(1)'let RESULT = OPERAND1 + OPERAND2<br />

go to PRINT<br />

'OP.LABEL(2)'let RESULT = OPERAND1 - OPERAND2<br />

go to PRINT<br />

'OP.LABEL(3)'let RESULT = OPERAND1 * OPERAND2<br />

go to PRINT<br />

'OP.LABEL(4)'let RESULT = OPERAND1 / OPERAND2<br />

go to PRINT<br />

'PRINT' print 1 line with RESULT thus<br />

RESULT IS: *******.******<br />

The read statement accepts two numeric operands and an integer value in the range 1 to 4 indicating<br />

the operations addition, subtraction, multiplication, and division. This integer code is used as a<br />

label subscript to select the appropriate transfer. The maximum subscript value allowed is arbitrarily<br />

limited to 3000. As an internal table (dimensioned by the largest subscript value used) must be<br />

generated, the use of widely ranging subscripts can lead to inefficiencies.<br />

When the number of possible transfers is small, and the indexing values can be chosen to be contiguous<br />

from 1, an alternative construct may be useful. The possible transfer labels may be listed,<br />

in order, within a go to statement. If label1, label2, label3, ..., labeln represent<br />

statement labels, and E represents an arithmetic expression, a statement of the form:<br />

go to label1 or label2 or ... or labeln per E<br />

evaluates e (rounding if it is real valued) and transfers program control to label1 if E=1, to<br />

label2 if E=2, ..., to labeln if E=n. That is, control is transferred to the label in the first label<br />

position, or the second label position, or the n th label position, according to the computed value of<br />

the expression E. Again, illegal transfers, where E lies outside the range 1 to n, cause abnormal<br />

program termination in most <strong>SIMSCRIPT</strong> <strong>II.5</strong> implementations. Any label names defined within<br />

the program may be included in the list, and any name may be repeated in more than one position.<br />

The label names in the list must be separated by the word or, or by a comma. The word to is optional.<br />

Typical computed go to statements are:<br />

go to ACCOUNT.ONE or ACCOUNT.TWO per CUSTOMER<br />

go to READ.AGAIN, WINDUP, CONTINUE or HALT per<br />

INSTRUCTION<br />

Two or more distinct label names may be used to identify the same statement. They are called<br />

equivalent labels. The use of equivalent labels, together with the computed go to statement, may<br />

be useful during program development, when the logical paths in the program have been identified,<br />

but not all segments have been fully coded. The go to statement may list all the segment labels.<br />

A number of these may reference the same statement. The use of a computed go to is shown in<br />

the following example, which is an alternative to the previous example. It can be seen that several<br />

258

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

Saved successfully!

Ooh no, something went wrong!