On Tue, Nov 8, 2016 at 12:34 PM Fleshgrinder <p...@fleshgrinder.com> wrote:

> This requires associativity, as Python has it.
>
> https://docs.python.org/3/reference/expressions.html#comparisons
>
> The problem, as explained in the Python reference, is that in `x < y <
> z` the variables `x` and `z` are never compared against each other.
> This, however, works great almost always and nothing is wrong in doing
> so in my opinion.
>
> That change would actually be brutally easy since we only need to change
> the `%nonassoc` to `%left` and we are done.
>
> https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L73


I don't think that alone allows the chaining of comparisons.  I'd have to
look closer, but it'd seem to me that zend_ast_create_binary_op
(ZEND_AST_BINARY_OP) evaluation might need to be amended as well.  Seems it
eventually calls a `op(zval*,zval*,zval*) so the evaluated end of: one op
would be a true/false, when comparing against another boolean op.

Regardless of implementation, the core question you raised was should
something like it exist, I'm still a strong yes on that front.  I'd just
promote introducing the left precedence and allowing the arbitrary chains
of comparison, rather than just a single interval comparison.

cheers
--
Dave

Reply via email to