Mail Archives: djgpp/2000/09/18/09:19:36
Jeff Williams <jeffw AT darwin DOT sfbr DOT org> wrote:
>> >Is there a obvious technique for passing the source code for a small C
>> >function (e.g., `for (i=1;i<=N;i++) y[i]=foo(x[i]);'), which might be in
>> >a file or passed via command-line, to an already-compiled C program and
>> >have that program be able to interpret and use the function internally?
> -: Write an interpreter for a C-Like Language.
> Is this the way gnuplot (for example) `reads' functions for plotting?
Essentially yes. We use a hand-written parser that translates C-like
notation into a 'stack machine' (like an RPN calculator from HP) which
is then executed by a huge bunch of functions like this (simplified
actual function from the gnuplot source):
void f_plus()
{
struct value a, b, result;
(void) pop(&b);
(void) pop(&a);
(void) Ginteger(&result, a.v.int_val + b.v.int_val);
push(&result);
}
Each expression is represented by a list of function pointers, essentially.
One each for every operator in the expression.
One of the future plans for gnuplot development is to isolate this
functionality so you can integrate it into other programs, without too
much hassle --- or rip it out and replace it by another one for use
inside gnuplot, on the other hand.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -