Example #1
0
        private void загрузитьТестToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                curTest    = TestsManager.GetTest(ofd.FileName);
                curQNumber = 0;
                refreshHeader();
                refreshProgress();
                refreshQuestion();
            }
        }
        public static void Main(string[] args)
        {
            //Load specs
            (FileInfo, FileInfo)? s = SpecificationsManager.GetSpecification("test-002");
            FileStream ts = s.Value.Item1.OpenRead();
            FileStream gs = s.Value.Item2.OpenRead();

            //Parse tokens
            TokenSchemeCollection t = new TokenSchemeCollection();

            t.ReadFromStream(ts);

            //Parse grammar
            GrammarSchemeCollection g = new GrammarSchemeCollection();

            g.ReadFromStream(gs);

            //Load test
            FileInfo   test       = TestsManager.GetTest("test_ast");
            FileStream testStream = test.OpenRead();

            //Parse test File
            Parser1 p1 = new Parser1()
            {
                BaseTokens = t, BaseGrammar = g
            };
            TokenCollection    tokens  = p1.ParseTokensFromStream(testStream);
            Stack <int>        history = p1.ParseHistory(tokens);
            AbstractSyntaxTree ast     = new AbstractSyntaxTree();

            ast.CreateTree(g, tokens, ReverseHistory(history));

            Console.WriteLine(ast);
            ast.BreakDownLists();
            Console.WriteLine(ast);

            //Parse to abstract
            CFLRuntime     rt      = new CFLRuntime();
            ProgramBuilder builder = new ProgramBuilder(rt);
            Container      cnt     = builder.BuildFromTree(ast);

            //Console.WriteLine("Calculate sum of n squares with CFL [Enter integer]:");
            //object n = Console.ReadLine().EvaluateMathExpression();
            //Console.WriteLine(rt.Execute("sum_n_squares", ("n", n)));

            Console.WriteLine("Count number of prime numbers below n with CFL [Enter integer n]:");
            object n = Console.ReadLine().EvaluateMathExpression();

            Console.WriteLine(rt.Execute("primes_below_n", ("n", n)));
        }
        static void Main(string[] args)
        {
            //Load specs
            (FileInfo, FileInfo)? s = SpecificationsManager.GetSpecification("test-002");
            FileStream ts = s.Value.Item1.OpenRead();
            FileStream gs = s.Value.Item2.OpenRead();

            //Parse tokens
            TokenSchemeCollection t = new TokenSchemeCollection();

            t.ReadFromStream(ts);

            //Parse grammar
            GrammarSchemeCollection g = new GrammarSchemeCollection();

            g.ReadFromStream(gs);

            //Load test
            FileInfo   test       = TestsManager.GetTest("test_ast");
            FileStream testStream = test.OpenRead();

            //Parse test File
            Parser1 p1 = new Parser1()
            {
                BaseTokens = t, BaseGrammar = g
            };
            TokenCollection    tokens  = p1.ParseTokensFromStream(testStream);
            Stack <int>        history = p1.ParseHistory(tokens);
            AbstractSyntaxTree ast     = new AbstractSyntaxTree();

            ast.CreateTree(g, tokens, ReverseHistory(history));

            Console.WriteLine(ast);
            ast.BreakDownLists();
            Console.WriteLine(ast);
        }