public void Start(TextReader reader, TextWriter writer) { var env = new Environment(); var macroEnv = new Environment(); while (true) { writer.Write(Prompt); var line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) { return; } var l = new Lexer.Lexer(line); var p = new Parser.Parser(l); var program = p.ParseProgram(); if (p.Errors.Any()) { PrintParserErrors(writer, p.Errors); continue; } var evaluator = new Evaluator.Evaluator(); evaluator.DefineMacros(program, macroEnv); var expanded = evaluator.ExpandMacros(program, macroEnv); var evaluated = evaluator.Eval(expanded, env); if (evaluated != null) { writer.WriteLine(evaluated.Inspect()); } } }
public MyControl() { InitializeComponent(); ev = new Evaluator.Evaluator(); RichTextBox myRichTextBox = new RichTextBox(); // Create a FlowDocument to contain content for the RichTextBox. FlowDocument myFlowDoc = new FlowDocument(); // Add initial content to the RichTextBox. Repl.Document = myFlowDoc; Repl.AppendText("> "); Repl.CaretPosition = Repl.CaretPosition.DocumentEnd; }
///<summary> ///this method iterates through each goal evaluator and selects the one ///that has the highest score as the current goal ///</summary> public void Arbitrate() { //for debugging _prevBestDesirability = _bestDesirability; _prevMostDesirable = _mostDesirable; LogUtil.WriteLineIfLogThink(LogPrefixText + LogArbitrateText + LogStatusText + " PrevDesirability = " + _prevBestDesirability.ToString(("F2")) + " PrevDesirable = " + (_prevMostDesirable == null ? "none" : _prevMostDesirable.GetType().Name)); _bestDesirability = 0.0f; _mostDesirable = null; //iterate through all the evaluators to find the highest scoring one foreach (Evaluator.Evaluator ev in _evaluators) { float desirabilty = ev.CalculateDesirability(Bot); if (desirabilty < _bestDesirability) continue; _bestDesirability = desirabilty; _mostDesirable = ev; } Assert.Fatal(_mostDesirable != null, "Think.Arbitrate: no evaluator selected"); LogUtil.WriteLineIfLogThink(LogPrefixText + LogArbitrateText + LogStatusText + " Desirability = " + _bestDesirability.ToString(("F2")) + " Desirable = " + (_mostDesirable == null ? "none" : _mostDesirable.GetType().Name)); if (_mostDesirable != null) { _mostDesirable.SetGoal(Bot); } }