On Apr 12, 2011, at 12:31 PM, Laurence Tratt wrote: > On Tue, Apr 12, 2011 at 08:47:42AM -0700, Terence Parr wrote: > > Dear Terence, > >> Only limitation is immediate-left-recur handled only. In my experience, >> that's good enough :) No point in some complicated algorithm when this >> covers any grammar I'd care about. > > A quick question: is any type of direct left recursion handled? I'm probably > being an idiot here (it's my normal mode), but your wiki post suggests that > this relies on the grammar being built in an "expression" sort-of way, but > the above post suggested there might be a bit more flexibility?
Hi. Yep, in the end, it was straightforward to convert any immediate left recursion as a side effect of looking for precedence-disambiguated expressions and the like. For example, a : a A | B ; gets translated to: a : a_[0] ; a_[int _p] : a_primary ( {_p <= 3}?=> A )* ; a_primary : B ; I removed some extraneous junk that gets generated for clarity. The transformation algorithm looks for unary prefix, unary suffix, binary, ternary operations and "other". The "other" stuff just gets thrown into the primary rule. In many cases the precedence predicates are unnecessary because syntax alone dictates what to do, as is the case here. In effect, a cleaned up grammar looks like a : B A* ; After I got this working, I kicked myself for not doing it 10 years ago! Very simple and covers practical cases of interest (mainly C-like declarations and then expressions for programming language grammars). Ter _______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg