Re: Constant expression evaluation?

Clint Olsen <>
18 May 2003 01:27:13 -0400

          From comp.compilers

Related articles
Constant expression evaluation? (Paul Davis) (2003-05-14)
Re: Constant expression evaluation? (Christian Bau) (2003-05-16)
Re: Constant expression evaluation? (Dierk Ohlerich) (2003-05-16)
Re: Constant expression evaluation? (Clint Olsen) (2003-05-18)
Re: Constant expression evaluation? (Niksa Orlic) (2003-05-29)
Re: Constant expression evaluation? (david lindauer) (2003-05-29)
| List of all articles for this month |

From: Clint Olsen <>
Newsgroups: comp.compilers
Date: 18 May 2003 01:27:13 -0400
Organization: AT&T Broadband
References: 03-05-089
Keywords: optimize, practice
Posted-Date: 18 May 2003 01:27:13 EDT

Paul Davis wrote:
> 1) Add a second expression syntax section in the Bison description for
> constant expressions, which get evaluated during compilation. This sounds
> really kludgey, and I suspect would lead to lots of conflicts.

This is the correct way to do it except you use the same "expression"
rule as before but annotate your parse tree with a constant flag in it
- you make it a semantic check. Otherwise like you said you get
parser conflicts between "constant_expression" and "expression". You
just percolate the constant flag upwards as you continue to parse

If both children are constants, so is the parent, and so on. This
kind of inheritance from the children works for many attributes in
fact. And if you then want to evaluate this expression, you can do it
at the rule that expects a constant expression:

constant_expression : expression
        if ($1->constant) {
                error("constant expression expected\n");

Something that smells like that should work anyway.


Post a followup to this message

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