From: Gregory Seidman Date: 2006-01-08T23:24:49+09:00 Subject: Re: [QUIZ] Dice Roller (#61) On Sun, Jan 08, 2006 at 10:48:01PM +0900, Pierre Barbier de Reuille wrote: } Matthew Moss a ?crit : } > Wow... You guys are just having too much fun with } > "(5d5-4)d(16/d4)+3", I think. Heck, if y'all know Ruby so well (more } > than me, cause I'm still such a n00b), you'd be able to swap in loaded } > dice for random dice and get your min's and max's. =) } > } > Anyway, I just wanted to add a couple of notes. It was made aware to } > me that the simplified BNF (in the original post) is slightly in } > error, in that it allows expressions like this: } > } > 3dddd6 } > } > which is invalid. } > } > A couple possible fixes: } > } > 1. Use the expanded BNF I posted, which doesn't have this fault. } > 2. Implement your dice parser using right-associativity for 'd' } > operators (but maintain left-assoc for the other binary operators). } > } > Feel free to do what you like. } > } > } } Well, why do you say it's invalid ? Given the simplified BNF it must be } read as : } } 3d(d(d(d6))) } } and it is perfectly valid as there is no other way to understand that ... That is only true if the d operator is right-associative. According to the original spec, it is left-associative and, therefore, 3dddd6 is a syntax error. Mind you, the second option Matthew gave is to make it right-associative, which is what you have done. I chose to treat it as a syntax error. } Pierre --Greg