1- # Grammar for Python, version 3
1+ # Grammar for Python, version 4
2+
3+ # Changes compared to version 3:
4+ # Removed 'dir' statement.
5+ # Function call argument is a testlist instead of exprlist.
26
37# Changes compared to version 2:
48# The syntax of Boolean operations is changed to use more
1115# 'import' and 'def' aren't special any more;
1216# added 'from' NAME option on import clause, and '*' to import all;
1317# added class definition.
14- # TO DO:
15- # replace 'dir' by something more general?
1618
1719# Start symbols for the grammar:
1820# single_input is a single interactive statement;
@@ -32,12 +34,11 @@ fplist: fpdef (',' fpdef)*
3234fpdef: NAME | '(' fplist ')'
3335
3436stmt: simple_stmt | compound_stmt
35- simple_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | dir_stmt | flow_stmt | import_stmt
37+ simple_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt
3638expr_stmt: (exprlist '=')* exprlist NEWLINE
3739# For assignments, additional restrictions enforced by the interpreter
3840print_stmt: 'print' (test ',')* [test] NEWLINE
3941del_stmt: 'del' exprlist NEWLINE
40- dir_stmt: 'dir' [expr] NEWLINE
4142pass_stmt: 'pass' NEWLINE
4243flow_stmt: break_stmt | return_stmt | raise_stmt
4344break_stmt: 'break' NEWLINE
@@ -61,7 +62,7 @@ expr: term (('+'|'-') term)*
6162term: factor (('*'|'/'|'%') factor)*
6263factor: ('+'|'-') factor | atom trailer*
6364atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' '}' | '`' testlist '`' | NAME | NUMBER | STRING
64- trailer: '(' [exprlist ] ')' | '[' subscript ']' | '.' NAME
65+ trailer: '(' [testlist ] ')' | '[' subscript ']' | '.' NAME
6566subscript: expr | [expr] ':' [expr]
6667exprlist: expr (',' expr)* [',']
6768testlist: test (',' test)* [',']
0 commit comments