Ejemplo n.º 1
0
        private static void DumpTable(IWriter writer, Tabler tabler)
        {
            const string topLeft  = "┌";
            const string topRight = "┐";
            const string topMid   = "┬";
            const string topMid2  = "╥";

            const string midLeft  = "├";
            const string midRight = "┤";
            const string midMid   = "┼";
            const string midMid2  = "╫";

            const string botLeft  = "└";
            const string botRight = "┘";
            const string botMid   = "┴";
            const string botMid2  = "╨";

            const string hBar  = "─";
            const string vbar  = "│";
            const string vbar2 = "║";

            var stateCount       = tabler.NumberOfStates;
            var terminalCount    = tabler.NumberOfTerminals;
            var nonterminalCount = tabler.NumberOfNonterminals;
            var symbolCount      = tabler.NumberOfSymbols;

            var line = new string(hBar[0], shortLength);

            var tLine = Short(string.Empty) +
                        topLeft +
                        string.Join(topMid, Enumerable.Repeat(line, terminalCount)) +
                        topMid2 +
                        string.Join(topMid, Enumerable.Repeat(line, nonterminalCount)) +
                        topRight;

            writer.WriteLine(tLine);

            writer.Write(Short(string.Empty));

            Debug.Assert(tabler.Grammar.PSymbols != null);
            foreach (var symbol in tabler.Grammar.PSymbols)
            {
                if (symbol.Pid == terminalCount)
                {
                    writer.Write(vbar2);
                }
                else
                {
                    writer.Write(vbar);
                }

                writer.Write(Short(symbol));
            }
            writer.WriteLine(vbar);

            tLine = Short(string.Empty) +
                    midLeft +
                    string.Join(midMid, Enumerable.Repeat(line, terminalCount)) +
                    midMid2 +
                    string.Join(midMid, Enumerable.Repeat(line, nonterminalCount)) +
                    midRight;
            writer.WriteLine(tLine);

            for (var stateNo = 0; stateNo < stateCount; ++stateNo)
            {
                writer.Write(Short(stateNo.ToString()));

                for (var symNo = 0; symNo < symbolCount; ++symNo)
                {
                    if (symNo == terminalCount)
                    {
                        writer.Write(vbar2);
                    }
                    else
                    {
                        writer.Write(vbar);
                    }

                    writer.Write(tabler.Display(stateNo, symNo));
                }
                writer.Write(vbar);

                writer.WriteLine();
            }

            tLine = Short(string.Empty) +
                    botLeft +
                    string.Join(botMid, Enumerable.Repeat(line, terminalCount)) +
                    botMid2 +
                    string.Join(botMid, Enumerable.Repeat(line, nonterminalCount)) +
                    botRight;
            writer.WriteLine(tLine);
        }