我正在观察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)] ]发布于 2018-07-21 00:07:12
如果
['*' [vfpdef] (',' vfpdef ['=' test])* ]是
[ [ non-terminal1 ] non-terminal2 ] -- parentheses deleted as redundant则non-terminal2表示
non-terminal3 *根据定义它是可以为空的。(即,它可能是空的。)
所以,严格地说,一旦你完成了转换
non-terminal1不是有效的结果。解析器必须是
non-terminal1 non-terminal2其中non-terminal2匹配了空字符串。
但是实际的解析逻辑更可能想要使用公式
[ [ non-terminal1 ] non-terminal3... ] -- Not EBNF syntax, but I hope you get the idea在这种情况下,non-terminal2已经被消除了,因为它分散了对结果解析的注意力。在这种情况下,由于0或更多的重复可以是0次重复,因此正确的结果将包括
-- nothing :-)
non-terminal1
non-terminal3
non-terminal1 non-terminal3
non-terminal3 non-terminal3诸若此类。
https://stackoverflow.com/questions/51445192
复制相似问题