Re: Equation compiler?

Zalman Stern <zalman@netcom9.netcom.com>
31 Oct 1999 01:27:26 -0400

          From comp.compilers

Related articles
Equation compiler? alan.garny@physiol.ox.ac.uk (Alan GARNY) (1999-10-27)
Re: Equation compiler? Sid-Ahmed-Ali.TOUATI@inria.fr (Sid Ahmed Ali TOUATI) (1999-10-29)
Re: Equation compiler? qjackson@wave.home.com (Quinn Tyler Jackson) (1999-10-29)
Re: Equation compiler? zalman@netcom9.netcom.com (Zalman Stern) (1999-10-31)
Re: Equation compiler? etechweb@yahoo.com (1999-11-02)
Re: Equation compiler? nr@wally.eecs.harvard.edu (1999-11-03)
Re: Equation compiler? niemannt@my-deja.com (1999-11-20)
| List of all articles for this month |
From: Zalman Stern <zalman@netcom9.netcom.com>
Newsgroups: comp.compilers
Date: 31 Oct 1999 01:27:26 -0400
Organization: MindSpring Enterprises
References: 99-10-113
Keywords: practice

Alan GARNY <alan.garny@physiol.ox.ac.uk> 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
interpretation.


-Z-


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.