handling 0 < x < 5

Chris Ryland <[email protected]> Mon, 29 Mar 2004 13:29:30 -0500
Newsgroups gmane.comp.lang.prothon.devel
Message-ID <[email protected]>
> Ben: I have a challenge for you.  Put in on your to-do list.  It is in 
> the
> main to-do list as "a < b < c".
>
> Python has a cool feature where comparisons can be chained in a human
> readable way like 0 < x < 5.  This would be true if x was between 0 
> and 5.
> Right now Prothon (and every other language) would parse this as (0 < 
> x) < 5
> which would try to compare the boolean on the left with the integer 5.
>
> I didn't implement it because I couldn't figure out how to get Bison to
> parse this.  You are better with Bison than I am so take a stab at it
> sometime.

I doubt if this is handled by the parser in Python--rather, the 
compiler probably looks at a given comparison binary operator to see if 
one or more of its children are other comparison ops, and compiles the 
appropriate chained comparisons. Just a thought.

Cheers!
--Chris Ryland / Em Software, Inc. / www.emsoftware.com