Python 3.0

Sintaxes completas representadas por Diagrama Sintático - Diagrama de Sintaxe (ver convenções) ou BNF (ver convenções).
Diagrama Sintático - Diagrama de Sintaxe | Diagrama Sintático - Diagrama de Sintaxe e BNF | BNF
1. file_input file_input : [(NEWLINE | stmt)+] ENDMARKER
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 file_input
2. single_input single_input : stmt? NEWLINE
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 single_input
3. eval_input eval_input : test {',' test} ','? [NEWLINE+] ENDMARKER
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 eval_input
4. stmt stmt : small_stmt (';' small_stmt)* ';'? |if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | [decorator+] (classdef | funcdef)
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 stmt
5. if_stmt if_stmt : 'if' [(test ':' suite 'elif')+] test ':' suite ['else' ':' suite]
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 if_stmt
>>> if x < 0:
... x = 0
... print 'Negative changed to zero'
... elif x == 0:
... print 'Zero'
... elif x == 1:
... print 'Single'
... else:
... print 'More'
6. while_stmt while_stmt : 'while' test':' suite ['else' ':' suite]
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 while_stmt
>>> # Fibonacci series:

... # the sum of two elements defines the next
... a, b = 0, 1
>>> while b < 10:
... print b
... a, b = b, a+b
7. for_stmt for_stmt : 'for' '*'? expr (',' '*'? expr)* ','? 'in' test (',' test)* ','? ':' suite['else' ':' suite]
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 for_stmt
>>> # Measure some strings:
... a = ['cat', 'window', 'defenestrate']
>>> for x in a:
... print x, len(x)
8. with_stmt with_stmt : 'with' test [ 'as' expr ] ':' suite
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 with_stmt
9. decorator decorator : '@' NAME ('.' NAME)* [ '(' arglist')' ] NEWLINE
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 decorator
10. classdef classdef : 'class' NAME ['(' arglist ')'] ':' suite
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 classdef
11. funcdef funcdef : 'def' NAME '(' typedargslist')'['->' test] ':' suite
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 funcdef
12. small_stmt small_stmt : expr_stmt | 'del' '*'? expr (',' '*'? expr)* ','? | 'pass'| flow_stmt | import_stmt | ('global '|' nonlocal') NAME (',' NAME)* |'assert' test [',' test]
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 small_stmt
13. expr_stmt expr_stmt : test (',' test)* ','? ('+ - * / ** & | ^ < < > > //' '=' (yield_expr | test (',' test)* ','?)|('=' (yield_expr | test (',' test)* ','?))+ | "")
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 expr_stmt
14. flow_stmt flow_stmt : 'break'| 'continue' | 'return' [test (',' test)* ','?] | 'raise' [test ['from' test]] | yield_expr
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 flow_stmt
15. import_stmt import_stmt : 'import' dotted_as_names | import_from
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 import_stmt
16. import_from import_from : 'from' ([('.' | '...')+] NAME ('.'NAME)* | ('.' |'...')+) 'import' ('*' | '(' import_as_names ')' | import_as_names)
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 import_from
17. import_as_names import_as_names : NAME ['as' NAME] (',' NAME ['as' NAME])* ','?
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 import_as_names
18. try_stmt try_stmt : 'try' ':' suite((except_clause ':' suite)+ ['else' ':' suite] ("" | 'finally' ':' suite) | 'finally' ':' suite)
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 try_stmt
19. except_clause except_clause : 'except' [test ['as' NAME]]
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 except_clause
20. typedargslist typedargslist : ([name_test ',']('*' tfpdef? [',' name_test] [',' '**' tfpdef] | '**' tfpdef) | name_test? ','?)
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 typedargslist
21. name_test name_test : tfpdef ['=' test] (',' tfpdef ['=' test])*
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 name_test
22. tfpdef tfpdef : NAME [':' test]
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 tfpdef
23. test test : or_test ['if' or_test 'else' test] | 'lambda' varargslist ':' test
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 test
24. suite suite : small_stmt (';' small_stmt)* [';'] NEWLINE | NEWLINE INDENT stmt+ DEDENT
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 suite
25. arglist arglist : (argument ',')* (argument [','] | '*' test (',' argument)* [',' '**' test] | '**' test)
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 arglist
26. argument argument : test (comp_for? | test '=' test)
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 argument
27. varargslist varargslist : name_test_list ',' ('*' [NAME] [',' name_test_list] [',' '**' NAME] | '**' NAME)| name_test_list [',']
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 varargslist
28. name_test_list name_test_list : NAME ['=' test]{',' NAME ['=' test]}
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 name_test_list
29. yield_expr yield_expr : 'yield' [test (',' test)* ','?]
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 yield_expr
30. or_test or_test : ('not'+)? '*'? expr("< | > | == | >= | <= | != | in | not in | is | is not" '*'?expr)* (('and' | 'or') ('not'+)? '*'? expr("< | > | == | >= | <= | != | in | not in | is | is not" '*' ?expr)*)*
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 or_test
31. expr expr : '+ | - | ~'? atom [trailer+]('+ - * / % ** & | ^ << >> //' '+ | - | ~'? atom [trailer+])*
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 expr
32. atom atom : ('(' ([yield_expr]|testlist_comp) ')'|'['testlist_comp']'|'{'dictorsetmaker '}' |NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 atom
33. testlist_comp testlist_comp : [test (comp_for | [(',' test)+] [','])]
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 testlist_comp
34. dictorsetmaker dictorsetmaker : test ( (':' test (comp_for |[(',' test ':' test)+] ','?)) |[(comp_for | ',' test)+] ','? )
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 dictorsetmaker
35. trailer trailer : '(' arglist ')' | '[' subscript (','subscript)* ','? ']' |'.' NAME
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 trailer
36. subscript subscript : test | [test] ':' test? (':' test?)?
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 subscript
37. dotted_as_names dotted_as_names : NAME ('.' NAME)* ['as' NAME](',' NAME ('.' NAME)*['as' NAME])*
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 dotted_as_names
38. comp_for comp_for : ('for' '*'? expr (',' '*'? expr)* ','? 'in' or_test [('if'test_nocond)+])+
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 comp_for
39. test_nocond test_nocond : or_test | 'lambda' varargslist ':' test_nocond
Diagrama Sintático - Diagrama de Sintaxe Python 3.0 test_nocond