Pedro Lopes wrote: > General question: for every R/R conflict, is there a way to write the > grammar that is equivalent but does not produce a conflict? Or are > some grammars inherently ambiguous an will always have conflicts? The grammar that you specify may be ambiguous. This ambiguity results in S/R and/or R/R conflicts when PLY tries to compile it and PLY uses simplistic (but generally effective) heuristics to choose one of the ambiguous cases over the others.
But the language recognized by the resulting parser produced by PLY is always an LR language (that's all that the mechanism used by PLY is capable of). So you should (at least in theory) be able to specify a grammar for the language recognized without any ambiguities in it. Let me go at this another way... If a grammar is "ambiguous", then either the language being recognized can not be expressed using LR grammars (in which case conflict resolution won't help, because it will prune valid language options from the grammar) or the grammar could be re-written so as to express the same language in an unambiguous way. The catch, in the latter case, is that the unambiguous grammar may require more rules. Generally this is just one or two more rules, but occasionally whole sections of the grammar need to be duplicated. I don't know of any books off the top of my head that walk you through making a grammar unambiguous. (That doesn't mean that there aren't any out there)! Sorry I couldn't be more help. But if you keep wrestling with it, you should be able to figure out other ways of specifying the same language. Try taking it one conflict at a time (though often one fix will resolve a whole set of related conflicts that arise in the same parsing state). -bruce --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "ply-hack" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/ply-hack?hl=en -~----------~----~----~----~------~----~------~--~---
