Re: Parsing/evaluating shortcutting operators

"Bartc" <>
Thu, 15 Jan 2009 18:05:08 GMT

          From comp.compilers

Related articles
Parsing/evaluating shortcutting operators (Jeremy J Starcher) (2009-01-13)
Re: Parsing/evaluating shortcutting operators (Bartc) (2009-01-15)
Re: Parsing/evaluating shortcutting operators (Jeremy J Starcher) (2009-01-17)
| List of all articles for this month |

From: "Bartc" <>
Newsgroups: comp.compilers
Date: Thu, 15 Jan 2009 18:05:08 GMT
Organization: Compilers Central
References: 09-01-032
Keywords: parse, code
Posted-Date: 16 Jan 2009 07:01:12 EST

"Jeremy J Starcher" <> wrote in message

> I am unsure how to proceed in setting up shortcutting operators
> however. For example, this code:
> declare boolean b
> b = (1 == 2) || (3 == 4)
> Which results in the expression
> 1 2 == 3 4 == || b =

You've made me feel inadequate, because my compiler only uses shortcut
evaluation when there are jumps involved (eg. inside an If conditional, but
not in an ordinary expression).

But I found that my (a|b|c) construct (equivalent to C's a?b:c) generates
code like an If statement.

So I can fix this 'problem' by turning 'a and b' into (a and b|1|0), and 'a
or b' into (a or b|1|0), either manually or letting the compile do it as you
seem to be attempting to.

It's possible that you can try something similar, if you also have an
equivalent a?b:c operator that already has short-circuit evaluation.


Post a followup to this message

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