Status of PEP's?
Greg Ewing
greg at cosc.canterbury.ac.nz
Mon Mar 4 23:13:48 EST 2002
James_Althoff at i2.com wrote:
>
> [David Eppstein]
> >
> > "for" expression ":"
>
> You might want to think this through a bit more since neither arbitrary
> "expression" nor arbitrary "conditional" is supported in the suggestions
> posted so far.
The official Python grammar currently defines a for-loop
thusly:
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
where 'exprlist' is, confusingly, *not* a list of
general expressions, but of expressions not including
comparisons.
So it seems that the following would work:
for_stmt: 'for' (exprlist 'in' testlist
| exprlist lt_op exprlist lt_op exprlist
| exprlist gt_op exprlist gt_op exprlist) ':' suite ['else' ':'
suite]
lt_op: '<' | '<='
gt_op: '>' | '>='
Later phases of the compiler would be responsible for checking
that the exprlists in the new parts actually contain only one
item each, and that the middle one is a variable.
--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list