Question

I'm using SimpleParse in a Python program in order to parse some rather simple linguistics. It should be able to parse the following sample text (each line separately):

d6
(d4 + d8 + 5) + 6
{5d20}+12
[d10 + 6d6] + 9
(d10 + d12) + 8d8

I've written up the following EBNF for the above, but the parser keeps crashing on me, even on the simple case of "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]*

I'm beginning to wonder if maybe I've gotten the logic in my EBNF wrong somewhere.

EDIT: For the curious, here is what the final EBNF looks like:

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]*
Was it helpful?

Solution

You haven't defined number, and I don't see it predefined in the docs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top