next up previous contents index
Next: Question files Up: Additional expression evaluators Previous: How to define new   Contents   Index


How to use additional expression evaluators

The command ch_expr is used to change the current expression evaluator.

- interpcom -> ch_expr n

(where n is an integer) will define the n-th expression evaluator as the current one.

The 0-th one is the ordinary one.

The 1-th uses complex numbers. In this case the variable I contains $\sqrt{-1}$. For instance

- interpcom -> A=2-3*I

defines the variable A containing the complex number $2-3i$.

The next expression evaluators are the supplementary ones.

The command varlist, used to give the list of all the variables of the usual expression evaluator, can also be used to see the variables of all the other ones:

- interpcom -> varlist n

gives the list of all the variables of the n-th expression evaluator, and

- interpcom -> varlist all

gives the list of all the variables of all the expression evaluators.


It is possible to use the variables of new expression evaluators in loops, when the sign of the corresponding numbers has a meaning. For example, in the following program

ch_expr 1
x=4+3*I
do i 1 10
x=x+1+I
enddo
ch_expr 0

the variable $i$ in the loop is a complex number. It is possible to let the loop use ordinary variables by using ch_expr inside the loop :

ch_expr 1
x=4+3*I
ch_expr 0
do i 1 10
ch_expr 1
x=x+1+I
ch_expr 0
enddo

In this case it is still possible to use the variable of the loop inside expressions parsed by other expression evaluators. For example

ch_expr 1
x=1
ch_expr 0
do i 1 10
ch_expr 1
x=x*!(i)
ch_expr 0
enddo

(cf. 4.5).


We show now how to call directly a new expression evaluator. This can be useful for instance if one wants to parse the arguments of a new command that needs a different kind of numbers. For this the function

int  Evaluate_Gen(int n, char *e, void **res, int *a, flow_data *flow_interp);

is used. Here n is the number of the supplementary expression evaluator (0 for the first), e contains the string that must be evaluated, result[0] will be the address of the result, and flow_interp is the address of the flow_data structure corresponding to the thread from which the function is called. For example

    void    *result;
    int      dum;

    result = NULL;
    Evaluate_Gen(n, "x=2", &result, &dum, flow_interp);
        /* Makes "x=2" in the additional expression evaluator n */

    if (result != NULL) {
        ... 
        Expreval_ops[n].clear(result); 
           /* frees the memory occupied by the result */
    }

Note that in this example, the expression evaluator used in the thread is
flow_interp->expr_ev, corresponding to n = flow_interp->expr_ev - 2). But it is possible to use a different n.


next up previous contents index
Next: Question files Up: Additional expression evaluators Previous: How to define new   Contents   Index
2009-11-12