parse-time optimizations

jcm grumble at usa.net
Wed May 30 09:46:14 EDT 2001


Tim Peters <tim.one at home.com> wrote:
> [Greg Ewing]
>> You would have to be careful how you implemented
>> this, because
>>
>>   x + "foo" + "blarg"
>>
>> could have very different results from
>>
>>   x + "fooblarg"
>>
>> depending on what sort of thing x is bound to.

> Ditto
>     x + 1 + 2
> vs
>     x + 3

Sure.  'x + 1 + 2' parses into:

     +
   +   2
  x 1

so the parser would never see the [false] opportunity to merge 1 and
2.  I'm not talking about some fancy analysis of the parse tree, just
something like constant-folding.



More information about the Python-list mailing list