-----Original Message-----
From: pharo-users-bounces@lists.gforge.inria.fr [mailto:pharo-users-bounces@lists.gforge.inria.fr] On Behalf Of Lukas Renggli Sent: 21 January 2011 14:39 To: A friendly place where any question about pharo is welcome Subject: Re: [Pharo-users] Left recursion in PetitParser
I know how to left-factor the grammar by hand. But should I have to? How powerful is thy magic, Lukas?
There is no magic.
You can fix the problem by wrapping one of the parsers in the cycle with #memoize. That could be done automatically (#cycleSet finds the cycles), but I would rather refactor the grammar as it leads to extremely inefficient parsers.
If you want to build complicated expression grammars (where typically left-recursion occurs) it might be useful to use the PPExpressionParser, see the class comment for an example.
I got my parser working by refactoring the grammar; Using not to do a little look-ahead and direct things down the correct path helped. I saw the tests for memoize, and get the idea of how to use it. But I don't find a cycleSet method anywhere ... Andrew