我在Python程序中使用SimpleParse来解析一些相当简单的语言学。它应该能够解析以下示例文本(每行单独):
d6
(d4 + d8 + 5) + 6
{5d20}+12
[d10 + 6d6] + 9
(d10 + d12) + 8d8
我已经为上面的内容编写了下面的EBNF,但是解析器不断地崩溃,即使是在“d6”这个简单的例子中:
^{pr2}$我开始怀疑我是否把我的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]*
您还没有定义
number
,而且我在文档中也没有看到它是预定义的。在相关问题 更多 >
编程相关推荐