示例#1
0
        public Defrule ruleBody()
        {
            Token exp = null;
            Token rulecomment = null;
            Defrule rule;
            ArrayList dec = new ArrayList();
            ArrayList conditions = new ArrayList();
            ArrayList actions = new ArrayList();
            exp = mcc_consume_token(IDENTIFIER);
            if (mcc_2_12(2147483647))
            {
                rulecomment = mcc_consume_token(STRING_LITERAL);
            }
            else
            {
                ;
            }
            if (mcc_2_13(2147483647))
            {
                ruleDeclaration(dec);
            }
            else
            {
                ;
            }
            switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
            {
                case LBRACE:
                case BIND:
                    while (true)
                    {
                        conditionElement(conditions);
                        switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                        {
                            case LBRACE:
                            case BIND:
                                ;
                                break;
                            default:
                                mcc_la1[32] = mcc_gen;
                                goto label_17;
                        }
                    }
                    label_17:
                    ;

                    break;
                default:
                    mcc_la1[33] = mcc_gen;
                    ;
                    break;
            }
            arrow();
            ruleActions(actions);
            rule = new Defrule(exp.image);
            if (rulecomment != null)
            {
                rule.Comment = rulecomment.image;
            }
            rule.setRuleProperties(dec);
            IEnumerator itrC = conditions.GetEnumerator();
            while (itrC.MoveNext())
            {
                rule.addCondition((ICondition) itrC.Current);
            }

            IEnumerator itr = actions.GetEnumerator();
            while (itr.MoveNext())
            {
                Object acn = itr.Current;
                if (acn is IFunction)
                {
                    FunctionAction faction = new FunctionAction();
                    faction.Function = (IFunction) acn;
                    rule.addAction(faction);
                }
                else if (acn is IAction)
                {
                    rule.addAction((IAction) acn);
                }
            }
            dec.Clear();
            conditions.Clear();
            actions.Clear();
            exp = null;
            {
                if (true) return rule;
            }
            throw new Exception("Missing return statement in function");
        }
示例#2
0
        public Defrule ruleBody()
        {
            Token exp = null;
            Token rulecomment = null;
            Defrule rule;
            IList dec = new ArrayList();
            IList conditions = new ArrayList();
            IList actions = new ArrayList();
            exp = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER);
            if (jj_2_12(2147483647))
            {
                rulecomment = jj_consume_token(CLIPSParserConstants_Fields.STRING_LITERAL);
            }
            else
            {
                ;
            }
            if (jj_2_13(2147483647))
            {
                ruleDeclaration(dec);
            }
            else
            {
                ;
            }
            switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
            {
                case CLIPSParserConstants_Fields.LBRACE:
                case CLIPSParserConstants_Fields.BIND:
                    while (true)
                    {
                        conditionElement(conditions);
                        switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                        {
                            case CLIPSParserConstants_Fields.LBRACE:
                            case CLIPSParserConstants_Fields.BIND:
                                ;
                                break;

                            default:
                                jj_la1[32] = jj_gen;
                                //UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1012"'
                                goto label_17_brk;
                        }
                    }
                    //UPGRADE_NOTE: Label 'label_17_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"'
                    label_17_brk:
                    ;

                    break;

                default:
                    jj_la1[33] = jj_gen;
                    ;
                    break;
            }
            arrow();
            ruleActions(actions);
            rule = new Defrule(exp.image);
            if (rulecomment != null)
            {
                rule.Comment = rulecomment.image;
            }
            rule.setRuleProperties(dec);
            IEnumerator itr = conditions.GetEnumerator();
            while (itr.MoveNext())
            {
                rule.addCondition((ICondition) itr.Current);
            }

            itr = actions.GetEnumerator();
            while (itr.MoveNext())
            {
                Object acn = itr.Current;
                if (acn is IFunction)
                {
                    FunctionAction faction = new FunctionAction();
                    faction.Function = (IFunction) acn;
                    rule.addAction(faction);
                }
                else if (acn is IAction)
                {
                    rule.addAction((IAction) acn);
                }
            }
            dec.Clear();
            conditions.Clear();
            actions.Clear();
            exp = null;
            {
                if (true)
                    return rule;
            }
            throw new ApplicationException("Missing return statement in function");
        }
示例#3
0
        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);
        }