かなり単純な言語学を解析するために、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]*