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:

  1. enclosure:

    enclosure ::=  parenth_form | list_display | dict_display | set_display
                   | generator_expression | yield_atom
    
  2. parenth_form:

    parenth_form ::=  "(" [starred_expression] ")"
    
  3. starred_expression:

    starred_expression ::=  expression | ( starred_item "," )* [starred_item]
    
  4. starred_item:

    starred_item       ::=  expression | "*" or_expr
    
  5. expression:

    expression             ::=  conditional_expression | lambda_expr
    
  6. conditional_expression:

    conditional_expression ::=  or_test ["if" or_test "else" expression]
    

    circular definition:

    contitional_expression ::= expression (6)
    expression ::= conditional_expression (5)
    
  7. or_test:

    or_test  ::=  and_test | or_test "or" and_test
    
  8. and_test:

    and_test ::=  not_test | and_test "and" not_test
    
  9. not_test:

    not_test ::=  comparison | "not" not_test
    
  10. comparison:

    comparison    ::=  or_expr ( comp_operator or_expr )*
    
  11. or_expr:

    or_expr  ::=  xor_expr | or_expr "|" xor_expr
    
  12. xor_expr:

    xor_expr ::=  and_expr | xor_expr "^" and_expr
    
  13. and_expr:

    and_expr ::=  shift_expr | and_expr "&" shift_expr
    
  14. shift_expr:

    shift_expr ::=  a_expr | shift_expr ( "<<" | ">>" ) a_expr
    
  15. a_expr:

    a_expr ::=  m_expr | a_expr "+" m_expr | a_expr "-" m_expr
    
  16. 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
    
  17. u_expr:

    u_expr ::=  power | "-" u_expr | "+" u_expr | "~" u_expr
    
  18. power:

    power ::=  ( await_expr | primary ) ["**" u_expr]
    
  19. await_expr:

    await_expr ::=  "await" primary
    
  20. primary:

    primary ::=  atom | attributeref | subscription | slicing | call
    
  21. atom:

    atom      ::=  identifier | literal | enclosure
    
  22. 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.


Hosted on 
    GitHub