gpt4 book ai didi

python - 我的EBNF逻辑错了吗?

转载 作者:行者123 更新时间:2023-12-01 06:11:54 24 4
gpt4 key购买 nike

我正在使用SimpleParse在 Python 程序中,以便解析一些相当简单的语言学。它应该能够解析以下示例文本(每行单独):

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

最佳答案

您尚未定义number,而且我在文档中没有看到它预定义的。

关于python - 我的EBNF逻辑错了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5481315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com