On Sun, Oct 09, 2005 at 07:55:02PM -0500, Patrick R. Michaud wrote: > On Sun, Oct 09, 2005 at 09:55:44AM -1000, Joshua Hoblitt wrote: > > > > What is the status of this bug? Should this be a PGE todo item? > > > > > > My opinion is that it's "not a bug" -- the normal behavior for > > > most programs with infinite recursive loops is that they > > > eventually explode. > > > > Sounds reasonable. I'm sure it would be nearly impossible to catch all > > possible cases of infinite recursion when the grammar is compiled but > > how difficult would it be to trap at runtime? A simple warning along > > the lines of "Warning: production foo has recursed 10,000 times without > > matching any terminal\n" would certainly be useful in figuring why it > > blew up... > > We can enter "trap recursions without terminals" as a possible PGE > todo item, but unless someone knows an easy implementation or wants > to take on the task of implementation it's not likely to be resolved > anytime soon. :-)
I'll tag this bug a TODO and update the subject. DISCLAIMER: I know about diddly-squat about parers. A possible naive implementation would be to have a counter on every production that gets incremented by one each time it is matched. If any counter has a value > $RECURSION_LIMIT a warning is generated or an error is raised. Any time a terminal is matched all counters are reset. A lightly simpler version might have just a single global counter but I think per production counters might also be useful for debugging/optimizing a grammar. Cheers, -J --
pgplOv8s7cQKI.pgp
Description: PGP signature