On 26 Jun 2012, at 13:23, Timothy Madden wrote: > I wrote a grammar file for an approximation of the php language (with the > purpose of adding braces to single-statements under if, for, while, but that > is not included yet), that simply outputs the found tokens back to an output > stream.
If you want to write a grammar for a known language, there is a good chance somebody already has done so. You might inquiry in the Usenet newsgroup comp.compilers. > My problem is I got like 233 shift/reduce conflicts (and 18 reduce/reduce > conflicts) and I do not really understand them. But searching the internet > shows most people have like 3 or 4 of them ... what did I do ? > > Is there a way for me to understand that report file bison outputs ? I looked > a lot through it, but I can not get where the conflicts are comming from. It > does says something about the first rules, describing whitespace, which I > want to preserve as significant part of the grammar. > > I have CenOS 6.2 64-bit (up-to-date), GNU bison 2.4.1 64-bit. > The grammar and report files are attached. Bison token preferences act on the tokens immediately before and after the parsing position '.' of the conflicting shift/reduce rules. So you might try to get rid some of them that way, by setting token precedences. Reduce/reduce conflicts may call for the grammar to be rewritten - write a grammar for a more general language without them, and cut it down in the semantic actions. Or you may try to use the GLR parser - see the manual for an example, from parsing C++ I recall. It is possible to use the first method for that too, so it is part a matter of taste which method to choose. Hans _______________________________________________ help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison