Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'position,': 0.04; 'operand': 0.07; 'subject: + ': 0.07; '"+"': 0.09; '0))': 0.09; 'atom': 0.09; 'identifier': 0.09; 'literal': 0.09; 'parsed': 0.09; 'bug': 0.10; 'python': 0.10; 'subject:not': 0.11; 'syntax': 0.13; '"%"': 0.16; '"*"': 0.16; '"-"': 0.16; '"/"': 0.16; '"//"': 0.16; '"and"': 0.16; '"not"': 0.16; '"or"': 0.16; '"~"': 0.16; '::=': 0.16; '>>on': 0.16; '["**"': 0.16; 'a_expr': 0.16; 'and_test': 0.16; 'attributeref': 0.16; 'dict_display': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'list_display': 0.16; 'm_expr': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'not_test': 0.16; 'or_test': 0.16; 'received:192.168.1.4': 0.16; 'syntaxerror:': 0.16; 'u_expr': 0.16; 'unary': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'stefan': 0.18; '>>>': 0.20; '(not': 0.20; '"",': 0.22; 'permitted': 0.22; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'example': 0.26; 'looks': 0.29; 'comparison': 0.29; 'primary': 0.31; 'ram': 0.33; 'file': 0.34; 'so,': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'wrong': 0.38; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'high': 0.60; 'skip:\xc2 10': 0.67; 'power': 0.72; 'as:': 0.79; "op's": 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=JOrGyJ+b c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=AGkejYDSTmIA:10 a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=k1eVPsZQAejob43jsPgA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 Date: Sat, 11 Jul 2015 17:20:58 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: 0 + not 0 References: <01ec6551-1f40-42b0-9406-036030591519@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436631668 news.xs4all.nl 2958 [2001:888:2000:d::a6]:59172 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93693 On 2015-07-11 17:02, Stefan Ram wrote: > Serhiy Storchaka writes: >>On 11.07.15 13:26, candide wrote: >>>>>> 0 + not 0 >>> File "", 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))