The warning message about rules being rejected is new in PLY-3.0.    
However, they are state dependent so I think I will clarify the  
message to more clearly indicate the state.   The idea of detecting a  
rule that's never reduced is interesting.  PLY-2 never reported any  
errors about that nor does PLY-3.   However, that seems like something  
that would be pretty useful to add.    I'll look into that for PLY-3.2  
(working on it now).

Cheers,
Dave


On Mar 23, 2009, at 5:50 PM, Bruce Frederiksen wrote:
>
>
> But on a different topic, I was wondering whether you went over the  
> material I had included in the P.S. of my message.  Basically, I'm  
> not sure whether you are thinking that PLY should report unreachable  
> rules or not.  If not, no problem.  If so, then either the second  
> example in the P.S. doesn't seem to produce any such notification;  
> or the first example produces an erroneous notification (depending  
> on what the notice looks like).  I only bring this up because you  
> say that PLY is used in a teaching setting and is designed to catch  
> lots of errors...
>
> -bruce
>> On Mar 23, 2009, at 4:06 PM, Bruce Frederiksen wrote:
>>
>>
>>> 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