I was going through the python assignment statement docs .
Here python uses below Backus–Naur form for assignment statements.
assignment_stmt ::= (target_list "=")+ (starred_expression | yield_expression)
target_list ::= target ("," target)* [","]
target ::= identifier
| "(" [target_list] ")"
| "[" [target_list] "]"
| attributeref
| subscription
| slicing
| "*" target
Where as starred_expression is in Backus-Naur Form is
starred_expression ::= expression | (starred_item ",")* [starred_item]
starred_item ::= assignment_expression | "*" or_expr
and yield_expression in Backus-Naur Form is
yield_atom ::= "(" yield_expression ")"
yield_expression ::= "yield" [expression_list | "from" expression]
After recursively going through all those related backnaur form of each sub expression given above. I am still scratching my head how does simple assignment like a=9 can fit into above back naur form. Specially how does the 9, on the RHS of the given statement can fall into yield_expression or starred_exression
Isn't it right here?
A
starred_expressioncan be just anexpression. It must be the case thatexpressionencompasses numeric literals like9.(Edited for clarity following comments.)
UPDATE
Here is the full line from
starred_expressionto9.What makes it confusing is that for every element from
conditional_expressiondown topower, the thing that makes it look like the "thing it is" is optional!For instance, in
power, the**operator is actually not even required. So we think of2**16as apower, but2also qualifies as apower. Similarly foror_test, anorkeyword is not actually required.It works like that all the way up. For every line,
9satisfies the simplest version of the syntactic element with none of the optional parts included.