|Equation compiler? firstname.lastname@example.org (Alan GARNY) (1999-10-27)|
|Re: Equation compiler? Sid-Ahmed-Ali.TOUATI@inria.fr (Sid Ahmed Ali TOUATI) (1999-10-29)|
|Re: Equation compiler? email@example.com (Quinn Tyler Jackson) (1999-10-29)|
|Re: Equation compiler? firstname.lastname@example.org (Zalman Stern) (1999-10-31)|
|Re: Equation compiler? email@example.com (1999-11-02)|
|Re: Equation compiler? firstname.lastname@example.org (1999-11-03)|
|Re: Equation compiler? email@example.com (1999-11-20)|
|From:||Zalman Stern <firstname.lastname@example.org>|
|Date:||31 Oct 1999 01:27:26 -0400|
Alan GARNY <email@example.com> wrote:
: Does anyone know how to create an equation compiler in C/C++? The idea
: is, for instance, to allow the user to enter an equation, such as y =
: 3x+2, and compile (in assembly language for faster computation?) it
: and use it to plot the corresponding graph.
The meat of an answer to this question depends a lot on the possible
target environments and ultimate "packaging" of your program. If it is
a one off project for a single machine, you might consider writing a
simple equation compiler that outputs assembly. Ditto if its a
commercial application and you have time and effort to throw at it, it
might be worth doing your own minicompiler.
Otherwise, if the platform is guaranteed to have a C compiler and has
suitable dynamic loading, and you can afford a second or two to
compile the equation, a good bet is to spit out some C code, compile
it, dynamically load it and call it. If you are more Java inclined and
have a decent JIT Java compiler in your environment, you can do the
same thing with Java. (Either generating a .class file directly or
generating Java and compiling it.) The call from C++ can be done using
Java Native Interface.
Similar things can be done with languages other than Java (e.g. Scheme).
Writing your own compiler to assembly language can be pretty
easy. E.g. you can use a simple stack machine model where each
operator pretty much just appends code to a list of instructions. It
will not produce optimal code, but it will be much faster than
Return to the
Search the comp.compilers archives again.