예제 #1
0
        //----< Test Stub >--------------------------------------------------

#if (TEST_PARSER)
        static void Main(string[] args)
        {
            Console.Write("\n  Demonstrating Parser");
            Console.Write("\n ======================\n");

            ShowCommandLine(args);

            List <string> files = TestParser.ProcessCommandline(args);

            foreach (object file in files)
            {
                Console.Write("\n  Processing file {0}\n", file as string);

                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }

                Console.Write("\n  Type and Function Analysis");
                Console.Write("\n ----------------------------\n");

                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser            parser  = builder.build();

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                    Console.Write("\n\n  locations table contains:");
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                foreach (Elem e in table)
                {
                    Console.Write("\n  {0,10}, {1,25}, {2,5}, {3,5}", e.type, e.name, e.begin, e.end);
                }
                Console.WriteLine();
                Console.Write("\n\n  That's all folks!\n\n");
                semi.close();
            }
        }
        public void doAnalysis(string[] files)
        {
            // Parser p = new Parser();
            //p.parseFiles(files);

            //NEW DESIGN

            CSsemi.CSemiExp   semi    = new CSsemi.CSemiExp();
            CSsemi.CSemiExp   semi2   = new CSsemi.CSemiExp();
            BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
            Parser            parser  = builder.build();

            foreach (object file in files)
            {
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }

                // Console.Write("\n  Type and Function Analysis");
                // Console.Write("\n ----------------------------\n");

                //  Console.WriteLine("processing file{0}", file as string);



                try
                {
                    if (semi.getSemi())
                    {
                        semi2 = semi;
                        parser.parse(semi);
                    }
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                    //Console.Write("\n\n  locations table contains:");
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                semi.close();
            }

            Repository  rep   = Repository.getInstance();
            List <Elem> table = rep.locations;


            Parser parser2 = builder.build2(rep, semi2);

            foreach (object file in files)
            {
                // CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi2.displayNewLines = false;

                if (!semi2.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }

                try
                {
                    do
                    {
                        parser2.parse(semi2);
                    } while (semi2.getSemi());
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                //Repository rep = Repository.getInstance();

                semi2.close();
            }
        }