Short Circuit Evaluation in Bison Interpreter

"Randall Hyde" <rhyde@shoe-size.com>
31 May 2000 23:07:48 -0400

          From comp.compilers

Related articles
Short Circuit Evaluation in Bison Interpreter rhyde@shoe-size.com (Randall Hyde) (2000-05-31)
| List of all articles for this month |
From: "Randall Hyde" <rhyde@shoe-size.com>
Newsgroups: comp.compilers
Date: 31 May 2000 23:07:48 -0400
Organization: Compilers Central
Keywords: interpreter, question

I've written an expression interpreter with Bison.
It has the text book implementation with productions
like


        ConstExpr '&' ConstExpr
        {
                << Semantic actions to logically AND the
                                two expressions above >>
        }


Of course, this scheme does a full boolean evaluation of the
expression. However, I need to ensure that the right ConstExpr item
doesn't produce any side-effects if the left ConstExpr item evaluates
false. Is there an *easy* way to do this in Bison, or am I stuck with
passing lots of attribute information around in my expression parser
and dealing with that in the semantic actions? (This latter solution
would be a real bummer since my interpreter is already written and
would require substantial change.)


Randy Hyde
[You can probably do it with a band-aid, make the '&' into a rule that
checks the top value on the expression stack and sets a "don't really
evaluate flag" if it's non-zero. -John]









Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.