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); } }
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; } }
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 }); }
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); } }
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); } }
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(); }
public void Reset() { Program = new Program(); }
public PrologExecutor(string sentences) { _program = new Prolog.Program(); InitializeSentences(sentences); }
private PrologHandler() { program = new Prolog.Program(); }