Esempio n. 1
0
 public bool RunMachine()
 {
     DFA dfa = new DFA (this);
     return dfa.RunMachine ();
 }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            bool help = false;
            bool adfa = false;
            bool anfa = false;
            bool gram = false;
            string filename = null;
            string input = null;

            Header ();

            try {
            for (int i = 0; i < args.Length - 2; i++ ) {
                switch (args [i]) {
                case "--dfa":
                    adfa = true;
                    filename = args [i+1];
                    input = args [i+2];
                    break;
                case "--nfa":
                    anfa = true;
                    filename = args [i+1];
                    input = args [i+2];
                    break;
                case "--gra":
                    gram = true;
                    filename = args [i+1];
                    input = args [i+2];
                    break;
                case "-h":
                case "--help":
                    help = true;
                    break;
                }
            }
            } catch (Exception e) {
            Console.WriteLine ("Error: " + e.ToString ());
            }

            if (help)
            Help ();

            if (adfa) {
            IFA fa = new DFA (filename, input);
            Console.WriteLine ("Input: {0} was {1} by the DFA",
                input == ""? "epsilon" : input,
                fa.RunMachine ()? "accepted" : "not accepted");
            } else if (anfa) {

            IFA fa = new NFA (filename, input);
            Console.WriteLine ("Input: {0} was {1} by the NFA",
                input == ""? "epsilon" : input,
                fa.RunMachine ()? "accepted" : "not accepted");
            } else if (gram) {
            RegGram rg = new RegGram (filename, input);
            Console.WriteLine ("Input: {0} was {1} by the grammar",
                input == ""? "epsilon" : input,
                rg.RunMachine ()? "accepted" : "not accepted");
            } else
            Help ();
        }