[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: speed-up parsing
From: |
Anthony DeRobertis |
Subject: |
Re: speed-up parsing |
Date: |
Wed, 19 Jun 2002 13:14:34 -0400 |
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.
Off the top of my head, not even compiled, much less tested or
thought about...
enum operator_t {
operator_constant,
operator_sin,
operator_cos
};
struct UnaryOp {
operator_t op;
union {
double val;
UnaryOp *child;
}
}
double eval_unary_op(UnaryOp *o) {
switch (o->op) {
case operator_constant:
return o->val;
case operator_sin:
return sin(eval_unary_op(o->child));
case operator_cos:
return cos(eval_unary_op(o->child));
default:
assert(!"I can get here.");
}
}
Notice that the above can handle sin(3), cos(3),
sin(cos(sin(3))), etc. The parser just builds the nodes.
HTH.
- Re: speed-up parsing, (continued)
Fwd: Re: speed-up parsing, Christian Kristukat, 2002/06/19
Re: speed-up parsing,
Anthony DeRobertis <=
Re: speed-up parsing, Hans Aberg, 2002/06/19
Re: speed-up parsing, Christian Kristukat, 2002/06/20