06.01.2015 Views

Manual

Manual

Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5: The Bison Parser Algorithm 77<br />

{ printf ("empty sequence\n"); }<br />

| sequence word<br />

{ printf ("added word %s\n", $2); }<br />

;<br />

Here is another common error that yields a reduce/reduce conflict:<br />

sequence: /* empty */<br />

| sequence words<br />

| sequence redirects<br />

;<br />

words: /* empty */<br />

| words word<br />

;<br />

redirects:/* empty */<br />

| redirects redirect<br />

;<br />

The intention here is to define a sequence which can contain either word or redirect<br />

groupings. The individual definitions of sequence, words and redirects are error-free,<br />

but the three together make a subtle ambiguity: even an empty input can be parsed in<br />

infinitely many ways!<br />

Consider: nothing-at-all could be a words. Or it could be two words in a row, or three,<br />

or any number. It could equally well be a redirects, or two, or any number. Or it could<br />

be a words followed by three redirects and another words. And so on.<br />

Here are two ways to correct these rules. First, to make it a single level of sequence:<br />

sequence: /* empty */<br />

| sequence word<br />

| sequence redirect<br />

;<br />

Second, to prevent either a words or a redirects from being empty:<br />

sequence: /* empty */<br />

| sequence words<br />

| sequence redirects<br />

;<br />

words:<br />

word<br />

| words word<br />

;<br />

redirects:redirect<br />

| redirects redirect<br />

;<br />

5.7 Mysterious Reduce/Reduce Conflicts<br />

Sometimes reduce/reduce conflicts can occur that don’t look warranted. Here is an example:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!