________________________________ De : moose-dev-bounces@iam.unibe.ch [moose-dev-bounces@iam.unibe.ch] de la part de Nicolas Anquetil [Nicolas.Anquetil@inria.fr] Date d'envoi : mercredi 18 décembre 2013 13:34 À : Moose-related development Objet : [Moose-dev] Re: PetitParser PPCompositeParser, Infinite loop ?
On 12/18/2013 11:27 AM, Goubier Thierry wrote:
Le 18/12/2013 11:15, Nicolas Anquetil a écrit :
ben there is nothing magic about PPCompositeParser, it is a parser like all the other one and if you call rules without consuming any input + have a loop in the rule calls, then there will be a infinite loop
Yes and no. Some parsers can't handle left-recursion in rules (petit parser? LL parsers can't), some parsers don't have any problem with left recursion (LR parsers like SmaCC).
I meant PPCompositeParser within PetitParser All parsers PPParsers behave more or less the same way when we come to this. If other can't handle correctly left-recursion ther eis no reasonnable reason to hope that PPCompositeParser composite parser will do. Ok, now I understand what you meant Moreover, being a recursive descent parser, PetitParser naturally can't handle left recursivity
You have a point :) In this case, you will need to convert the grammar to a right recursive one, for example like this (which is more or less the same thing I believe):
ClassOrInterfaceType: ClassType "/ InterfaceType -- this option is useless here as it is equal to ClassType"
ClassType: TypeDeclSpecifier
TypeDeclSpecifier: TypeName { . TypeDeclSpecifier }
TypeName: Identifier TypeArgumentsopt
InterfaceType: TypeDeclSpecifier, TypeArgumentsopt
Some of the rules are not really needed, but that way it sticks closer to the reference grammar In that particular problem (InterfaceType = ClassType), PetitParser would select the first alternative everytime, since they are both equal, and would never reach InterfaceType ?
Regards,
Thierry nicolas
-- Nicolas Anquetil -- RMod research team (Inria)