コード例 #1
0
ファイル: PrologRun.cs プロジェクト: Slesa/Poseidon
        public void Run()
        {
            var program = new Prolog.Program();
            var content = File.ReadAllText(_fileName);
            var codeSentences = GetCodeSentences(content);
            if (codeSentences == null) return;

            foreach (var sentence in codeSentences)
                program.Add(sentence);

            PrologMachine lastMachine = null;
            while (true)
            {
                Console.WriteLine("Hint.: "+_queryHint);
                Console.Write("Query: ");
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) return;

                var query = GetQuery(input);
                if (query == null) continue;

                if (input.ToLower() == ";" && lastMachine != null)
                {
                    lastMachine = Execute(lastMachine, query);
                    continue;
                }

                lastMachine = Execute(program, query);
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Slesa/Playground
        void ExecuteCode()
        {
            var codeSentences = GetCodeSentences();
            if (codeSentences == null)
                return;

            var query = GetQuery();
            if (query == null)
                return;

            var program = new Prolog.Program();
            foreach (var sentence in codeSentences)
                program.Add(sentence);

            textResult.Text = "";
            try
            {
                var machine = PrologMachine.Create(program, query);
                machine.ExecutionComplete += CodeExecuted;
                var result = machine.RunToSuccess();
                textStatus.Text = Enum.GetName(typeof(ExecutionResults), result);
            }
            catch (Exception ex)
            {
                textStatus.Text = "Error";
                textResult.Text += string.Format("Got exception: {0}", ex.Message);
                return;
            }
        }
コード例 #3
0
        protected static void SetModified(Program program)
        {
            var t = program.GetType();
            //t.GetProperty("IsModified", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            t.InvokeMember("IsModified",
                           BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetProperty |
                           BindingFlags.Instance, null, program, new object[] { true });

        }
コード例 #4
0
ファイル: PrologRun.cs プロジェクト: Slesa/Poseidon
 PrologMachine Execute(Prolog.Program program, Query query)
 {
     try
     {
         var machine = PrologMachine.Create(program, query);
         machine.ExecutionComplete += CodeExecuted;
         var result = machine.RunToSuccess();
         Console.WriteLine(Enum.GetName(typeof(ExecutionResults), result));
         return(machine);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error, got exception: {0}", ex.Message);
         return(null);
     }
 }
コード例 #5
0
ファイル: PrologRun.cs プロジェクト: Slesa/Poseidon
        public void Run()
        {
            var program       = new Prolog.Program();
            var content       = File.ReadAllText(_fileName);
            var codeSentences = GetCodeSentences(content);

            if (codeSentences == null)
            {
                return;
            }

            foreach (var sentence in codeSentences)
            {
                program.Add(sentence);
            }

            PrologMachine lastMachine = null;

            while (true)
            {
                Console.WriteLine("Hint.: " + _queryHint);
                Console.Write("Query: ");
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    return;
                }

                var query = GetQuery(input);
                if (query == null)
                {
                    continue;
                }

                if (input.ToLower() == ";" && lastMachine != null)
                {
                    lastMachine = Execute(lastMachine, query);
                    continue;
                }

                lastMachine = Execute(program, query);
            }
        }
コード例 #6
0
        private void ExecutePrologProgram(string programStr)
        {
            var lines         = programStr.Split(Environment.NewLine.ToCharArray());
            var codeSentences = new List <CodeSentence>();

            foreach (var line in lines)
            {
                codeSentences.AddRange(Prolog.Parser.Parse(line));
            }
            Prolog.Program program = new Prolog.Program();
            foreach (var codeSentence in codeSentences)
            {
                program.Add(codeSentence);
            }
            var           qw      = Parser.Parse($":-{QueryTextBox.Text}");
            Query         query   = new Query(qw[0]);
            PrologMachine machine = PrologMachine.Create(program, query);
            StringBuilder sb      = new StringBuilder();

            sb.AppendLine(machine.RunToSuccess().ToString());
            if (machine.QueryResults != null)
            {
                foreach (var v in machine.QueryResults.Variables)
                {
                    sb.AppendLine($"{v.Name} = {v.Text}");
                }
            }

            //if (machine.StackFrames != null)
            //{
            //    foreach (var v in machine.StackFrames)
            //    {
            //        sb.AppendLine(v.ToString());
            //    }
            //}
            ResultTextBox.Text = sb.ToString();
        }
コード例 #7
0
 public void Reset()
 {
     Program = new Program();
 }
コード例 #8
0
ファイル: PrologExecutor.cs プロジェクト: Slesa/Playground
 public PrologExecutor(string sentences)
 {
     _program = new Prolog.Program();
     InitializeSentences(sentences);
 }
コード例 #9
0
 private PrologHandler()
 {
     program = new Prolog.Program();
 }