a = b = 1 just syntactic sugar?
Ed Avis
ed at membled.com
Mon Jun 9 02:43:50 EDT 2003
More information about the Python-list mailing list
Mon Jun 9 02:43:50 EDT 2003
- Previous message (by thread): a = b = 1 just syntactic sugar?
- Next message (by thread): a = b = 1 just syntactic sugar?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) writes: >>>That doesn't answer my question. What would be the output of this >>>statement? >> >>It is syntactically ambiguous because of the two print statements both >>accepting commas. > >This still doesn't answer my question "What would be the output?", What I meant was, I imagine the output would be the same as the output of the statement print ,))( that is, a syntax error. >I assume you want it to cause a SyntaxError. > >Then the question is what algorithm exactly do you apply to detect an >ambiguity? Yes - I don't know enough about parser generators to tell what they do in the case of an ambiguity. Would it find a syntax error or would it pick one of the two alternatives based on which production occurs earlier in the grammar definition? >No, it is rejected because nobody has made a specification, yet, as >to how exactly it should work. Only if a precise, detailed, complete, >and implementable specification is made, it can be studied for >undesired effects, and possibly be rejected. OK. My one-line grammar change and proposed semantics is not a precise specification because I am not well-aquainted with the parser generator Python uses and so I can't explain how it would affect the language in corner cases, such as the ambiguous statement you mentioned. Are there already legal Python constructs that match two or more grammar rules? >>Elsewhere in this thread I have mentioned >> >> lambda_form ::= >> "lambda" [parameter_list]: simple_stmt >> >>which seems to match the specification of 'any statement that can fit >>on one line' (which itself seems pretty exact to me). > >Elsewhere in the thread I have said that this interpretation is >incorrect: a simple_stmt always ends with a NEWLINE, something which >you apparently don't want. And yet elsewhere I have replied citing the definition of simple_stmt from <http://python.org/doc/current/ref/grammar.txt>, which seems to show that simple_stmt does not end with a NEWLINE. >It's counter-intuitive that > >x = (lambda s: print s) > >is incorrect. Under your proposal, it would be incorrect, and you >would have to write > >x = (lambda s: print s >) > >to insert the necessary NEWLINE. No, please look at the grammar <http://python.org/doc/current/ref/grammar.txt> and see that there is no NEWLINE in simple_stmt. Or if there is, point it out because I must have overlooked it. -- Ed Avis <ed at membled.com>
- Previous message (by thread): a = b = 1 just syntactic sugar?
- Next message (by thread): a = b = 1 just syntactic sugar?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list