0
shift/reduce conflict in state [stack: PFamilia TClasse TCid TBlocoIni TCons PTipoPrimitivo TId TAtribuicaoConst TId *] on TPontoEVirg in {
    [ PFatorArt = TId * ] followed by TPontoEVirg (reduce),
    [ PLogicChamAtr = TId * TPontoEVirg ] (shift)
}

I am struggling trying to resolve this conflict, I've tried eliminating recursion on exp but since the shift doesn't consume the PontoEVirg token, the shift/reduce conflict persists.

Also any tips for reduce/reduce conflicts would be appreciated since I struggled with those too

Part of the grammar:

programa = {programa} familia def_classe;
 relacao = {relacao} classe [left]:cid filha_classe [right]:cid;
 familia = {familia} relacao relacoes* ponto_e_virg;
 relacoes = {relacao_lista} e_comercial relacao;

 def_classe = {def_classe} classe cid bloco_ini atributos metodos bloco_fim;

 atributos_opcoes = {atributos_opcoes} atributos_opcoesb | dec_cons;
 atributos_opcoesb = {atributos_opcoesb} dec_obj | dec_var;
 atributos = {atributos_fecho} atributos_opcoes*;
 metodos_opcoes = {metodos_opcoes} dec_procedimento | dec_funcao;
 metodos = {metodos_fecho} metodos_opcoes*;
 virg_id = {virg_id} virg id;
 dec_obj = {dec_obj} objeto cid id virg_id* ponto_e_virg;
 dec_var = {dec_var} var tipo id virg_id* ponto_e_virg;
 virg_ini = {virg_ini} virg inicializacao;
 dec_cons = {dec_cons} cons tipo_primitivo inicializacao virg_ini* ponto_e_virg;
 inicializacao = {inicializacao} id atribuicao_const exp; 

 tipo = {tipo} tipo_classe | tipo_primitivo;
 tipo_primitivo = {tipo_primitivo} tipo_primitivob | real;
 tipo_primitivob = {tipo_primitivob} inteiro | booleano;
 tipo_classe = {tipo_classe} cid;

bloco = bloco_ini atributos comando* bloco_fim;


 exp_logic = {explogic_e} exp_logic e_comparacao termo_logic
 | {explogic_ou} exp_logic ou_comparacao termo_logic
 | {explogic_termo} termo_logic;

 termo_logic = {termologic_par} par_esq exp par_dir
 | {termologic_neg} negacao termo_logic
 | {termologic_fator} fator_logic;

 fator_logic = {fatorlogic_igual} exp_art igual termo_art
 | {fatorlogic_maiorq} exp_art maior_que termo_art
 | {fatorlogic_menorq} exp_art menor_que termo_art
 | {fatorlogic_se} se par_esq [left]:exp par_dir entao [middle]:exp senao [right]:exp
 | {fatorlogic_chamatr} logic_cham_atr
 | {fatorlogic_bool} booleano;

 logic_cham_atr = {cham_atr} id_ponto? cham_atr ponto_e_virg;
 cham_atr = {exp_chamatr} chamada | atributo; 

 exp_art = {expart_soma} exp_art soma termo_art
 | {expart_subtracao} exp_art subt termo_art
 | {expart_termo} termo_art;

 termo_art = {termoart_mult} termo_art mult fator_art 
 | {termoart_div} termo_art div fator_art 
 | {termoart_mod} termo_art mod fator_art
 | {termoart_fator} fator_art;

 fator_art = {fatorart_id} id 
 | {fatorart_menos} subt fator_art
 | {fatorart_pot} [left]:fator_art potencia [right]:fator_art
 | {fatorart_int} inteiro
 | {fatorart_real} real
 | {fatorart_bloco} bloco_exp;

 bloco_exp = {bloco_exp} bloco_ini dec_cons* exp bloco_fim;
 chamada = {chamada} id par_esq lista_exp par_dir;
 atributo = {atributo} id;
 lista_exp = {lista_exp} exp? virg_exp*;
 exp_booleano = {exp_boolean} true | false;
 exp_real = {exp_real} [left]:numero ponto [right]:numero;
 exp_inteiro = {exp_inteiro} numero;
 exp = {expart} exp_art | {explogic} exp_logic;
 virg_exp = {virg_exp} virg exp;
  • I don't think I understand why you don't allow function calls in arithmetic expressions, and I certainly don't understand why you put the semicolon in `logic_cham_atr`. No other factor contains a semicolon, and semicolons seem to be used conventionally in your grammar, as separators. That's not the only shift-reduce conflict, right? It seems like you exponentiation rule should lead to a large number of conflicts. – rici Mar 02 '20 at 07:04
  • logic_cham_atr was an attempt of solving the problem, but I can see that it is redundant. before that I tried putting those sentences in factor_logic and as an alternative in "exp", all of those failed – Brenno Felix Santana Rodrigues Mar 02 '20 at 13:56
  • ok, that was probably too aggressive. Sorry. I'd like to help, but I really don't know what language you are attempting to parse. All I can see is part of your grammar, and even there, it has been modified in some way which didn't work and which didn't preserve the original syntax description. On top of that, your grammar excerpt doesn't include the token definitions, so one has to guess whether a name refers to a token or a non-terminal whose definition hasn't been included. Please provide a [mre]; it will make life easier for all of us. – rici Mar 02 '20 at 21:12

0 Answers0