From: Will Shattuck Date: 2006-01-07T05:42:32+09:00 Subject: Re: [QUIZ] Dice Roller (#61) forgive my ignorance... BNF? w On 1/6/06, Matthew Moss wrote: > > I would appreciate the full BNF, please. > > Okay, this is what I've done in my current version that takes care of basic > precedence and associativity. > > INTEGER = /[1-9][0-9]*/ > > expr: fact > | expr '+' fact > | expr '-' fact > > fact: term > | fact '*' term > | fact '/' term > > term: unit > | [term] 'd' dice > > dice: '%' > | unit > > unit: '(' expr ')' > | INTEGER > > > Actually, this is slightly different than my current version, which after > reexamining to extract this BNF, I found a minor error (in handling of the > term rules and handling of the optional arg). My own code has a morphed > version of this BNF in order to code up a recursive descent parser, but this > BNF shows one way to handle the precedence/association rules. > > -- Will Shattuck ( willshattuck.at.gmail.com ) Home Page: http://www.thewholeclan.com/will When you get to your wit's end, you'll find God lives there.