# Parsing Dice Notation

The syntax of dice notation follows the following grammar:

$$Roll \rightarrow Dice | Dice'x'Int | More \quad Mod \quad More$$ $$Dice \rightarrow Int_{1}'d'Int_2$$ $$Mod \rightarrow '+'|'-'$$ $$More \rightarrow Int | Roll$$ $$Int \rightarrow <integer>$$

Give a leftmost derivation for the sample string: $3d8 + 2d4x3 + 1d12 + 567$

I was able to parse the two first operands $3d8 + 2d4x3$ but I couldn't find a reasonable derivation for the rest.

My solution is like:

E -> More Mod More
E -> Roll Mod More
E -> Dice Mod More
E -> Int1’d’Int2 Mod More
E -> <integer>’d’Int2 Mod More
...
...
E -> <integer>’d’<integer> + <integer>’d’<integer>’x’<integer> + More Mod More
E -> <integer>’d’<integer> + <integer>’d’<integer>’x’<integer> + Roll Mod More
E -> <integer>’d’<integer> + <integer>’d’<integer>’x’<integer> + Dice Mod More
E -> <integer>’d’<integer> + <integer>’d’<integer>’x’<integer> + Int1’d’Int2 Mod More


I was thinking that the given string is not a valid string for this grammar.

Does any have any idea for this problem. I'm newbie in Compiler Design :-)

• Thank you! Actually, in the third and fourth string is 1d12 + 567 12 and 567 is an integer, not three consecutive integers. After that clarity, everything is much easier for me. – DucCuong Nov 27 '13 at 9:56