0.9b (c) 1995 Peter Childs
>>----INTERPRET----expression----;--------------><
INTERPRET is used to process instructions that have been built dynamically by evaluating expression.
The expression is evaluated, and is then processed (interpreted) as though the resulting string was a line inserted into the input file (and bracketed by a DO; and an END;).
Any instructions (including INTERPRET instructions) are allowed, but note that constructions such as DO ... END and SELECT ... END must be complete. For example, a string of instructions being interpreted cannot contain a LEAVE or ITERATE instruction (valid only within a repetitive DO loop) unless it also contains the whole repetitive DO ... END construct.
A semicolon is implied at the end of the expression during processing, as a service to the user.
Example:
data='FRED' interpret data '= 4' /* Will a) build the string "FRED = 4" */ /* b) execute FRED = 4; */ /* Thus the variable "FRED" will be set to "4" */
Example:
data='do 3; say "Hello there!"; end' interpret data /* Would display: */ /* Hello there! */ /* Hello there! */ /* Hello there! */
Notes:
1. Labels within the interpreted string are not permanent and are therefore ignored. Therefore, executing a SIGNAL instruction from within an interpreted string causes immediate exit from that string before the label search begins.
2. If you are new to the concept of the INTERPRET instruction and are getting results that you do not understand, you might find that executing the instruction with TRACE R or TRACE I set is helpful.
Example:
/* Here we have a small program. */ Trace Int name='Kitty' indirect='name' interpret 'say "Hello"' indirect'"!"'
when run, the following trace is displayed:
[C:\]kitty kitty 3 *-* name='Kitty' >L> "Kitty" 4 *-* indirect='name' >L> "name" 5 *-* interpret 'say "Hello"' indirect'"!"' >L> "say "Hello"" >V> "name" >O> "say "Hello" name" >L> ""!"" >O> "say "Hello" name"!"" *-* say "Hello" name"!" >L> "Hello" >V> "Kitty" >O> "Hello Kitty" >L> "!" >O> "Hello Kitty!" Hello Kitty! [C:\]
Lines 3 and 4 set the variables used in line 5. Execution of line 5 then proceeds in two stages. First the string to be interpreted is built up, using a literal string, a variable (INDIRECT), and another literal. The resulting pure character string is then interpreted, as though it were actually part of the original program. Since it is a new clause, it is traced as such (the second *-* trace flag under line 5) and is then executed. Again a literal string is concatenated to the value of a variable (NAME) and another literal, and the final result is then displayed as follows:
Hello Kitty!
3. For many purposes, the VALUE function can be used instead of the INTERPRET instruction. Line 5 in the last example could therefore have been replaced by:
say "Hello" value(indirect)"!"
INTERPRET is usually only required in special cases, such as when more than one statement is to be interpreted at once.
Inf-HTML End Run - Successful