mirror of https://github.com/python/cpython
Added 'continue', semicolons and dictionary displays.
This commit is contained in:
parent
2fe53f7fec
commit
56f7837704
|
@ -1,4 +1,10 @@
|
||||||
# Grammar for Python, version 4
|
# Grammar for Python, version 5
|
||||||
|
|
||||||
|
# Changes compared to version 4:
|
||||||
|
# Semicolons can separate small statements
|
||||||
|
# 'continue' statement
|
||||||
|
# Dictionary constructors: {key:value, key:value, ...}
|
||||||
|
# More tests instead of exprs
|
||||||
|
|
||||||
# Changes compared to version 3:
|
# Changes compared to version 3:
|
||||||
# Removed 'dir' statement.
|
# Removed 'dir' statement.
|
||||||
|
@ -34,23 +40,25 @@ fplist: fpdef (',' fpdef)*
|
||||||
fpdef: NAME | '(' fplist ')'
|
fpdef: NAME | '(' fplist ')'
|
||||||
|
|
||||||
stmt: simple_stmt | compound_stmt
|
stmt: simple_stmt | compound_stmt
|
||||||
simple_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt
|
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
|
||||||
expr_stmt: (exprlist '=')* exprlist NEWLINE
|
small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt
|
||||||
|
expr_stmt: (exprlist '=')* exprlist
|
||||||
# For assignments, additional restrictions enforced by the interpreter
|
# For assignments, additional restrictions enforced by the interpreter
|
||||||
print_stmt: 'print' (test ',')* [test] NEWLINE
|
print_stmt: 'print' (test ',')* [test]
|
||||||
del_stmt: 'del' exprlist NEWLINE
|
del_stmt: 'del' exprlist
|
||||||
pass_stmt: 'pass' NEWLINE
|
pass_stmt: 'pass'
|
||||||
flow_stmt: break_stmt | return_stmt | raise_stmt
|
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt
|
||||||
break_stmt: 'break' NEWLINE
|
break_stmt: 'break'
|
||||||
return_stmt: 'return' [testlist] NEWLINE
|
continue_stmt: 'continue'
|
||||||
raise_stmt: 'raise' expr [',' expr] NEWLINE
|
return_stmt: 'return' [testlist]
|
||||||
import_stmt: 'import' NAME (',' NAME)* NEWLINE | 'from' NAME 'import' ('*' | NAME (',' NAME)*) NEWLINE
|
raise_stmt: 'raise' test [',' test]
|
||||||
|
import_stmt: 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*)
|
||||||
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
|
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
|
||||||
if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
|
if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
|
||||||
while_stmt: 'while' test ':' suite ['else' ':' suite]
|
while_stmt: 'while' test ':' suite ['else' ':' suite]
|
||||||
for_stmt: 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite]
|
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
|
||||||
try_stmt: 'try' ':' suite (except_clause ':' suite)* ['finally' ':' suite]
|
try_stmt: 'try' ':' suite (except_clause ':' suite)* ['finally' ':' suite]
|
||||||
except_clause: 'except' [expr [',' expr]]
|
except_clause: 'except' [test [',' test]]
|
||||||
suite: simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
|
suite: simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
|
||||||
|
|
||||||
test: and_test ('or' and_test)*
|
test: and_test ('or' and_test)*
|
||||||
|
@ -61,11 +69,12 @@ comp_op: '<'|'>'|'='|'>' '='|'<' '='|'<' '>'|'in'|'not' 'in'|'is'|'is' 'not'
|
||||||
expr: term (('+'|'-') term)*
|
expr: term (('+'|'-') term)*
|
||||||
term: factor (('*'|'/'|'%') factor)*
|
term: factor (('*'|'/'|'%') factor)*
|
||||||
factor: ('+'|'-') factor | atom trailer*
|
factor: ('+'|'-') factor | atom trailer*
|
||||||
atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' '}' | '`' testlist '`' | NAME | NUMBER | STRING
|
atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING
|
||||||
trailer: '(' [testlist] ')' | '[' subscript ']' | '.' NAME
|
trailer: '(' [testlist] ')' | '[' subscript ']' | '.' NAME
|
||||||
subscript: expr | [expr] ':' [expr]
|
subscript: test | [test] ':' [test]
|
||||||
exprlist: expr (',' expr)* [',']
|
exprlist: expr (',' expr)* [',']
|
||||||
testlist: test (',' test)* [',']
|
testlist: test (',' test)* [',']
|
||||||
|
dictmaker: test ':' test (',' test ':' test)* [',']
|
||||||
|
|
||||||
classdef: 'class' NAME parameters ['=' baselist] ':' suite
|
classdef: 'class' NAME parameters ['=' baselist] ':' suite
|
||||||
baselist: atom arguments (',' atom arguments)*
|
baselist: atom arguments (',' atom arguments)*
|
||||||
|
|
Loading…
Reference in New Issue