/// <summary> The current implementation expects the deffact or object binding /// constriant to be first. /// </summary> public override String toPPString() { StringBuilder buf = new StringBuilder(); int start = 0; // this is a hack, but it keeps the code simple for spacing // default indent for CE is 2 spaces String pad = " "; bool obind = false; IConstraint cn = (IConstraint)constraints[0]; if (cn is BoundConstraint) { BoundConstraint bc = (BoundConstraint)cn; if (bc.IsObjectBinding) { start = 1; buf.Append(bc.toFactBindingPPString()); // since the first Constraint is a fact binding we // change the padding to 1 space pad = " "; obind = true; } } if (negated) { buf.Append(pad + "(not" + Constants.LINEBREAK); pad = " "; } buf.Append(pad + "(" + templateName + Constants.LINEBREAK); for (int idx = start; idx < constraints.Count; idx++) { IConstraint cnstr = (IConstraint)constraints[idx]; if (negated) { buf.Append(" " + cnstr.toPPString()); } else { buf.Append(cnstr.toPPString()); } } if (negated) { buf.Append(pad + ")" + Constants.LINEBREAK); pad = " "; } if (obind && !negated) { buf.Append(pad + " )" + Constants.LINEBREAK); } else { buf.Append(pad + ")" + Constants.LINEBREAK); } return(buf.ToString()); }
public void propertyType(IList list, Token identifier) { Token id = null; Object body = null; Token body2 = null; bool bval = false; LiteralConstraint vc; BoundConstraint bc; OrLiteralConstraint orc; AndLiteralConstraint andc; //UPGRADE_TODO: Field java.util was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1095"' IList andor = new ArrayList(); MultiValue mv = null; if (jj_2_26(2147483647)) { predicateFunc(list, identifier); } else if (jj_2_27(2147483647)) { body2 = jj_consume_token(CLIPSParserConstants_Fields.BIND4); if (body2 != null) { bc = new BoundConstraint(); bc.Name = identifier.image; bc.Value = body2.image.Substring(2); bc.IsMultislot = true; list.Add(bc); } } else if (jj_2_28(2147483647)) { body2 = jj_consume_token(CLIPSParserConstants_Fields.BIND); if (body2 != null) { bc = new BoundConstraint(); bc.Name = identifier.image; bc.Value = body2.image.Substring(1); list.Add(bc); } } else if (jj_2_29(2147483647)) { jj_consume_token(CLIPSParserConstants_Fields.TILDA); body2 = jj_consume_token(CLIPSParserConstants_Fields.BIND); if (body2 != null) { bc = new BoundConstraint(); bc.Name = identifier.image; bc.Value = body2.image.Substring(1); bc.Negated = true; list.Add(bc); } } else if (jj_2_30(2147483647)) { body = typeExpr(); while (true) { jj_consume_token(CLIPSParserConstants_Fields.OR2); orType(andor); switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field) { case CLIPSParserConstants_Fields.OR2: ; break; default: jj_la1[49] = 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_24_brk; } } //UPGRADE_NOTE: Label 'label_24_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"' label_24_brk: ; if (body != null) { orc = new OrLiteralConstraint(); orc.Name = identifier.image; mv = new MultiValue(body); orc.addValue(mv); orc.addValues(andor); list.Add(orc); } } else if (jj_2_31(2147483647)) { jj_consume_token(CLIPSParserConstants_Fields.TILDA); body = typeExpr(); while (true) { jj_consume_token(CLIPSParserConstants_Fields.OR2); orType(andor); switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field) { case CLIPSParserConstants_Fields.OR2: ; break; default: jj_la1[50] = 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_25_brk; } } //UPGRADE_NOTE: Label 'label_25_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"' label_25_brk: ; if (body != null) { orc = new OrLiteralConstraint(); orc.Name = identifier.image; mv = new MultiValue(body); mv.Negated = true; orc.addValue(mv); orc.addValues(andor); list.Add(orc); } } else if (jj_2_32(2147483647)) { body = typeExpr(); while (true) { jj_consume_token(CLIPSParserConstants_Fields.AND2); andType(andor); switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field) { case CLIPSParserConstants_Fields.AND2: ; break; default: jj_la1[51] = 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_26_brk; } } //UPGRADE_NOTE: Label 'label_26_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"' label_26_brk: ; if (body != null) { andc = new AndLiteralConstraint(); andc.Name = identifier.image; mv = new MultiValue(body); andc.addValue(mv); andc.addValues(andor); list.Add(andc); } } else if (jj_2_33(2147483647)) { jj_consume_token(CLIPSParserConstants_Fields.TILDA); body = typeExpr(); while (true) { jj_consume_token(CLIPSParserConstants_Fields.AND2); andType(andor); switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field) { case CLIPSParserConstants_Fields.AND2: ; break; default: jj_la1[52] = 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_27_brk; } } //UPGRADE_NOTE: Label 'label_27_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"' label_27_brk: ; if (body != null) { andc = new AndLiteralConstraint(); andc.Name = identifier.image; mv = new MultiValue(body); mv.Negated = true; andc.addValue(mv); andc.addValues(andor); list.Add(andc); } } else if (jj_2_34(2147483647)) { jj_consume_token(CLIPSParserConstants_Fields.TILDA); body = typeExpr(); if (body != null) { vc = new LiteralConstraint(); vc.Name = identifier.image; vc.Value = body; vc.Negated = true; list.Add(vc); } } else if (jj_2_35(2147483647)) { id = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER); if (id != null) { vc = new LiteralConstraint(); vc.Name = identifier.image; vc.Value = id.image; list.Add(vc); } } else if (jj_2_36(2147483647)) { jj_consume_token(CLIPSParserConstants_Fields.TILDA); id = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER); if (id != null) { vc = new LiteralConstraint(); vc.Name = identifier.image; vc.Value = id.image; vc.Negated = true; list.Add(vc); } } else { switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field) { case CLIPSParserConstants_Fields.INTEGER_LITERAL: case CLIPSParserConstants_Fields.FLOATING_POINT_LITERAL: case CLIPSParserConstants_Fields.STRING_LITERAL: case CLIPSParserConstants_Fields.PATH_LITERAL: body = typeExpr(); if (body != null) { vc = new LiteralConstraint(); vc.Name = identifier.image; vc.Value = body; list.Add(vc); } break; case CLIPSParserConstants_Fields.TRUE: case CLIPSParserConstants_Fields.TRUE2: case CLIPSParserConstants_Fields.FALSE: case CLIPSParserConstants_Fields.FALSE2: bval = trueFalse(); vc = new LiteralConstraint(); vc.Name = identifier.image; vc.Value = bval; list.Add(vc); break; default: jj_la1[53] = jj_gen; jj_consume_token(- 1); throw new ParseException(); } } }
public void conditionElement(IList list) { Token exp; if (jj_2_23(2147483647)) { exp = jj_consume_token(CLIPSParserConstants_Fields.BIND); jj_consume_token(CLIPSParserConstants_Fields.ASSIGN); jj_consume_token(CLIPSParserConstants_Fields.LBRACE); CEType(list); jj_consume_token(CLIPSParserConstants_Fields.RBRACE); ObjectCondition oc = (ObjectCondition) list[list.Count - 1]; BoundConstraint bc = new BoundConstraint(oc.TemplateName, true); bc.Value = exp.image.Substring(1); oc.addConstraint(bc, 0); } else { switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field) { case CLIPSParserConstants_Fields.LBRACE: jj_consume_token(CLIPSParserConstants_Fields.LBRACE); CEType(list); jj_consume_token(CLIPSParserConstants_Fields.RBRACE); break; default: jj_la1[36] = jj_gen; jj_consume_token(- 1); throw new ParseException(); } } }
// conditionalElement checks for object binding public void conditionElement(ArrayList list) { Token exp; if (mcc_2_23(2147483647)) { exp = mcc_consume_token(BIND); mcc_consume_token(ASSIGN); mcc_consume_token(LBRACE); CEType(list); mcc_consume_token(RBRACE); ObjectCondition oc = (ObjectCondition) list[list.Count - 1]; BoundConstraint bc = new BoundConstraint(oc.TemplateName, true); bc.Value = exp.image.Substring(1); oc.addConstraint(bc, 0); } else { switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk) { case LBRACE: mcc_consume_token(LBRACE); CEType(list); mcc_consume_token(RBRACE); break; default: mcc_la1[36] = mcc_gen; mcc_consume_token(-1); throw new ParseException(); } } }
public void propertyType(ArrayList list, Token identifier) { Token id = null; Object body = null; Token body2 = null; bool bval = false; LiteralConstraint vc; BoundConstraint bc; OrLiteralConstraint orc; AndLiteralConstraint andc; ArrayList andor = new ArrayList(); MultiValue mv = null; if (mcc_2_26(2147483647)) { predicateFunc(list, identifier); } else if (mcc_2_27(2147483647)) { body2 = mcc_consume_token(BIND4); if (body2 != null) { bc = new BoundConstraint(); bc.Name = identifier.image; bc.Value = body2.image.Substring(2); bc.IsMultislot = true; list.Add(bc); } } else if (mcc_2_28(2147483647)) { body2 = mcc_consume_token(BIND); if (body2 != null) { bc = new BoundConstraint(); bc.Name = identifier.image; bc.Value = body2.image.Substring(1); list.Add(bc); } } else if (mcc_2_29(2147483647)) { mcc_consume_token(TILDA); body2 = mcc_consume_token(BIND); if (body2 != null) { bc = new BoundConstraint(); bc.Name = identifier.image; bc.Value = body2.image.Substring(1); bc.Negated = true; list.Add(bc); } } else if (mcc_2_30(2147483647)) { body = typeExpr(); while (true) { mcc_consume_token(OR2); orType(andor); switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk) { case OR2: ; break; default: mcc_la1[51] = mcc_gen; goto label_25; } } label_25: ; if (body != null) { orc = new OrLiteralConstraint(); orc.Name = identifier.image; mv = new MultiValue(body); orc.addValue(mv); orc.addValues(andor); list.Add(orc); } } else if (mcc_2_31(2147483647)) { mcc_consume_token(TILDA); body = typeExpr(); while (true) { mcc_consume_token(OR2); orType(andor); switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk) { case OR2: ; break; default: mcc_la1[52] = mcc_gen; goto label_26; } } label_26: ; if (body != null) { orc = new OrLiteralConstraint(); orc.Name = identifier.image; mv = new MultiValue(body); mv.Negated = true; orc.addValue(mv); orc.addValues(andor); list.Add(orc); } } else if (mcc_2_32(2147483647)) { body = bindTypeExpr(); while (true) { mcc_consume_token(AND2); andType(andor); switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk) { case AND2: ; break; default: mcc_la1[53] = mcc_gen; goto label_27; } } label_27: ; if (body != null) { if (body is String && ((String) body).StartsWith("?")) { bc = new BoundConstraint(); bc.Name = identifier.image; bc.Value = ((String) body).Substring(1); bc.IntraFactJoin = true; bc.addIntrFactJoin(andor); list.Add(bc); } else { andc = new AndLiteralConstraint(); andc.Name = identifier.image; mv = new MultiValue(body); andc.addValue(mv); andc.addValues(andor); list.Add(andc); } } } else if (mcc_2_33(2147483647)) { mcc_consume_token(TILDA); body = typeExpr(); while (true) { mcc_consume_token(AND2); andType(andor); switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk) { case AND2: ; break; default: mcc_la1[54] = mcc_gen; goto label_28; } } label_28: ; if (body != null) { andc = new AndLiteralConstraint(); andc.Name = identifier.image; mv = new MultiValue(body); mv.Negated = true; andc.addValue(mv); andc.addValues(andor); list.Add(andc); } } else if (mcc_2_34(2147483647)) { mcc_consume_token(TILDA); body = typeExpr(); if (body != null) { vc = new LiteralConstraint(); vc.Name = identifier.image; vc.Value = body; vc.Negated = true; list.Add(vc); } } else if (mcc_2_35(2147483647)) { id = mcc_consume_token(IDENTIFIER); if (id != null) { vc = new LiteralConstraint(); vc.Name = identifier.image; vc.Value = id.image; list.Add(vc); } } else if (mcc_2_36(2147483647)) { mcc_consume_token(TILDA); id = mcc_consume_token(IDENTIFIER); if (id != null) { vc = new LiteralConstraint(); vc.Name = identifier.image; vc.Value = id.image; vc.Negated = true; list.Add(vc); } } else { switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk) { case INTEGER_LITERAL: case FLOATING_POINT_LITERAL: case STRING_LITERAL: case PATH_LITERAL: body = typeExpr(); if (body != null) { vc = new LiteralConstraint(); vc.Name = identifier.image; vc.Value = body; list.Add(vc); } break; case TRUE: case TRUE2: case FALSE: case FALSE2: bval = trueFalse(); vc = new LiteralConstraint(); vc.Name = identifier.image; vc.Value = Convert.ToBoolean(bval); list.Add(vc); break; default: mcc_la1[55] = mcc_gen; mcc_consume_token(-1); throw new ParseException(); } } }
// need to enhance to handling bindings public void andType(ArrayList list) { Token body = null; Object val = null; MultiValue mv = null; BoundConstraint bc; if (mcc_2_39(2147483647)) { body = mcc_consume_token(IDENTIFIER); if (body != null) { mv = new MultiValue(body.image); list.Add(mv); } } else if (mcc_2_40(2147483647)) { mcc_consume_token(TILDA); val = typeExpr(); if (val != null) { mv = new MultiValue(val, true); list.Add(mv); } } else { switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk) { case BIND: // a binding ?bind body = mcc_consume_token(BIND); bc = new BoundConstraint(); bc.Value = body.image.Substring(1); list.Add(bc); break; case TILDA: mcc_consume_token(TILDA); body = mcc_consume_token(BIND); bc = new BoundConstraint(); bc.Value = body.image.Substring(1); bc.Negated = true; list.Add(bc); break; case INTEGER_LITERAL: case FLOATING_POINT_LITERAL: case STRING_LITERAL: case PATH_LITERAL: val = typeExpr(); if (val != null) { mv = new MultiValue(val); list.Add(mv); } break; default: mcc_la1[56] = mcc_gen; mcc_consume_token(-1); throw new ParseException(); } } }
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); }
/// <summary> /// method creates Bindings from the bound constraint and adds them to /// the Rule. /// </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(BoundConstraint cnstr, ITemplate templ, Rule.IRule rule, int position) { BaseAlpha2 current = null; if (rule.getBinding(cnstr.VariableName) == null) { // if the HashMap doesn't already contain the binding, we create // a new one if (cnstr.IsObjectBinding) { Binding bind = new Binding(); bind.VarName = cnstr.VariableName; bind.LeftRow = position; bind.LeftIndex = - 1; bind.IsObjectVar = true; rule.addBinding(cnstr.VariableName, bind); } else { Binding bind = new Binding(); bind.VarName = cnstr.VariableName; bind.LeftRow = position; bind.LeftIndex = templ.getSlot(cnstr.Name).Id; bind.RowDeclared = position; cnstr.FirstDeclaration = true; rule.addBinding(cnstr.VariableName, bind); } } return current; }