Beispiel #1
0
        public void Report(string filename)
        {
            using (TextWriter w = File.CreateText(filename + ".report"))
            {
                w.WriteLine("Grammar");

                NonTerminal lhs = null;
                foreach (Production production in grammar.productions)
                {
                    if (production.lhs != lhs)
                    {
                        lhs = production.lhs;
                        w.WriteLine();
                        w.Write("{0,5} {1}: ", production.num, lhs);
                    }
                    else
                    {
                        w.Write("{0,5} {1}| ", production.num, new string(' ', lhs.ToString().Length));
                    }

                    for (int i = 0; i < production.rhs.Count - 1; i++)
                    {
                        w.Write("{0} ", production.rhs[i].ToString());
                    }

                    if (production.rhs.Count > 0)
                    {
                        w.WriteLine("{0}", production.rhs[production.rhs.Count - 1]);
                    }
                    else
                    {
                        w.WriteLine("/* empty */");
                    }
                }

                w.WriteLine();

                foreach (State state in states)
                {
                    w.WriteLine(state.ToString());
                }
            }
        }
        public void Report()
        {
            Console.WriteLine("Grammar");

            NonTerminal lhs = null;

            foreach (Production production in grammar.productions)
            {
                if (production.lhs != lhs)
                {
                    lhs = production.lhs;
                    Console.WriteLine();
                    Console.Write("{0,5} {1}: ", production.num, lhs);
                }
                else
                {
                    Console.Write("{0,5} {1}| ", production.num, new string(' ', lhs.ToString().Length));
                }

                for (int i = 0; i < production.rhs.Count - 1; i++)
                {
                    Console.Write("{0} ", production.rhs[i].ToString());
                }

                if (production.rhs.Count > 0)
                {
                    Console.WriteLine("{0}", production.rhs[production.rhs.Count - 1]);
                }
                else
                {
                    Console.WriteLine("/* empty */");
                }
            }

            Console.WriteLine();

            foreach (State state in states)
            {
                Console.WriteLine(state.ToString());
            }
        }
Beispiel #3
0
 public void Report(string log)
 {
     using (TextWriter textWriter = (log != null) ? File.CreateText(log) : Console.Out)
     {
         textWriter.WriteLine("Grammar");
         NonTerminal nonTerminal = null;
         foreach (Production current in this.grammar.productions)
         {
             if (current.lhs != nonTerminal)
             {
                 nonTerminal = current.lhs;
                 textWriter.WriteLine();
                 textWriter.Write("{0,5} {1}: ", current.num, nonTerminal);
             }
             else
             {
                 textWriter.Write("{0,5} {1}| ", current.num, new string(' ', nonTerminal.ToString().Length));
             }
             for (int i = 0; i < current.rhs.Count - 1; i++)
             {
                 textWriter.Write("{0} ", current.rhs[i].ToString());
             }
             if (current.rhs.Count > 0)
             {
                 textWriter.WriteLine("{0}", current.rhs[current.rhs.Count - 1]);
             }
             else
             {
                 textWriter.WriteLine("/* empty */");
             }
         }
         textWriter.WriteLine();
         foreach (State current2 in this.states)
         {
             textWriter.WriteLine(current2.ToString());
         }
     }
 }