David Beazley wrote:
> Reduce/reduce conflicts are almost always bad---they mean that certain  
> rules in your grammar will never be triggered.
This isn't always true.  Consider the following grammar:

# foo.py

from ply import yacc

tokens = ('A', 'B', 'C')

def p_grammar(p):
    '''
    rule1 : rule2 B
          | rule2 C

    rule2 : rule3 B
          | rule4

    rule3 : A

    rule4 : A
    '''

yacc.yacc()

This has a reduce/reduce conflict, but all rules are used:

A B B => rule3 B B => rule2 B => rule1
A C => rule4 C => rule2 C => rule1


-bruce

P.S.  Should PLY 3.1 report unused rules?  On this input, it outputs:

WARNING: no p_error() function is defined
Generating LALR tables
WARNING: 1 reduce/reduce conflict
WARNING: reduce/reduce conflict in state 1 resolved using rule (rule3 -> A)
WARNING: rejected rule (rule4 -> A)

The final line says that (rule4 -> A) is rejected, but (rule4 -> A) is 
still used in other situations (as noted in the second example input, 
above).  Maybe the WARNING just means that the rule was rejected in this 
one state.

But if that's the case, the following input never uses (rule5 -> A) 
under any circumstance:

# foo.py

from ply import yacc

tokens = ('A', 'B', 'C')

def p_grammar(p):
    '''
    rule1 : rule2 B
          | rule2 C

    rule2 : rule3 B
          | rule4
          | rule5

    rule3 : A

    rule4 : A

    rule5 : A
    '''

yacc.yacc()

And yet the WARNING message is the same:

WARNING: no p_error() function is defined
Generating LALR tables
WARNING: 3 reduce/reduce conflicts
WARNING: reduce/reduce conflict in state 1 resolved using rule (rule3 -> A)
WARNING: rejected rule (rule4 -> A)
WARNING: reduce/reduce conflict in state 1 resolved using rule (rule3 -> A)
WARNING: rejected rule (rule5 -> A)
WARNING: reduce/reduce conflict in state 1 resolved using rule (rule4 -> A)
WARNING: rejected rule (rule5 -> A)

And there is nothing is parser.out indicating the (rule5 -> A) is never 
used.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to