Re: Simple question on lex/yacc specifications

Max Hailperin <max@gustavus.edu>
Sun, 15 Mar 2009 06:12:51 -0500

          From comp.compilers

Related articles
Simple question on lex/yacc specifications eric.fowler@gmail.com (Eric Fowler) (2009-03-13)
Re: Simple question on lex/yacc specifications eric.fowler@gmail.com (Eric Fowler) (2009-03-14)
Re: Simple question on lex/yacc specifications kym@svalbard.freeshell.org (russell kym horsell) (2009-03-15)
Re: Simple question on lex/yacc specifications max@gustavus.edu (Max Hailperin) (2009-03-15)
Re: Simple question on lex/yacc specifications eric.fowler@gmail.com (Eric Fowler) (2009-03-15)
| List of all articles for this month |
From: Max Hailperin <max@gustavus.edu>
Newsgroups: comp.compilers
Date: Sun, 15 Mar 2009 06:12:51 -0500
Organization: Compilers Central
References: 09-03-058 09-03-062
Keywords: parse, yacc
Posted-Date: 15 Mar 2009 16:58:26 EDT

Eric Fowler <eric.fowler@gmail.com> writes:


> ...
> Here is what is NOT working (cut down):
> ...
> Obviously I am doing something fundamentally wrong.
>
> I tried transposing the rules for decimalnum and opt_decimalnum in the
> yacc rules file, and it inverted the outcome, in other words, the
> string with the empty number token is now not recognized, but a string
> with digits is....
> [Try this:
> ...
> Empty RHS rules are valid and useful in a situation like this. -John]


John is of course correct that empty right hand sides are valid and
could be used to make a cleaner grammar.


But that doesn't explain why Eric's grammar wasn't working.


The answer is: something he isn't showing us. The stripped down code
he included in his posting is 100% correct -- if extended with a
correct lexical analyzer and test harness (main, etc.) it produces the
correct output when fed either of his two test inputs. So the problem
must be in the stuff he stripped out.


We get a clue from the fact that reversing the order of the
productions for two nonterminals (neither of which is the start
symbol) changes the symptoms. This strongly suggests that the problem
in the full grammar is a reduce-reduce conflict. Without seeing that
full grammar, and where the reduce-reduce conflict is within it, I
wouldn't place a bet in either direction regarding whether the
conflict might go away as a side effect of making John's suggested
change. -max



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.