[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question regarding short-circuited operators.
From: |
Hans Aberg |
Subject: |
Re: Question regarding short-circuited operators. |
Date: |
Tue, 26 Feb 2002 13:20:54 +0100 |
At 17:07 -0800 2002/02/25, Eric Poulsen wrote:
>I'm creating an expression parser that supports variables. Consider
>this expression:
>
>x = 5 || y = 3
>
>After evaluating this simple statement, variable 'x' should be 5, and
>variable 'y' should be undefined, if you take into account
>short-circuiting of logical operators the way C, and several other
>languages implement this.
This sounds like a question more suitable to the comp.compilers newsgroup,
on how to implement various compiler features.
In your example, under C, the compiler can optimize, if you so want,
finding that x = 5 and y = 3 at compile time. If you have an expression
x = a || y = b
then the compiler can figure out that x = a, but not that what y is, so one
has to build some kind of closure (runtime code executed later) for that.
Hans Aberg