Grammar python: incorrect definition of an atom?

Checking python grammar for official documentation is what it reads

atom_expr: ['await'] atom trailer*
atom: ('(' [yield_expr|testlist_comp] ')' |
       '[' [testlist_comp] ']' |
       '{' [dictorsetmaker] '}' |
       NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME

It 10.bit_length()is then valid syntax according to this definition, but not according to the python interpreter. Instead, it n=10;n.bit_length()is a valid syntax for both specifications and the interpreter.

Where can I find a real definition atomand atom_expr?

+4
source share
1 answer

Thanks to juanpa's comment and the answers in the corresponding question, the problem seems to come from 10.. The definition of NUMBER includes a point such that it 10.bit_length()has the form NUMBER NAME trailer, and not NUMBER '.' NAME trailer.

atom_expr, : 10 .bit_length(), (10).bit_length() .

+2

Source: https://habr.com/ru/post/1693974/


All Articles