我观察了manual中列出的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状态的wiki页
That is, everything that is set within the square brackets may be
present just once, or not at all
但这是否将方括号内的所有内容都归为一个实体,可能只出现一次,或者选项是选择性的,例如:
[ [non-terminal1] [(non-terminal2)] ]
如果
是
那么
non-terminal2
表示定义为空。(也就是说,它可能是空的。)
所以,严格地说,一旦你完成了转换
不是有效的结果。解析必须是
其中
non-terminal2
匹配了一个空字符串。你知道吗但实际的解析逻辑更可能希望使用公式
其中
non-terminal2
已被排除在结果解析之外。在这种情况下,由于0或更多的重复可以是0次重复,正确的结果将包括等等。你知道吗
相关问题 更多 >
编程相关推荐