Re: Parsing/evaluating shortcutting operators

Jeremy J Starcher <r3jjs@yahoo.com>
Sat, 17 Jan 2009 19:39:56 GMT

          From comp.compilers

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

From: Jeremy J Starcher <r3jjs@yahoo.com>
Newsgroups: comp.compilers
Date: Sat, 17 Jan 2009 19:39:56 GMT
Organization: at&t http://my.att.net/
References: 09-01-032 09-01-035
Keywords: code
Posted-Date: 18 Jan 2009 08:06:34 EST

On Thu, 15 Jan 2009 18:05:08 +0000, Bartc wrote:
> "Jeremy J Starcher" <r3jjs@yahoo.com> 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).


Hey.. don't feel that way. You are a step over where I am.


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


Interesting idea .... Hmmmm... Room to think. Thank you.


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


And here I was, going to make the trinary operator work via the
shortcutting operators ;) Chicken-and-egg.


To get it, I think I'm going to have to come up with a different equation
parser, and split the calculations into 'sub-expressions'. Not that I'm
ever going to add optimization, but it would also 'common-subexpression'
elimination, as well as folding constants.



Post a followup to this message

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