|Fastening the run-time interpretation of mathematical expressions email@example.com (PAolo) (2006-11-11)|
|Re: Fastening the run-time interpretation of mathematical expressions firstname.lastname@example.org (2006-11-11)|
|Re: Fastening the run-time interpretation of mathematical expressions email@example.com (Dmitry A. Kazakov) (2006-11-13)|
|Re: Fastening the run-time interpretation of mathematical expressions firstname.lastname@example.org (Andreas Kochenburger) (2006-11-13)|
|Re: Fastening the run-time interpretation of mathematical expressions email@example.com (Martin Ward) (2006-11-13)|
|Re: Fastening the run-time interpretation of mathematical expressions firstname.lastname@example.org (Tommy Thorn) (2006-11-13)|
|Re: Fastening the run-time interpretation of mathematical expressions email@example.com (Karsten Nyblad) (2006-11-15)|
|Re: Fastening the run-time interpretation of mathematical expressions firstname.lastname@example.org (Martin Ward) (2006-11-15)|
|[3 later articles]|
|From:||email@example.com (Hans Aberg)|
|Date:||11 Nov 2006 21:30:49 -0500|
|Posted-Date:||11 Nov 2006 21:30:49 EST|
"PAolo" <firstname.lastname@example.org> wrote:
> I am writing a piece of software that accept in input the definition
> of a mathematical function and a list of points in which evaluate the
> function and puts the result in output. The main feature of the progam
> is that once the function definition is read, the program evaluates
> the function very fast [Well this isn't done already...]. I was
> thinking to build a pair of stacks, one containig the operands
> (floats) and the other containig the operators (function pointers).
This is typically used when the user is allowed to define operators
with a large number of precedence levels. One can then integrate it in
an otherwise static grammar. I once write it, but I do not immediately
recall if I used one or two stacks. The trick is to the operator
precedence. Add an end marker # to the expression; when it appears,
the rest of the stacks are computed. Try a two value/operator stack
approach on "a + b * c #". First push 'a', '+', 'b'. When the '*'
appears, check the operator stack, to see that it is a '+' with lower
precedence on top; so then '*' and 'c' should be pushed. Then '#'
appears, saying that all stuff on the stacks should be computed, first
b * c, which is put back on the value stack, and then '+' is applied
When you know how to compute the expression, converting it to other
formats, such as the Australian notation
<http://en.wikipedia.org/wiki/Reverse_Polish_notation>, is easy.
Return to the
Search the comp.compilers archives again.