public void predicateFunc(IList list, Token identifier) { Token varname = null; String func = null; IList params_Renamed = new ArrayList(); Token bind = null; Token val = null; varname = jj_consume_token(CLIPSParserConstants_Fields.BIND2); jj_consume_token(CLIPSParserConstants_Fields.LBRACE); func = functionName(); bind = jj_consume_token(CLIPSParserConstants_Fields.BIND); actionParams(params_Renamed); jj_consume_token(CLIPSParserConstants_Fields.RBRACE); PredicateConstraint predc = new PredicateConstraint(); predc.Name = identifier.image; predc.VariableName = varname.image.Substring(1, (varname.image.Length - 2) - (1)); predc.FunctionName = func; BoundParam bp = new BoundParam(); bp.VariableName = bind.image; predc.addParameter(bp); predc.addParameters(params_Renamed); list.Add(predc); }
public virtual int analyze(IRule rule) { int result = Analysis_Fields.VALIDATION_PASSED; error = new ErrorSummary(); warning = new WarningSummary(); checkForModule(rule); ICondition[] cnds = rule.Conditions; for (int idx = 0; idx < cnds.Length; idx++) { ICondition cnd = cnds[idx]; if (cnd is ObjectCondition) { ObjectCondition oc = (ObjectCondition)cnd; Deftemplate dft = oc.Deftemplate; if (dft != null) { IConstraint[] cntrs = oc.Constraints; for (int idy = 0; idy < cntrs.Length; idy++) { IConstraint cons = cntrs[idy]; if (cons is LiteralConstraint) { Slot sl = dft.getSlot(cons.Name); if (sl == null) { error.addMessage(INVALID_SLOT + " " + cons.Name + " slot does not exist."); result = Analysis_Fields.VALIDATION_FAILED; } } else if (cons is BoundConstraint) { BoundConstraint bc = (BoundConstraint)cons; if (!bc.isObjectBinding) { Slot sl = dft.getSlot(bc.Name); if (sl == null) { error.addMessage(INVALID_SLOT + " " + cons.Name + " slot does not exist."); result = Analysis_Fields.VALIDATION_FAILED; } } } else if (cons is PredicateConstraint) { PredicateConstraint pc = (PredicateConstraint)cons; IFunction f = engine.findFunction(pc.FunctionName); if (f == null) { addInvalidFunctionError(pc.FunctionName); } } } } else { error.addMessage(INVALID_TEMPLATE + " " + oc.TemplateName + " template does not exist."); result = Analysis_Fields.VALIDATION_FAILED; } } else if (cnd is TestCondition) { TestCondition tc = (TestCondition)cnd; if (tc.Function == null) { error.addMessage(NO_FUNCTION); result = Analysis_Fields.VALIDATION_FAILED; } else { IFunction f = tc.Function; if (engine.findFunction(f.Name) == null) { addInvalidFunctionError(f.Name); result = Analysis_Fields.VALIDATION_FAILED; } } } else if (cnd is ExistCondition) { } } // now we check the Right-hand side IAction[] acts = rule.Actions; for (int idx = 0; idx < acts.Length; idx++) { IAction act = acts[idx]; if (act is FunctionAction) { FunctionAction fa = (FunctionAction)act; if (engine.findFunction(fa.FunctionName) == null) { addInvalidFunctionError(fa.FunctionName); result = Analysis_Fields.VALIDATION_FAILED; } } } return(result); }
public void predicateFunc(ArrayList list, Token identifier) { Token varname = null; String func = null; ArrayList parms = new ArrayList(); Token bind = null; Token val = null; varname = mcc_consume_token(BIND2); mcc_consume_token(LBRACE); func = functionName(); bind = mcc_consume_token(BIND); actionParams(parms); mcc_consume_token(RBRACE); PredicateConstraint predc = new PredicateConstraint(); predc.Name = identifier.image; predc.VariableName = varname.image.Substring(1, varname.image.Length - 2); predc.FunctionName = func; BoundParam bp = new BoundParam(); bp.VariableName = bind.image; predc.addParameter(bp); predc.addParameters(parms); list.Add(predc); }
/// <summary> /// Compiles the constraint. /// </summary> /// <param name="cnstr">The CNSTR.</param> /// <param name="templ">The templ.</param> /// <param name="rule">The rule.</param> /// <param name="position">The position.</param> /// <returns></returns> public virtual BaseAlpha2 compileConstraint(PredicateConstraint cnstr, ITemplate templ, Rule.IRule rule, int position) { BaseAlpha2 current = null; // for now we expect the user to write the predicate in this // way (> ?bind value), where the binding is first. this // needs to be updated so that we look at the order of the // parameters and set the node appropriately // we only create an AlphaNode if the predicate isn't // joining 2 bindings. if (!cnstr.PredicateJoin) { if (ConversionUtils.isPredicateOperatorCode(cnstr.FunctionName)) { int oprCode = ConversionUtils.getOperatorCode(cnstr.FunctionName); Slot sl = (Slot) templ.getSlot(cnstr.Name).Clone(); Object sval = ConversionUtils.convert(sl.ValueType, cnstr.Value); sl.Value = sval; // create the alphaNode if (rule.RememberMatch) { current = new AlphaNode(engine.nextNodeId()); } else { current = new NoMemANode(engine.nextNodeId()); } current.Slot = sl; current.Operator = oprCode; current.incrementUseCount(); // we increment the node use count when when create a new // AlphaNode for the LiteralConstraint templ.getSlot(sl.Id).incrementNodeCount(); } else { // the function isn't a built in predicate function that // returns boolean true/false. We look up the function IFunction f = engine.findFunction(cnstr.FunctionName); if (f != null) { // we create the alphaNode if a function is found and // the return type is either boolean primitive or object if (f.ReturnType == Constants.BOOLEAN_PRIM_TYPE || f.ReturnType != Constants.BOOLEAN_OBJECT) { // TODO - need to implement it } else { // the function doesn't return boolean, so we have to notify // the listeners the condition is not valid CompileMessageEventArgs ce = new CompileMessageEventArgs(this, EventType.FUNCTION_INVALID); ce.Message = INVALID_FUNCTION + " " + f.ReturnType; //$NON-NLS-1$ notifyListener(ce); } } else { // we need to notify listeners the function wasn't found CompileMessageEventArgs ce = new CompileMessageEventArgs(this, EventType.FUNCTION_NOT_FOUND); ce.Message = FUNCTION_NOT_FOUND + " " + cnstr.FunctionName; notifyListener(ce); } } } Binding bind = new Binding(); bind.VarName = cnstr.VariableName; bind.LeftRow = position; bind.LeftIndex = templ.getSlot(cnstr.Name).Id; bind.RowDeclared = position; // we only Add the binding to the map if it doesn't already exist if (rule.getBinding(cnstr.VariableName) == null) { rule.addBinding(cnstr.VariableName, bind); } return current; }