private bool ResolveConflictByPrecedence(ParserState state, BnfTerm conflict) { var stateData = state.BuilderData; if (!conflict.IsSet(TermOptions.UsePrecedence)) { return(false); } if (!stateData.ShiftTerms.Contains(conflict)) { return(false); //it is not shift-reduce } //first find reduce items var reduceItems = stateData.ReduceItems.SelectByLookahead(conflict); if (reduceItems.Count > 1) { return(false); // if it is reduce-reduce conflict, we cannot fix it by precedence } var reduceItem = reduceItems.First(); //remove shift action and replace it with operator action var oldAction = state.Actions[conflict]; var action = ParserAction.CreateOperator(oldAction.NewState, reduceItem.Core.Production); state.Actions[conflict] = action; stateData.ResolvedConflicts.Add(conflict); return(true); }