Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python EBNF如何读取_Python_Grammar_Ebnf - Fatal编程技术网

Python EBNF如何读取

Python EBNF如何读取,python,grammar,ebnf,Python,Grammar,Ebnf,所以我偶然发现了Python语言()的语法,我无法完全理解它是如何工作的。特别是,我对这个关于if语句的剪报感兴趣 if_stmt: 'if' namedexpr_test ':' suite ('elif' namedexpr_test ':' suite)* ['else' ':' suite] [...] namedexpr_test: test [':=' test] test: or_test ['if' or_test 'else' test] | lambdef test_noco

所以我偶然发现了Python语言()的语法,我无法完全理解它是如何工作的。特别是,我对这个关于if语句的剪报感兴趣

if_stmt: 'if' namedexpr_test ':' suite ('elif' namedexpr_test ':' suite)* ['else' ':' suite]
[...]
namedexpr_test: test [':=' test]
test: or_test ['if' or_test 'else' test] | lambdef
test_nocond: or_test | lambdef_nocond
lambdef: 'lambda' [varargslist] ':' test
lambdef_nocond: 'lambda' [varargslist] ':' test_nocond
or_test: and_test ('or' and_test)*
and_test: not_test ('and' not_test)*
not_test: 'not' not_test | comparison
comparison: expr (comp_op expr)*
# <> isn't actually a valid comparison operator in Python. It's here for the
# sake of a __future__ import described in PEP 401 (which really works :-)
comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
if_stmt:'if'namedexpr_test':'suite('elif'namedexpr_test':'suite)*['else':'suite]
[...]
namedexpr_测试:测试[':='测试]
测试:或|测试['if'或|测试'else'测试]| lambdef
测试无约束:或测试无约束
lambdef:'lambda'[varargslist]':'test
lambdef_nocond:'lambda'[varargslist]':'test_nocond
or_测试:and_测试('or'and_测试)*
and_测试:not_测试(‘and’not_测试)*
非|测试:非|非|测试|比较
比较:expr(comp_op expr)*
#实际上在Python中不是有效的比较运算符。它在这里是为了
#为了PEP 401中描述的“未来”导入(实际有效:-)

comp|op:''它编码优先级。使用此语法,您可以明确地解析表达式

not x and y or z
作为


以“预期”的方式,不需要括号。

就是这样,
的优先级高于
                    or_test
                   /       \
                  /         z
                and_test
               /        \
              /          y
          not_test
             |
             x