private void AddAction(int state, int token, ParserAction action)
        {
            int cell = ParserAction.Encode(action);
            int currentCell = actionTable.Get(state, token);
            if (currentCell == 0)
            {
                actionTable.Set(state, token, cell);
            }
            else if (currentCell != cell)
            {
                int resolvedCell;
                if (!TryResolveShiftReduce(currentCell, cell, token, out resolvedCell))
                {
                    ParserConflictInfo conflict;
                    var key = new TransitionKey(state, token);
                    if (!transitionToConflict.TryGetValue(key, out conflict))
                    {
                        conflict = new ParserConflictInfo(state, token);
                        transitionToConflict[key] = conflict;
                        conflict.AddAction(currentCell);
                    }

                    if (!conflict.Actions.Contains(action))
                    {
                        conflict.AddAction(action);
                    }
                }

                actionTable.Set(state, token, resolvedCell);
            }
        }
Esempio n. 2
0
 internal ReportData(
     IGrammarSource       source,
     LanguageData         data,
     ParserConflictInfo[] parserConflicts,
     DotState[]           parserStates)
 {
     this.source = source;
     this.data = data;
     this.parserConflicts = parserConflicts;
     this.parserStates = parserStates;
 }
        private void ReportConflict(IReportData data, ParserConflictInfo conflict, StreamWriter message)
        {
            var symbol = data.Grammar.Symbols[conflict.Token];

            const string Indent = "  ";

            message.WriteLine(new string('-', 50));
            message.Write("Conflict on token ");
            message.Write(symbol.Name);
            message.Write(" between actions in state #");
            message.Write(conflict.State + "");
            message.WriteLine(":");
            DescribeState(data, conflict.State, message, Indent).WriteLine();
            for (int i = 0; i != conflict.Actions.Count; ++i)
            {
                message.WriteLine("Action #{0}", i);
                DescribeAction(data, conflict.Actions[i], message, Indent);
            }

            message.WriteLine(new string('-', 50));
        }