diff options
author | Guido van Rossum <guido@python.org> | 1991-12-10 13:51:08 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-12-10 13:51:08 (GMT) |
commit | 68fc349744a48c18e278a4827a6f1782acb679a7 (patch) | |
tree | 4fc7643667f9a9d55b521c3de1108cba869e571f /Grammar | |
parent | ccf0ca28602a145b3b9519b00a4d870196e85e1e (diff) | |
download | cpython-68fc349744a48c18e278a4827a6f1782acb679a7.zip cpython-68fc349744a48c18e278a4827a6f1782acb679a7.tar.gz cpython-68fc349744a48c18e278a4827a6f1782acb679a7.tar.bz2 |
Added 'global' and new class syntax.
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/Grammar | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Grammar/Grammar b/Grammar/Grammar index 6de1312..494ebf0 100644 --- a/Grammar/Grammar +++ b/Grammar/Grammar @@ -1,4 +1,8 @@ -# Grammar for Python, version 7 +# Grammar for Python, version 8 + +# Changes since version 7: +# New syntax to specify base classes (but old syntax retained for now) +# 'global' statement (valid only in functions but not enforced here) # Changes since version 6: # Add logical operators '|', '^', '&' and '~' @@ -52,7 +56,7 @@ fpdef: NAME | '(' fplist ')' stmt: simple_stmt | compound_stmt simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE -small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt +small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt expr_stmt: (exprlist '=')* exprlist # For assignments, additional restrictions enforced by the interpreter print_stmt: 'print' (test ',')* [test] @@ -64,6 +68,7 @@ continue_stmt: 'continue' return_stmt: 'return' [testlist] raise_stmt: 'raise' test [',' test] import_stmt: 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*) +global_stmt: 'global' NAME (',' NAME)* compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] while_stmt: 'while' test ':' suite ['else' ':' suite] @@ -91,6 +96,9 @@ exprlist: expr (',' expr)* [','] testlist: test (',' test)* [','] dictmaker: test ':' test (',' test ':' test)* [','] -classdef: 'class' NAME parameters ['=' baselist] ':' suite +# New class syntax should be: +# classdef: class NAME ['(' testlist ')'] ':' suite +# but merged with old syntax for compatibility it becomes: +classdef: 'class' NAME ['(' testlist ')' |'(' ')' ['=' baselist]] ':' suite baselist: atom arguments (',' atom arguments)* -arguments: '(' [testlist] ')' +arguments: '(' ')' |