Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68fc349

Browse files
committed
Added 'global' and new class syntax.
1 parent ccf0ca2 commit 68fc349

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

Grammar/Grammar

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
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

5357
stmt: simple_stmt | compound_stmt
5458
simple_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
5660
expr_stmt: (exprlist '=')* exprlist
5761
# For assignments, additional restrictions enforced by the interpreter
5862
print_stmt: 'print' (test ',')* [test]
@@ -64,6 +68,7 @@ continue_stmt: 'continue'
6468
return_stmt: 'return' [testlist]
6569
raise_stmt: 'raise' test [',' test]
6670
import_stmt: 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*)
71+
global_stmt: 'global' NAME (',' NAME)*
6772
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
6873
if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
6974
while_stmt: 'while' test ':' suite ['else' ':' suite]
@@ -91,6 +96,9 @@ exprlist: expr (',' expr)* [',']
9196
testlist: test (',' test)* [',']
9297
dictmaker: 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
95103
baselist: atom arguments (',' atom arguments)*
96-
arguments: '(' [testlist] ')'
104+
arguments: '(' ')'

0 commit comments

Comments
 (0)