public InvalidParseTableException(ParseTableExceptionType exceptions, IParseTable <T> invalidTable, int state = -1, GrammarElement <T> nextInput = null)
     : base(createExceptionMsg(exceptions))
 {
     ParseTable = invalidTable;
     State      = state;
     NextInput  = nextInput;
 }
 public ParseTableConflict(ParseTableExceptionType conflictType, ColumnRowPair <int, Terminal <T> > tableLocation, StateNode <GrammarElement <T>, LRItem <T>[]> graphLocation, params LRItem <T>[] conflictingItems)
 {
     TableLocation    = tableLocation;
     GraphLocation    = graphLocation;
     ConflictType     = conflictType;
     ConflictingItems = new ReadOnlyCollection <LRItem <T> >(conflictingItems.ToList());
 }
        private static string createExceptionMsg(ParseTableExceptionType exceptions)
        {
            var b = new StringBuilder();

            b.Append("The parse table contains the following conflicts: {");

            //shift-reduce conflict
            if ((exceptions & ParseTableExceptionType.SHIFT_REDUCE) == ParseTableExceptionType.SHIFT_REDUCE)
            {
                b.Append("SHIFT_REDUCE,");
            }
            //reduce-reduce conflict
            if ((exceptions & ParseTableExceptionType.REDUCE_REDUCE) == ParseTableExceptionType.REDUCE_REDUCE)
            {
                b.Append(" REDUCE_REDUCE,");
            }
            //first-set clash
            if ((exceptions & ParseTableExceptionType.FIRST_SET) == ParseTableExceptionType.FIRST_SET)
            {
                b.Append(" FIRST_SET_CLASH");
            }

            string s = b.ToString();

            //remove possible trailing ','
            if (s.Last() == ',')
            {
                s = s.Remove(s.Length - 1);
            }

            s += " }";

            return(s);
        }