1- # Grammar for Python, version 7
1+ # Grammar for Python, version 8
2+
3+ # Changes since version 7:
4+ # New syntax to specify base classes (but old syntax retained for now)
5+ # 'global' statement (valid only in functions but not enforced here)
26
37# Changes since version 6:
48# Add logical operators '|', '^', '&' and '~'
@@ -52,7 +56,7 @@ fpdef: NAME | '(' fplist ')'
5256
5357stmt: simple_stmt | compound_stmt
5458simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
55- small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt
59+ small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt
5660expr_stmt: (exprlist '=')* exprlist
5761# For assignments, additional restrictions enforced by the interpreter
5862print_stmt: 'print' (test ',')* [test]
@@ -64,6 +68,7 @@ continue_stmt: 'continue'
6468return_stmt: 'return' [testlist]
6569raise_stmt: 'raise' test [',' test]
6670import_stmt: 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*)
71+ global_stmt: 'global' NAME (',' NAME)*
6772compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
6873if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
6974while_stmt: 'while' test ':' suite ['else' ':' suite]
@@ -91,6 +96,9 @@ exprlist: expr (',' expr)* [',']
9196testlist: test (',' test)* [',']
9297dictmaker: test ':' test (',' test ':' test)* [',']
9398
94- classdef: 'class' NAME parameters ['=' baselist] ':' suite
99+ # New class syntax should be:
100+ # classdef: class NAME ['(' testlist ')'] ':' suite
101+ # but merged with old syntax for compatibility it becomes:
102+ classdef: 'class' NAME ['(' testlist ')' |'(' ')' ['=' baselist]] ':' suite
95103baselist: atom arguments (',' atom arguments)*
96- arguments: '(' [testlist] ')'
104+ arguments: '(' ')'
0 commit comments