📄 cstrnpsr.c
字号:
CONSTRAINT_PARSE_RECORD *pc; CONSTRAINT_RECORD *cdst,*csrc; { if (pc->type == 0) { cdst->anyAllowed = csrc->anyAllowed; cdst->symbolsAllowed = csrc->symbolsAllowed; cdst->stringsAllowed = csrc->stringsAllowed; cdst->floatsAllowed = csrc->floatsAllowed; cdst->integersAllowed = csrc->integersAllowed; cdst->instanceNamesAllowed = csrc->instanceNamesAllowed; cdst->instanceAddressesAllowed = csrc->instanceAddressesAllowed; cdst->externalAddressesAllowed = csrc->externalAddressesAllowed; cdst->factAddressesAllowed = csrc->factAddressesAllowed; } if (pc->range == 0) { ReturnExpression(cdst->minValue); ReturnExpression(cdst->maxValue); cdst->minValue = CopyExpression(csrc->minValue); cdst->maxValue = CopyExpression(csrc->maxValue); } if (pc->allowedValues == 0) { if ((pc->allowedSymbols == 0) && (pc->allowedStrings == 0) && (pc->allowedLexemes == 0) && (pc->allowedIntegers == 0) && (pc->allowedFloats == 0) && (pc->allowedNumbers == 0) && (pc->allowedInstanceNames == 0)) { cdst->anyRestriction = csrc->anyRestriction; cdst->symbolRestriction = csrc->symbolRestriction; cdst->stringRestriction = csrc->stringRestriction; cdst->floatRestriction = csrc->floatRestriction; cdst->integerRestriction = csrc->integerRestriction; cdst->instanceNameRestriction = csrc->instanceNameRestriction; cdst->restrictionList = CopyExpression(csrc->restrictionList); } else { if ((pc->allowedSymbols == 0) && csrc->symbolRestriction) { cdst->symbolRestriction = 1; AddToRestrictionList(SYMBOL,cdst,csrc); } if ((pc->allowedStrings == 0) && csrc->stringRestriction) { cdst->stringRestriction = 1; AddToRestrictionList(STRING,cdst,csrc); } if ((pc->allowedLexemes == 0) && csrc->symbolRestriction && csrc->stringRestriction) { cdst->symbolRestriction = 1; cdst->stringRestriction = 1; AddToRestrictionList(SYMBOL,cdst,csrc); AddToRestrictionList(STRING,cdst,csrc); } if ((pc->allowedIntegers == 0) && csrc->integerRestriction) { cdst->integerRestriction = 1; AddToRestrictionList(INTEGER,cdst,csrc); } if ((pc->allowedFloats == 0) && csrc->floatRestriction) { cdst->floatRestriction = 1; AddToRestrictionList(FLOAT,cdst,csrc); } if ((pc->allowedNumbers == 0) && csrc->integerRestriction && csrc->floatRestriction) { cdst->integerRestriction = 1; cdst->floatRestriction = 1; AddToRestrictionList(INTEGER,cdst,csrc); AddToRestrictionList(FLOAT,cdst,csrc); } if ((pc->allowedInstanceNames == 0) && csrc->instanceNameRestriction) { cdst->instanceNameRestriction = 1; AddToRestrictionList(INSTANCE_NAME,cdst,csrc); } } } if (pc->cardinality == 0) { ReturnExpression(cdst->minFields); ReturnExpression(cdst->maxFields); cdst->minFields = CopyExpression(csrc->minFields); cdst->maxFields = CopyExpression(csrc->maxFields); } }/**********************************************//* OverlayConstraintParseRecord: Performs a *//* field-wise "or" of the destination parse *//* record with the source parse record. *//**********************************************/globle VOID OverlayConstraintParseRecord(dst,src) CONSTRAINT_PARSE_RECORD *dst,*src; { if (src->type) dst->type = CLIPS_TRUE; if (src->range) dst->range = CLIPS_TRUE; if (src->allowedSymbols) dst->allowedSymbols = CLIPS_TRUE; if (src->allowedStrings) dst->allowedStrings = CLIPS_TRUE; if (src->allowedLexemes) dst->allowedLexemes = CLIPS_TRUE; if (src->allowedIntegers) dst->allowedIntegers = CLIPS_TRUE; if (src->allowedFloats) dst->allowedFloats = CLIPS_TRUE; if (src->allowedNumbers) dst->allowedNumbers = CLIPS_TRUE; if (src->allowedValues) dst->allowedValues = CLIPS_TRUE; if (src->allowedInstanceNames) dst->allowedInstanceNames = CLIPS_TRUE; if (src->cardinality) dst->cardinality = CLIPS_TRUE; }/************************************************************//* AddToRestrictionList: Prepends atoms of the specified *//* type from the source restriction list to the destination *//************************************************************/static VOID AddToRestrictionList(type,cdst,csrc) int type; CONSTRAINT_RECORD *cdst,*csrc; { struct expr *exp,*tmp; for (exp = csrc->restrictionList; exp != NULL; exp = exp->nextArg) { if (exp->type == type) { tmp = GenConstant(exp->type,exp->value); tmp->nextArg = cdst->restrictionList; cdst->restrictionList = tmp; } } } /*******************************************************************//* ParseAllowedValuesAttribute: Parses the allowed-... attributes. *//*******************************************************************/static BOOLEAN ParseAllowedValuesAttribute(readSource,constraintName, constraints,parsedConstraints) char *readSource; char *constraintName; CONSTRAINT_RECORD *constraints; CONSTRAINT_PARSE_RECORD *parsedConstraints; { struct token inputToken; int expectedType, error = CLIPS_FALSE; struct expr *newValue, *lastValue; int constantParsed = CLIPS_FALSE, variableParsed = CLIPS_FALSE; char *tempPtr; /*======================================================*/ /* The allowed-values attribute is not allowed if other */ /* allowed-... attributes have already been parsed. */ /*======================================================*/ if ((strcmp(constraintName,"allowed-values") == 0) && ((parsedConstraints->allowedSymbols) || (parsedConstraints->allowedStrings) || (parsedConstraints->allowedLexemes) || (parsedConstraints->allowedIntegers) || (parsedConstraints->allowedFloats) || (parsedConstraints->allowedNumbers) || (parsedConstraints->allowedInstanceNames))) { if (parsedConstraints->allowedSymbols) tempPtr = "allowed-symbols"; else if (parsedConstraints->allowedStrings) tempPtr = "allowed-strings"; else if (parsedConstraints->allowedLexemes) tempPtr = "allowed-lexemes"; else if (parsedConstraints->allowedIntegers) tempPtr = "allowed-integers"; else if (parsedConstraints->allowedFloats) tempPtr = "allowed-floats"; else if (parsedConstraints->allowedNumbers) tempPtr = "allowed-numbers"; else if (parsedConstraints->allowedInstanceNames) tempPtr = "allowed-instance-names"; NoConjunctiveUseError("allowed-values",tempPtr); return(CLIPS_FALSE); } /*=======================================================*/ /* The allowed-values/numbers/integers/floats attributes */ /* are not allowed with the range attribute. */ /*=======================================================*/ if (((strcmp(constraintName,"allowed-values") == 0) || (strcmp(constraintName,"allowed-numbers") == 0) || (strcmp(constraintName,"allowed-integers") == 0) || (strcmp(constraintName,"allowed-floats") == 0)) && (parsedConstraints->range)) { NoConjunctiveUseError(constraintName,"range"); return(CLIPS_FALSE); } /*===================================================*/ /* The allowed-... attributes are not allowed if the */ /* allowed-values attribute has already been parsed. */ /*===================================================*/ if ((strcmp(constraintName,"allowed-values") != 0) && (parsedConstraints->allowedValues)) { NoConjunctiveUseError(constraintName,"allowed-values"); return(CLIPS_FALSE); } /*==================================================*/ /* The allowed-numbers attribute is not allowed if */ /* the allowed-integers or allowed-floats attribute */ /* has already been parsed. */ /*==================================================*/ if ((strcmp(constraintName,"allowed-numbers") == 0) && ((parsedConstraints->allowedFloats) || (parsedConstraints->allowedIntegers))) { if (parsedConstraints->allowedFloats) tempPtr = "allowed-floats"; else tempPtr = "allowed-integers"; NoConjunctiveUseError("allowed-numbers",tempPtr); return(CLIPS_FALSE); } /*============================================================*/ /* The allowed-integers/floats attributes are not allowed if */ /* the allowed-numbers attribute has already been parsed. */ /*============================================================*/ if (((strcmp(constraintName,"allowed-integers") == 0) || (strcmp(constraintName,"allowed-floats") == 0)) && (parsedConstraints->allowedNumbers)) { NoConjunctiveUseError(constraintName,"allowed-number"); return(CLIPS_FALSE); } /*==================================================*/ /* The allowed-lexemes attribute is not allowed if */ /* the allowed-symbols or allowed-strings attribute */ /* has already been parsed. */ /*==================================================*/ if ((strcmp(constraintName,"allowed-lexemes") == 0) && ((parsedConstraints->allowedSymbols) || (parsedConstraints->allowedStrings))) { if (parsedConstraints->allowedSymbols) tempPtr = "allowed-symbols"; else tempPtr = "allowed-strings"; NoConjunctiveUseError("allowed-lexemes",tempPtr); return(CLIPS_FALSE); } /*===========================================================*/ /* The allowed-symbols/strings attributes are not allowed if */ /* the allowed-lexemes attribute has already been parsed. */ /*===========================================================*/ if (((strcmp(constraintName,"allowed-symbols") == 0) || (strcmp(constraintName,"allowed-strings") == 0)) && (parsedConstraints->allowedLexemes)) { NoConjunctiveUseError(constraintName,"allowed-lexemes"); return(CLIPS_FALSE); } /*========================*/ /* Get the expected type. */ /*========================*/ expectedType = GetConstraintTypeFromAllowedName(constraintName); SetRestrictionFlag(expectedType,constraints,CLIPS_TRUE); /*=================================================*/ /* Get the last value in the restriction list (the */ /* allowed values will be appended there). */ /*=================================================*/ lastValue = constraints->restrictionList; if (lastValue != NULL) { while (lastValue->nextArg != NULL) lastValue = lastValue->nextArg; } /*==================================================*/ /* Read the allowed values and add them to the list */ /* until a right parenthesis is encountered. */ /*==================================================*/ SavePPBuffer(" "); GetToken(readSource,&inputToken); while (inputToken.type != RPAREN) { SavePPBuffer(" "); /*=============================================*/ /* Determine the type of the token just parsed */ /* and if it is an appropriate value. */ /*=============================================*/ switch(inputToken.type) { case INTEGER: if ((expectedType != UNKNOWN_VALUE) && (expectedType != INTEGER) && (expectedType != INTEGER_OR_FLOAT)) error = CLIPS_TRUE; constantParsed = CLIPS_TRUE; break; case FLOAT: if ((expectedType != UNKNOWN_VALUE) && (expectedType != FLOAT) && (expectedType != INTEGER_OR_FLOAT)) error = CLIPS_TRUE; constantParsed = CLIPS_TRUE; break; case STRING: if ((expectedType != UNKNOWN_VALUE) && (expectedType != STRING) && (expectedType != SYMBOL_OR_STRING)) error = CLIPS_TRUE; constantParsed = CLIPS_TRUE; break; case SYMBOL: if ((expectedType != UNKNOWN_VALUE) && (expectedType != SYMBOL) && (expectedType != SYMBOL_OR_STRING)) error = CLIPS_TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -