help-bison
[Top][All Lists]
Advanced

[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.




reply via email to

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