From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: pass C source to program binary? Date: 18 Sep 2000 13:13:53 GMT Organization: Aachen University of Technology (RWTH) Lines: 34 Message-ID: <8q54eh$lkn$1@nets3.rz.RWTH-Aachen.DE> References: <200009151433 DOT JAA00227 AT darwin DOT sfbr DOT org> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 969282833 22167 137.226.32.75 (18 Sep 2000 13:13:53 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 18 Sep 2000 13:13:53 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Jeff Williams 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.