Exemplo n.º 1
0
    static void Main(string[] args)
    {
        int Z = readNum();
        for(int i = 0; i < Z; i++) {
            int statesCount = readNum();
            FiniteMachine fm = new FiniteMachine(statesCount);

            // states list is ignored for now
            Console.ReadLine();

            int count = readNum();
            foreach(string n in Console.ReadLine().Split(' ')) {
                fm.SetFinal(int.Parse(n));
            }

            int fns = readNum();
            for(int x = 0; x < fns; x++) {
                var parts = Console.ReadLine().Split(' ');

                fm.AddTransition(int.Parse(parts[0]), parts[1][0], int.Parse(parts[2]));
            }

            int examples = readNum();
            for(int x = 0; x < examples; x++) {
                fm.reset();
                Console.WriteLine(fm.isValid(Console.ReadLine()) ? "ANO" : "NE");
            }
        }
    }
Exemplo n.º 2
0
        private void Start_Click(object sender, RoutedEventArgs e)
        {
            List <string> sourceCode = GetListStringFromRichTextBox(this.codeTextBox);

            ILexicalAnalyser analyser = new FiniteMachine(sourceCode);

            analyser.Analize();

            Const.AllConstFromCode = analyser.ConstantList;
            Idnt.AllIdnFromCode    = analyser.IdentifierList;
            if (showLexemTable.IsChecked)
            {
                new LexemTable(analyser.LexemList, analyser.IdentifierList, analyser.ConstantList).Show();
            }



            ISyntaxAnalyser syntaxAnalyser  = new AscendingAnalys();
            ISyntaxAnalyser syntaxAnalyser2 = new RecursiveDescent();


            AdapterFromOldToNewModel adapter = new AdapterFromOldToNewModel(analyser.LexemList, analyser.IdentifierList, analyser.ConstantList);


            //try
            //{

            syntaxAnalyser2.CheckSyntax(adapter.ModelLexemList);

            syntaxAnalyser.CheckSyntax(adapter.ModelLexemList);

            DijkstrasAlgorithm dijkstra = new DijkstrasAlgorithm();

            dijkstra.BuildRPN(adapter.ModelLexemList);
            ExecutingRPN.ExecutingRPN executingRPN = new ExecutingRPN.ExecutingRPN(dijkstra.OutputList);

            this.Activate();
            executingRPN.Execute();

            //}
            //    catch (Exception ex)
            //    {
            //        MessageBox.Show(ex.Message+" "+ex.Source);
            //    }
        }