[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: speed-up parsing

From: Hans Aberg
Subject: Re: speed-up parsing
Date: Wed, 19 Jun 2002 19:42:14 +0200

At 18:26 +0200 2002/06/19, Christian Kristukat wrote:
>Well, let's forget the least-squares thing... I may have a basic
>problem. So my question is: is it possible to evaluate an already parsed
>expression once again without having to call yparse() and if yes, how do I do
>it. E.g. you have a parse string "sin(x)" and you want to evaluate it at many
>different x.

There is nothing in the Bison parser program that prevents you from
evaluating in many times. :-)

But that is not what people would do: One would create a closure, some
binary code, or whatever you want to call it, which knows how to remember
"sin" and how to feed an "x" to it. Then one does that multiple times.

Otherwise, if you really want to parse it several times, just make a lookup
table (in C++, you can use say std::map) which stores all the relevant
names and their values. When your lexer (generated say by using Flex)
encounters a name, it consults the lookup table to see the type and value
and returns that to the parser.

With this strategy, it is easy to fill the lookup table with some
predefined names like "sin" and pointers to appropriate C/C++ functions.

  Hans Aberg

reply via email to

[Prev in Thread] Current Thread [Next in Thread]