Message123188
On Thu, Dec 2, 2010 at 11:49 PM, Éric Araujo <report@bugs.python.org> wrote:
..
> Whether 1+2j is a literal or an expression is debatable.
> I think +1 is an expression but 1+2j is a literal; neither should have a space.
With respect to implementation there is no debate:
[TokenInfo(type=57 (ENCODING), string='utf-8', start=(0, 0), end=(0,
0), line=''),
TokenInfo(type=2 (NUMBER), string='1', start=(1, 0), end=(1, 1), line='1+1j'),
TokenInfo(type=53 (OP), string='+', start=(1, 1), end=(1, 2), line='1+1j'),
TokenInfo(type=2 (NUMBER), string='1j', start=(1, 2), end=(1, 4), line='1+1j'),
TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='')]
[TokenInfo(type=57 (ENCODING), string='utf-8', start=(0, 0), end=(0,
0), line=''),
TokenInfo(type=53 (OP), string='-', start=(1, 0), end=(1, 1), line='-1'),
TokenInfo(type=2 (NUMBER), string='1', start=(1, 1), end=(1, 2), line='-1'),
TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='')]
(Who designed the tokenize interface, btw? I took me 3 tries to come
up with the incantation above.)
>
> I’m not sure the language reference and the actual implementation are in agreement here
> (I have peephole optimizations in mind).
Literals are atomic to the tokenizer. AST processes a stream of
tokens. Peephole optimizations are irrelevant because these are hacks
that operate on the bytecode when the lexical structure is all but
forgotten. |
|
Date |
User |
Action |
Args |
2010-12-03 05:34:03 | belopolsky | set | recipients:
+ belopolsky, lemburg, georg.brandl, rhettinger, mark.dickinson, pitrou, eric.araujo, Retro, michael.foord, brian.curtin |
2010-12-03 05:34:00 | belopolsky | link | issue10562 messages |
2010-12-03 05:34:00 | belopolsky | create | |
|