On 2015-07-11 17:02, Stefan Ram wrote:
Serhiy Storchaka <storch...@gmail.com> writes:
On 11.07.15 13:26, candide wrote:
0 + not 0
File "<stdin>", line 1
0 + not 0
^
SyntaxError: invalid syntax
What is syntactically wrong with 0 + not 0?
This looks as a bug to me. Please file a report
I look at Python 3.4.3:
a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr
So, »not 0« must be an »m_expr« when used as the right operand of »+«.
m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr | m_expr
"%" u_expr
u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr
power ::= primary ["**" u_expr]
primary ::= atom | attributeref | subscription | slicing | call
atom ::= identifier | literal | enclosure
enclosure ::= parenth_form | list_display | dict_display | set_display |
generator_expression | yield_atom
How can there be a »not«?
»not« is used in
not_test ::= comparison | "not" not_test
and_test ::= not_test | and_test "and" not_test
or_test ::= and_test | or_test "or" and_test
conditional_expression ::= or_test ["if" or_test "else" expression]
expression_nocond ::= or_test | lambda_expr_nocond
expression ::= conditional_expression | lambda_expr
, but an »expression« is not an »m_expr«.
If "not" had the high priority of unary "-", then:
not a < b
would be parsed as:
(not a) < b
If you extended the OP's example to:
0 + not 0 + 0
and permitted "not" in that position, it wouldn't be parsed as:
0 + (not 0) + 0
but as:
0 + (not (0 + 0))
--
https://mail.python.org/mailman/listinfo/python-list