> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: 13 March 2003 19:33
> To: Ford, Mike [LSS]
> Cc: 'Andrey Hristov'; [EMAIL PROTECTED]
> Subject: RE: [PHP-DEV] Possible problem in the parser
> 
> 
> At 14:58 13.03.2003, Ford, Mike               [LSS] wrote:
> 
> >Just to make this completely clear, in left-associative PHP
> >
> >    b = a==1? 4:a==2? 5:6;
> >
> >is equivalent to
> >
> >    b = (a==1? 4:a==2)? 5:6;
> 
> 
> NO it is not equal. Either '==' has higher precedence OR '?:' has.
> See one of my previous mails where i showed where the error is.

Yes, it is -- believe me, I've researched this extensively.  It is NOT about 
precedence, but associativity.  If you want me to be totally completist about this:

Starting from:

   b = a==1? 4:a==2? 5:6;

precedence rules make this equivalent to:

   b = (a==1)? 4:(a==2)? 5:6;

but this is still ambiguous -- which ?: phrase do you evaluate first?  Associativity 
provides the answer: in PHP, where ?: is left associative (i.e. the left most ?: is 
evaluated first), the result is equivalent to:

   b = ((a==1)? 4:(a==2))? 5:6;

On the other hand, in c, where ?: is right associative, the equivalent is:

   b = (a==1)? 4:((a==2)? 5:6);

which, apart from the additional (unnecessary) parentheses around the == comparisons, 
is exactly what I said before.

QED

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to