Tracing Expressions with the TRACE istruction

You can use the TRACE instruction to show how the language processor evaluates each operation of an expression as it reads it, or to show the final result of an expression. These two types of tracing are useful for debugging programs.

Tracing operations

To trace operations within an expression, use the TRACE I (TRACE Intermediates) form of the TRACE instruction. The language processor breaks down all expressions that follow the instruction and analyzes them as:
>V> -
V
ariable value - The data traced is the contents
of a variable.
>L> -
L
iteral value - The data traced is a literal
(string, uninitialized variable, or constant).
>O> -
O
peration result - The data traced is the result
of an operation on two terms.
The following example uses the TRACE I instruction. (The line numbers are not part of the program. They facilitate the discussion of the example that follows it.)
Figure 1. TRACE Shows How REXX Evaluates an Expression
 1 /************************* REXX
***************************/
2 /* This program uses the TRACE instruction to show how */
3 /* an expression is evaluated, operation by operation. */
4 /**********************************************************/
5 a = 9
6 y = 2
7 TRACE I
8
9 IF a + 1 > 5 * y THEN
10 SAY 'a is big enough.'
11 ELSE NOP /* No operation on the ELSE path */
When you run the example, the SAY instruction produces:
9 *-* IF a + 1 > 5 * y
>V> "9"
>L> "1"
>O> "10"
>L> "5"
>V> "2"
>O> "10"
>O> "0"

The 9 is the line number. The *-* indicates that what follows is the data from the program, IF a + 1 < 5 * y . The remaining lines break down all the expressions.

Tracing results

To trace only the final result of an expression, use the TRACE R (TRACE Results) form of the TRACE instruction. The language processor analyzes all expressions that follow the instruction as follows:
>>> Final result of an expression
If you changed the TRACE instruction operand in the previous example from an I to an R, you would see the following results.
9 *-* IF a + 1 > 5 * y
>>> "0"

In addition to tracing operations and results, the TRACE instruction offers other types of tracing, see TRACE.

Exercises: using the TRACE instruction

Write a program with a complex expression, such as:
IF (a > z) | (c < 2 * d) THEN ....

Define a , z , c , and d in the program and use the TRACE I instruction.

ANSWER
Figure 2. Possible solution
/****************************** REXX
********************************/
/* This program uses the TRACE nstruction to show how the language
*/
* processor evaluates an expression, operation by operation. */
/********************************************************************/
a = 1
z = 2
c = 3
d = 4

TRACE I

IF (a > z) | (c < 2 * d) THEN
SAY 'At least one expression was true.'
ELSE
SAY 'Neither expression was true.'
When you run this program, it produces:
 12 *-* IF (a > z) | (c < 2 * d)
>V> "1"
>V> "2"
>O> "0"
>V> "3"
>L> "2"
>V> "4"
>O> "8"
>O> "1"
>O> "1"
*-* THEN
13 *-* SAY 'At least one expression was true.'
>L> "At least one expression was true."
At least one expression was true.


trace1.html | Timestamp icon Last updated: Monday, 5 June 2017