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

Skip to content

Commit 56f7837

Browse files
committed
Added 'continue', semicolons and dictionary displays.
1 parent 2fe53f7 commit 56f7837

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

Grammar/Grammar

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# Grammar for Python, version 4
1+
# Grammar for Python, version 5
2+
3+
# Changes compared to version 4:
4+
# Semicolons can separate small statements
5+
# 'continue' statement
6+
# Dictionary constructors: {key:value, key:value, ...}
7+
# More tests instead of exprs
28

39
# Changes compared to version 3:
410
# Removed 'dir' statement.
@@ -34,23 +40,25 @@ fplist: fpdef (',' fpdef)*
3440
fpdef: NAME | '(' fplist ')'
3541

3642
stmt: simple_stmt | compound_stmt
37-
simple_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt
38-
expr_stmt: (exprlist '=')* exprlist NEWLINE
43+
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
44+
small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt
45+
expr_stmt: (exprlist '=')* exprlist
3946
# For assignments, additional restrictions enforced by the interpreter
40-
print_stmt: 'print' (test ',')* [test] NEWLINE
41-
del_stmt: 'del' exprlist NEWLINE
42-
pass_stmt: 'pass' NEWLINE
43-
flow_stmt: break_stmt | return_stmt | raise_stmt
44-
break_stmt: 'break' NEWLINE
45-
return_stmt: 'return' [testlist] NEWLINE
46-
raise_stmt: 'raise' expr [',' expr] NEWLINE
47-
import_stmt: 'import' NAME (',' NAME)* NEWLINE | 'from' NAME 'import' ('*' | NAME (',' NAME)*) NEWLINE
47+
print_stmt: 'print' (test ',')* [test]
48+
del_stmt: 'del' exprlist
49+
pass_stmt: 'pass'
50+
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt
51+
break_stmt: 'break'
52+
continue_stmt: 'continue'
53+
return_stmt: 'return' [testlist]
54+
raise_stmt: 'raise' test [',' test]
55+
import_stmt: 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*)
4856
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
4957
if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
5058
while_stmt: 'while' test ':' suite ['else' ':' suite]
51-
for_stmt: 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite]
59+
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
5260
try_stmt: 'try' ':' suite (except_clause ':' suite)* ['finally' ':' suite]
53-
except_clause: 'except' [expr [',' expr]]
61+
except_clause: 'except' [test [',' test]]
5462
suite: simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
5563

5664
test: and_test ('or' and_test)*
@@ -61,11 +69,12 @@ comp_op: '<'|'>'|'='|'>' '='|'<' '='|'<' '>'|'in'|'not' 'in'|'is'|'is' 'not'
6169
expr: term (('+'|'-') term)*
6270
term: factor (('*'|'/'|'%') factor)*
6371
factor: ('+'|'-') factor | atom trailer*
64-
atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' '}' | '`' testlist '`' | NAME | NUMBER | STRING
72+
atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING
6573
trailer: '(' [testlist] ')' | '[' subscript ']' | '.' NAME
66-
subscript: expr | [expr] ':' [expr]
74+
subscript: test | [test] ':' [test]
6775
exprlist: expr (',' expr)* [',']
6876
testlist: test (',' test)* [',']
77+
dictmaker: test ':' test (',' test ':' test)* [',']
6978

7079
classdef: 'class' NAME parameters ['=' baselist] ':' suite
7180
baselist: atom arguments (',' atom arguments)*

0 commit comments

Comments
 (0)