grammatica-users
[Top][All Lists]
Advanced

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

Re: [Grammatica-users] Re-using of token lists in with Analyzer class


From: Sonja
Subject: Re: [Grammatica-users] Re-using of token lists in with Analyzer class
Date: Fri, 20 Jul 2007 11:15:57 +0200
User-agent: Thunderbird 1.5.0.12 (Windows/20070509)

Hi and thanks four your reply,

I'll think about your suggestion. Just hoped there would be a more effortless solution...

Klaus

Per Cederberg schrieb:
Hi,

Currently there is no way to analyze a parse tree without
rebuilding it each time. That doesn't seem optimal in your
case, so I'd recommend that you create your own internal
data structure to represent your arithmetic expression in
an efficient way.

The easiest most obvious way would perhaps be to create
an interface something like this:

  public interface Expression {

      /**
       * Returns a list of all used variable names.
       */
      ArrayList getVariables();

      /**
       * Evaluates the expression with the specified
       * variable bindings (name + Double value).
       */
      double eval(HashMap variables);
  }

Then the analyzer should just create appropriate subclass
instances for this interface upon parsing the text string.
For the expression below for instance, you'd create
instances of the following imaginary classes:

  AdditionExpresson(Expression exp1, Expression exp2)
  DivisionExpression(Expression exp1, Expression exp2)
  ConstantExpression(Double value)
  VariableExpression(String name)

Cheers,

/Per

Sonja wrote:
Hi,

is there any way how I can re-use an already parsed file/string?

Eg. I have this string:  (12+y)/3

Now I want to evaluate it with an instance of a class derived from Analyzer.

So far this is no problem (new ArithmeticParser(inputReade, analyzer) ) but now
I want to evaluate it not just ones but about one million times.

My question now is: Do I always have to parse and build an token-list again? Or is there any way to use the previous built token-list again in the Analyzer object?

(I have to evaluate this string so often because I always replace the variables
(y) with different values in the Analyzer class!)

Thanks for any help!

Klaus





_______________________________________________
Grammatica-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/grammatica-users




_______________________________________________
Grammatica-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/grammatica-users





reply via email to

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