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>Programming</strong> <strong>Language</strong> Concepts<br />

constant<br />

or<br />

constant to constant<br />

the mode of expression and each constant must agree, in accordance with the following rules:<br />

1. If expression is numeric (integer, real or double), then each constant must be numeric.<br />

2. If expression is alpha or text, then constant must be a literal string delimited by quotation<br />

marks,<br />

e.g., "string".<br />

3. If expression is a subprogram variable, constant must be a subprogram literal (see<br />

paragraph 2.30) delimited by single apostrophes, e.g., 'sin.f'.<br />

Each statement group is a sequence of 0 or more <strong>SIMSCRIPT</strong> statements.<br />

The following example emulates a simple calculator:<br />

define OPERATION as a text variable<br />

define OPERAND1, OPERAND2 and RESULT as real variables<br />

until OPERATION = "halt"<br />

do<br />

read OPERATION, OPERAND1 AND OPERAND2<br />

select case OPERATION<br />

case "+"<br />

let RESULT = OPERAND1 + OPERAND2<br />

case "-"<br />

let RESULT = OPERAND1 - OPERAND2<br />

case "*"<br />

let RESULT = OPERAND1 * OPERAND2<br />

case "/"<br />

let RESULT = OPERAND1 / OPERAND2<br />

case "halt"<br />

default<br />

print 1 line with OPERATION thus<br />

******** is not a valid operation.<br />

endselect<br />

loop<br />

The cases may be overlapping, in which case the first matching case will be selected for execution.<br />

For example:<br />

85

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

Saved successfully!

Ooh no, something went wrong!