我的EBNF逻辑有问题吗?
我在一个Python程序中使用SimpleParse来解析一些比较简单的语言学内容。它应该能够逐行解析以下示例文本:
d6
(d4 + d8 + 5) + 6
{5d20}+12
[d10 + 6d6] + 9
(d10 + d12) + 8d8
我为上面的内容写了以下的EBNF(扩展巴科斯-诺尔范式),但是解析器总是崩溃,连“d6”这样简单的例子也不行:
# 'number' is already predefined in SimpleParse to parse exactly what you think it will parse
root := roll
roll := space,operations,space
operations := function+
function := ((dice,op,function)/(grouping,op,function)/(function,op,grouping))/(dice/grouping/constant) #just to clarify, the '/' is a FirstOf operator
constant := number
grouping := ([[(],operations,[])])/'{',dice,'}'
dice := number?,[dD],number
op := space,[-+],space
space := [ \t]*
我开始怀疑我的EBNF逻辑是不是哪里出了问题。
编辑:对于好奇的人,这里是最终的EBNF样子:
roll := space,operations,space
operations := function
function := (dice,op,operations)/(grouping,op,operations)/dice/constant/grouping
constant := number
grouping := ('(',operations,')')/('{',dice,'}')/('[',operations,']')
dice := number?,[dD],number
op := space,[-+],space
space := [ \t]*
1 个回答
2
你还没有定义number
这个东西,我在文档里也没看到它有预先定义的内容。