From: Christian Surlykke Date: 2010-08-17T15:55:52+09:00 Subject: Re: Parsing, BNF, TreeTop, GhostWheel, ... --001517503ba67efbee048dff70d7 Content-Type: text/plain; charset=ISO-8859-1 You may want to look at: http://kanocc.rubyforge.org/ best regards Christian Surlykke 2010/8/17 Clifford Heath > (Sent previously, but it didn't appear. Sorry if you get this twice). > > > Philipp Kempgen wrote: > >> Is this a problem with packrat/PEG parsers in general? >> > > Yes. PEG parsers are greedy (iterate as far as possible and never > backtrack on that), and also take the first alternative that succeeds, > without trying subsequent alternatives. It's actually quite useful > and natural, once you get the hang of it. > > Pure PEGs have no lookahead, as Treetop does. It's often necessary > though, in the light of the above. > > Also, your approach will yield the wrong results when you add '-' into > the mix, because of associativity. "1-2-3" will calculate as 1-(2-3). > A better way is to use iteration, see > > < > http://github.com/nathansobo/treetop/blob/master/examples/lambda_calculus/arithmetic.treetop > > > > Clifford Heath. > --001517503ba67efbee048dff70d7--