Wondering about circular definitions in Python Language Reference?
September 2, 2016 by omiday ['ɔ:mi:deı]If you have been reading the Python Tutorial and did follow the various references to Python Language Reference all the way you likely ended up with something along these lines:
-
enclosure ::= parenth_form | list_display | dict_display | set_display | generator_expression | yield_atom
-
parenth_form ::= "(" [starred_expression] ")"
-
starred_expression ::= expression | ( starred_item "," )* [starred_item]
-
starred_item ::= expression | "*" or_expr
-
expression ::= conditional_expression | lambda_expr
-
conditional_expression ::= or_test ["if" or_test "else" expression]
contitional_expression ::= expression (6) expression ::= conditional_expression (5)
-
or_test ::= and_test | or_test "or" and_test
-
and_test ::= not_test | and_test "and" not_test
-
not_test ::= comparison | "not" not_test
-
comparison ::= or_expr ( comp_operator or_expr )*
-
or_expr ::= xor_expr | or_expr "|" xor_expr
-
xor_expr ::= and_expr | xor_expr "^" and_expr
-
and_expr ::= shift_expr | and_expr "&" shift_expr
-
shift_expr ::= a_expr | shift_expr ( "<<" | ">>" ) a_expr
-
a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr
-
m_expr ::= u_expr | m_expr "*" u_expr | m_expr "@" m_expr | m_expr "//" u_expr| m_expr "/" u_expr | m_expr "%" u_expr
-
u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr
-
power ::= ( await_expr | primary ) ["**" u_expr]
-
await_expr ::= "await" primary
-
primary ::= atom | attributeref | subscription | slicing | call
atom:
atom ::= identifier | literal | enclosure
-
enclosure ::= parenth_form | list_display | dict_display | set_display | generator_expression | yield_atom
And we are back from where we started!
But fear not, there are other similar circular definitions.