protected void parse(Rete engine, CLIPSParser parser, IList factlist) { Object itm = null; try { while ((itm = parser.basicExpr()) != null) { // System.Console.WriteLine("obj is " + itm.getClass().Name); if (itm is Defrule) { Defrule rule = (Defrule) itm; engine.RuleCompiler.addRule(rule); } else if (itm is Deftemplate) { Deftemplate dt = (Deftemplate) itm; Console.WriteLine("template=" + dt.Name); engine.declareTemplate(dt); } else if (itm is FunctionAction) { FunctionAction fa = (FunctionAction) itm; } else if (itm is IFunction) { IReturnVector rv = ((IFunction) itm).executeFunction(engine, null); IEnumerator itr = rv.Iterator; while (itr.MoveNext()) { IReturnValue rval = (IReturnValue) itr.Current; Console.WriteLine(rval.StringValue); } } } } catch { // Console.WriteLine(e.Message); parser.ReInit(Console.OpenStandardInput()); } }
/// <summary> /// method does the actual work of creating a CLIPSParser and parsing /// the file. /// </summary> /// <param name="engine">The engine.</param> /// <param name="ins">The ins.</param> /// <param name="rv">The rv.</param> public virtual void parse(Rete engine, Stream ins, DefaultReturnVector rv) { try { CLIPSParser parser = new CLIPSParser(engine, ins); Object expr = null; while ((expr = parser.basicExpr()) != null) { if (expr is Defrule) { Defrule rl = (Defrule) expr; engine.RuleCompiler.addRule(rl); } else if (expr is Deftemplate) { Deftemplate dft = (Deftemplate) expr; engine.CurrentFocus.addTemplate(dft, engine, engine.WorkingMemory); } else if (expr is IFunction) { IFunction fnc = (IFunction) expr; fnc.executeFunction(engine, null); } } if (rv != null) { rv.addReturnValue(new DefaultReturnValue(Constants.BOOLEAN_OBJECT, true)); } } catch (ParseException e) { engine.writeMessage(e.Message + Constants.LINEBREAK, Constants.DEFAULT_OUTPUT); } }
public virtual IReturnVector eval(Rete engine, String command) { IReturnVector result = null; try { CLIPSParser parser = new CLIPSParser(engine, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(command))); CLIPSInterpreter interpreter = new CLIPSInterpreter(engine); Object expr = null; while ((expr = parser.basicExpr()) != null) { result = interpreter.executeCommand(expr); } } catch (ParseException e) { // we should report the error Trace.WriteLine(e.Message); } return result; }