Luiz Miranda
Luiz Miranda

Reputation: 128

Why does it gives me this error? Python parser

I'm developing a parser with ply. I have this parser rules:

def p_maint(p):
    'maint : PROGRAMA ID declaraciones'

def p_declaraciones(p):
    '''declaraciones : vacio
                     | declaraciones
                     | tipo ID definicion_vector ";"'''

def p_tipo(p):
    '''tipo : ENTERO
            | FLOTANTE
            | CHAR'''

def p_definicion_vector(p):
    '''definicion_vector : vacio 
                         | "[" CTE_ENTERO "]" '''


def p_vacio(p):
    'vacio : '

But it gives me a warning:

WARNING: 1 reduce/reduce conflict
WARNING: reduce/reduce conflict in state 8 resolved using rule (maint -> PROGRAMA ID declaraciones)
WARNING: rejected rule (declaraciones -> declaraciones) in state 8
WARNING: Rule (declaraciones -> declaraciones) is never reduced

How can I remove this errors?

Upvotes: 0

Views: 45

Answers (1)

Michael Dyck
Michael Dyck

Reputation: 2458

You have the production declaraciones -> declaraciones, which is pointless. (It doesn't enlarge the language, and it makes the grammar ambiguous.)

My guess is, you meant to join two right-hand sides: '''declaraciones : vacio | declaraciones tipo ID definicion_vector ";"'''

Upvotes: 1

Related Questions