When using yacc if we have the following grammar it does not give us any problem, only the conflict displaces / reduces the if else that it should be.
Programa : Cabecera_programa Bloque;
Cabecera_programa : PRIN | error;
Bloque : ABRIRLLAVE
Declar_variables_locales
Declar_subprogs
Sentencias
CERRARLLAVE
| ABRIRLLAVE
Declar_variables_locales
Sentencias
CERRARLLAVE
| ABRIRLLAVE
Declar_subprogs
Sentencias
CERRARLLAVE
| ABRIRLLAVE
Declar_variables_locales
Declar_subprogs
CERRARLLAVE
| ABRIRLLAVE
Sentencias
CERRARLLAVE;
Declar_subprogs : Declar_subprogs Declar_subprog
| Declar_subprog;
Declar_subprog : Cabecera_subprog Bloque;
Declar_variables_locales : DECLA Variables_locales FINDECLA ;
Variables_locales : Variables_locales Cuerpo_decla_variables
| Cuerpo_decla_variables;
Cuerpo_decla_variables : TIPO Lista_ids PUNCOM
| error;
Cabecera_subprog : TIPO Id_array ABREPAR Parametros CIERRAPAR;
Sentencias : Sentencias Sentencia
| Sentencia;
Sentencia : Bloque
| Sentencia_asignacion
| Sentencia_if
| Sentencia_while
| Sentencia_entrada
| Sentencia_salida
| Sentencia_return
| Sentencia_for
| error;
Sentencia_asignacion : Variable ASIGN Expresion PUNCOM;
Sentencia_if : SI ABREPAR Expresion CIERRAPAR Sentencia
| SI ABREPAR Expresion CIERRAPAR Sentencia
SINO Sentencia;
Sentencia_while : MIENTRAS ABREPAR Expresion CIERRAPAR Sentencia;
Sentencia_entrada : LEER Lista_ids PUNCOM;
Sentencia_salida : MOSTRAR Lista_exp_cadenas PUNCOM;
Sentencia_return : RET Expresion PUNCOM;
Sentencia_for : PARA ID ASIGN Expresion HASTA Expresion PASO Expresion EMPIEZA Sentencia FIN;
Expresion : ABREPAR Expresion CIERRAPAR
| Expresion OPBIN Expresion
| Expresion OPOR Expresion
| Expresion OPAND Expresion
| Expresion OPMD Expresion
| Expresion MASMENOS Expresion
| MASMENOS Expresion %prec OPUN
| OPUN Expresion
| Constante
| Funcion
| Variable
| error;
Funcion : ID ABREPAR Lista_ids CIERRAPAR
| ID ABREPAR CIERRAPAR;
Lista_ids : Lista_ids COMA Id_array
| Id_array;
Parametros : Parametros COMA Parametro
| Parametro;
Parametro : TIPO Id_array;
Variable : ID
| ID ABRECOR Expresion CIERRACOR
| ID ABRECOR Expresion COMA Expresion CIERRACOR;
Lista_exp_cadenas : Lista_exp_cadenas COMA Exp_cad
| Exp_cad;
Exp_cad : Expresion
| CADENA;
Id_array : Array
| ID;
Array : ID ABRECOR ENTERO CIERRACOR
| ID ABRECOR ENTERO CIERRACOR ABRECOR ENTERO CIERRACOR;
Constante : ENTERO
| CARACTER
| REAL
| BOOL
| Constante_array;
Constante_array : Cons_array_enteros
| Cons_array_reales
| Cons_array_booleanos
| Cons_array_caracteres;
Cons_array_enteros : ABRECOR Lista_cons_enteros CIERRACOR
| ABRECOR Lista_cons_enteros_2d CIERRACOR;
Cons_array_reales : ABRECOR Lista_cons_reales CIERRACOR
| ABRECOR Lista_cons_reales_2d CIERRACOR;
Cons_array_booleanos : ABRECOR Lista_cons_booleanos CIERRACOR
| ABRECOR Lista_cons_booleanos_2d CIERRACOR;
Cons_array_caracteres : ABRECOR Lista_cons_caracteres CIERRACOR
| ABRECOR Lista_cons_caracteres_2d CIERRACOR;
Lista_cons_enteros : Lista_cons_enteros COMA ENTERO
| ENTERO;
Lista_cons_enteros_2d : Lista_cons_enteros PUNCOM Lista_cons_enteros;
Lista_cons_reales : Lista_cons_reales COMA REAL
| REAL;
Lista_cons_reales_2d : Lista_cons_reales PUNCOM Lista_cons_reales;
Lista_cons_booleanos : Lista_cons_booleanos COMA BOOL
| BOOL;
Lista_cons_booleanos_2d : Lista_cons_booleanos PUNCOM Lista_cons_booleanos;
Lista_cons_caracteres : Lista_cons_caracteres COMA CARACTER
| CARACTER;
Lista_cons_caracteres_2d : Lista_cons_caracteres PUNCOM Lista_cons_caracteres;
The problem is in the block production rule, we want the grammar to end in the following way.
Programa : Cabecera_programa Bloque;
Cabecera_programa : PRIN | error;
Bloque : ABRIRLLAVE
Declar_variables_locales
Declar_subprogs
Sentencias
CERRARLLAVE; ///Modificada la regla de producción
Declar_subprogs : Declar_subprogs Declar_subprog
| Declar_subprog
| ; ///Modificada la regla de producción
Declar_subprog : Cabecera_subprog Bloque;
Declar_variables_locales : DECLA Variables_locales FINDECLA
| ; ///Modificada la regla de producción
Variables_locales : Variables_locales Cuerpo_decla_variables
| Cuerpo_decla_variables;
Cuerpo_decla_variables : TIPO Lista_ids PUNCOM
| error;
Cabecera_subprog : TIPO Id_array ABREPAR Parametros CIERRAPAR;
Sentencias : Sentencias Sentencia
| Sentencia
| ; ///Modificada la regla de producción
Sentencia : Bloque
| Sentencia_asignacion
| Sentencia_if
| Sentencia_while
| Sentencia_entrada
| Sentencia_salida
| Sentencia_return
| Sentencia_for
| error;
Sentencia_asignacion : Variable ASIGN Expresion PUNCOM;
Sentencia_if : SI ABREPAR Expresion CIERRAPAR Sentencia
| SI ABREPAR Expresion CIERRAPAR Sentencia
SINO Sentencia;
Sentencia_while : MIENTRAS ABREPAR Expresion CIERRAPAR Sentencia;
Sentencia_entrada : LEER Lista_ids PUNCOM;
Sentencia_salida : MOSTRAR Lista_exp_cadenas PUNCOM;
Sentencia_return : RET Expresion PUNCOM;
Sentencia_for : PARA ID ASIGN Expresion HASTA Expresion PASO Expresion EMPIEZA Sentencia FIN;
Expresion : ABREPAR Expresion CIERRAPAR
| Expresion OPBIN Expresion
| Expresion OPOR Expresion
| Expresion OPAND Expresion
| Expresion OPMD Expresion
| Expresion MASMENOS Expresion
| MASMENOS Expresion %prec OPUN
| OPUN Expresion
| Constante
| Funcion
| Variable
| error;
Funcion : ID ABREPAR Lista_ids CIERRAPAR
| ID ABREPAR CIERRAPAR;
Lista_ids : Lista_ids COMA Id_array
| Id_array;
Parametros : Parametros COMA Parametro
| Parametro;
Parametro : TIPO Id_array;
Variable : ID
| ID ABRECOR Expresion CIERRACOR
| ID ABRECOR Expresion COMA Expresion CIERRACOR;
Lista_exp_cadenas : Lista_exp_cadenas COMA Exp_cad
| Exp_cad;
Exp_cad : Expresion
| CADENA;
Id_array : Array
| ID;
Array : ID ABRECOR ENTERO CIERRACOR
| ID ABRECOR ENTERO CIERRACOR ABRECOR ENTERO CIERRACOR;
Constante : ENTERO
| CARACTER
| REAL
| BOOL
| Constante_array;
Constante_array : Cons_array_enteros
| Cons_array_reales
| Cons_array_booleanos
| Cons_array_caracteres;
Cons_array_enteros : ABRECOR Lista_cons_enteros CIERRACOR
| ABRECOR Lista_cons_enteros_2d CIERRACOR;
Cons_array_reales : ABRECOR Lista_cons_reales CIERRACOR
| ABRECOR Lista_cons_reales_2d CIERRACOR;
Cons_array_booleanos : ABRECOR Lista_cons_booleanos CIERRACOR
| ABRECOR Lista_cons_booleanos_2d CIERRACOR;
Cons_array_caracteres : ABRECOR Lista_cons_caracteres CIERRACOR
| ABRECOR Lista_cons_caracteres_2d CIERRACOR;
Lista_cons_enteros : Lista_cons_enteros COMA ENTERO
| ENTERO;
Lista_cons_enteros_2d : Lista_cons_enteros PUNCOM Lista_cons_enteros;
Lista_cons_reales : Lista_cons_reales COMA REAL
| REAL;
Lista_cons_reales_2d : Lista_cons_reales PUNCOM Lista_cons_reales;
Lista_cons_booleanos : Lista_cons_booleanos COMA BOOL
| BOOL;
Lista_cons_booleanos_2d : Lista_cons_booleanos PUNCOM Lista_cons_booleanos;
Lista_cons_caracteres : Lista_cons_caracteres COMA CARACTER
| CARACTER;
Lista_cons_caracteres_2d : Lista_cons_caracteres PUNCOM Lista_cons_caracteres;
Basically it is to add the empty to Declar_variables_local, Declar_subprogs and Sentences. The problem is that in doing so we get 11 conflicts displaces / reduces when it should be the same as in the first one that does not give problems.