[Python-ideas] a in x or in y

Nick Coghlan ncoghlan at gmail.com
Thu Feb 13 14:51:41 CET 2014


On 13 Feb 2014 23:30, "Boris Borcic" <bborcic at gmail.com> wrote:
>
> Nick Coghlan wrote:
>
>> On 13 February 2014 20:57, Steven D'Aprano <steve-iDnA/YwAAsAk+I/
owrrOrA at public.gmane.org> wrote:
>>>
>>> - given the restrictions on the parser, is this even possible? and
>>
>>
>> I haven't worked through an actual candidate grammar (so I could
>> potentially be wrong) but I'm pretty sure it requires more lookahead
>> than Guido is willing to allow for the language definition.
>>
>> At the point we hit:
>>
>>      X in Y and
>>
>> we're going to want to process "X in Y" as an expression, and then
>> start looking at compiling the RHS of the "and".
>>
>> This proposal would mean that when the "in" shows up after the "and",
>> we need to backtrack, lift "X" out as its own expression, and then
>> reinsert it as the LHS of *multiple* containment tests.
>>
>> It's worth noting that this deliberate "no more than one token
>> lookahead" design constraint in the language syntax isn't just for the
>> benefit of compiler writers: it's there for the benefit of human
>> readers as well.
>>
>> In linguistics, there's a concept called "garden path" sentences -
>> these are sentences where the first part is a grammatically coherent
>> sentence, but by *adding more words to the end*, you change the
>> meaning of words that appeared earlier.
>
>
> Are you trying to say "X in Y and" forms a complete expression?? And
couldn't the lexer recognize "and in" and cognates as single tokens anyway,
like it apparently does presently for "is not" ?

Yes, there are ways around the technical limitation - the point of the rest
of the post was to make it clear that was largely irrelevant, because it
would still be too hard to read.

Cheers,
Nick.

>
>
> ---
> Ce courrier électronique ne contient aucun virus ou logiciel malveillant
parce que la protection avast! Antivirus est active.
> http://www.avast.com
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140213/9cbe79d5/attachment.html>


More information about the Python-ideas mailing list