我的EBNF逻辑错了吗?

2024-04-24 08:27:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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]*

Tags: 程序示例numberfunctionspacediceoperations语言学