Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.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语法,并考虑其EBNF形式的输出,特别是使用varargslist: varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [ '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]] | '**' vfpdef [',']]] | '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**'

我正在观察中列出的python语法,并考虑其EBNF形式的输出,特别是使用varargslist:

varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [
'*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
| '**' vfpdef [',']]]
| '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
| '**' vfpdef [',']
虽然我对这一部分特别感兴趣:

['*' [vfpdef] (',' vfpdef ['=' test])* ]
我将其解释为:

[ [ non-terminal1 ] ( non-terminal2) ]
我意识到两者

non-terminal1 (non-terminal2)
(non-terminal2)
此表单中的选项有效,但是否包括:

non-terminal1
还有吗?EBNF状态的页面

That is, everything that is set within the square brackets may be 
present just once, or not at all
但是,该组是否将方括号内的所有内容视为一个实体,可能只出现一次,或者选项是否具有选择性,例如:

[ [non-terminal1] [(non-terminal2)] ]
如果

然后
非终端2
表示

non-terminal3 *
根据定义,它可以为空。(也就是说,它可能是空的。)

严格来说,一旦你完成了转换

non-terminal1
这不是一个有效的结果。解析必须是

non-terminal1 non-terminal2
其中,
non-terminal2
匹配了一个空字符串

但实际的解析逻辑更可能希望使用公式

[ [ non-terminal1 ] non-terminal3... ]   -- Not EBNF syntax, but I hope you get the idea
其中,
非终端2
已被消除,因为它分散了对结果解析的注意力。在这种情况下,由于0或更多的重复可以是0次重复,正确的结果包括

                                          -- nothing :-)
non-terminal1
              non-terminal3
non-terminal1 non-terminal3
              non-terminal3 non-terminal3
等等

[ [ non-terminal1 ] non-terminal3... ]   -- Not EBNF syntax, but I hope you get the idea
                                          -- nothing :-)
non-terminal1
              non-terminal3
non-terminal1 non-terminal3
              non-terminal3 non-terminal3