📄 cstrnpsr.c
字号:
CONSTRAINT_PARSE_RECORD *parsedConstraints; char *constraintName; int multipleValuesAllowed; { struct token inputToken; int range; char *tempPtr; /*=================================*/ /* Determine if we're parsing the */ /* range or cardinality attribute. */ /*=================================*/ if (strcmp(constraintName,"range") == 0) { parsedConstraints->range = CLIPS_TRUE; range = CLIPS_TRUE; } else { parsedConstraints->cardinality = CLIPS_TRUE; range = CLIPS_FALSE; } /*===================================================================*/ /* The cardinality attribute can only be used with multifield slots. */ /*===================================================================*/ if ((range == CLIPS_FALSE) && (multipleValuesAllowed == CLIPS_FALSE)) { PrintErrorID("CSTRNPSR",5,CLIPS_TRUE); PrintCLIPS(WERROR,"The cardinality attribute "); PrintCLIPS(WERROR,"can only be used with multifield slots.\n"); return(CLIPS_FALSE); } /*====================================================*/ /* The range attribute is not allowed with the */ /* allowed-values/numbers/integers/floats attributes. */ /*====================================================*/ if ((range == CLIPS_TRUE) && (parsedConstraints->allowedValues || parsedConstraints->allowedNumbers || parsedConstraints->allowedIntegers || parsedConstraints->allowedFloats)) { if (parsedConstraints->allowedValues) tempPtr = "allowed-values"; else if (parsedConstraints->allowedIntegers) tempPtr = "allowed-integers"; else if (parsedConstraints->allowedFloats) tempPtr = "allowed-floats"; else if (parsedConstraints->allowedNumbers) tempPtr = "allowed-numbers"; NoConjunctiveUseError("range",tempPtr); return(CLIPS_FALSE); } /*==========================*/ /* Parse the minimum value. */ /*==========================*/ SavePPBuffer(" "); GetToken(readSource,&inputToken); if ((inputToken.type == INTEGER) || ((inputToken.type == FLOAT) && range)) { if (range) { ReturnExpression(constraints->minValue); constraints->minValue = GenConstant(inputToken.type,inputToken.value); } else { ReturnExpression(constraints->minFields); constraints->minFields = GenConstant(inputToken.type,inputToken.value); } } else if ((inputToken.type == SF_VARIABLE) && (strcmp(inputToken.printForm,"?VARIABLE") == 0)) { /* Do nothing. */ } else { char tempBuffer[120]; sprintf(tempBuffer,"%s attribute",constraintName); SyntaxErrorMessage(tempBuffer); return(CLIPS_FALSE); } /*==========================*/ /* Parse the maximum value. */ /*==========================*/ SavePPBuffer(" "); GetToken(readSource,&inputToken); if ((inputToken.type == INTEGER) || ((inputToken.type == FLOAT) && range)) { if (range) { ReturnExpression(constraints->maxValue); constraints->maxValue = GenConstant(inputToken.type,inputToken.value); } else { ReturnExpression(constraints->maxFields); constraints->maxFields = GenConstant(inputToken.type,inputToken.value); } } else if ((inputToken.type == SF_VARIABLE) && (strcmp(inputToken.printForm,"?VARIABLE") == 0)) { /* Do nothing. */ } else { char tempBuffer[120]; sprintf(tempBuffer,"%s attribute",constraintName); SyntaxErrorMessage(tempBuffer); return(CLIPS_FALSE); } /*================================*/ /* Parse the closing parenthesis. */ /*================================*/ GetToken(readSource,&inputToken); if (inputToken.type != RPAREN) { SyntaxErrorMessage("range attribute"); return(CLIPS_FALSE); } /*====================================================*/ /* Minimum value must be less than the maximum value. */ /*====================================================*/ if (range) { if (CompareNumbers(constraints->minValue->type, constraints->minValue->value, constraints->maxValue->type, constraints->maxValue->value) == GREATER_THAN) { PrintErrorID("CSTRNPSR",2,CLIPS_TRUE); PrintCLIPS(WERROR,"Minimum range value must be less than\n"); PrintCLIPS(WERROR,"or equal to the maximum range value\n"); return(CLIPS_FALSE); } } else { if (CompareNumbers(constraints->minFields->type, constraints->minFields->value, constraints->maxFields->type, constraints->maxFields->value) == GREATER_THAN) { PrintErrorID("CSTRNPSR",2,CLIPS_TRUE); PrintCLIPS(WERROR,"Minimum cardinality value must be less than\n"); PrintCLIPS(WERROR,"or equal to the maximum cardinality value\n"); return(CLIPS_FALSE); } } /*====================================*/ /* Return TRUE to indicate that the */ /* attribute was successfully parsed. */ /*====================================*/ return(CLIPS_TRUE); }/******************************************************************//* GetConstraintTypeFromAllowedName: Returns the type restriction *//* associated with an allowed-... attribute. *//******************************************************************/static int GetConstraintTypeFromAllowedName(constraintName) char *constraintName; { if (strcmp(constraintName,"allowed-values") == 0) return(UNKNOWN_VALUE); else if (strcmp(constraintName,"allowed-symbols") == 0) return(SYMBOL); else if (strcmp(constraintName,"allowed-strings") == 0) return(STRING); else if (strcmp(constraintName,"allowed-lexemes") == 0) return(SYMBOL_OR_STRING); else if (strcmp(constraintName,"allowed-integers") == 0) return(INTEGER); else if (strcmp(constraintName,"allowed-numbers") == 0) return(INTEGER_OR_FLOAT); else if (strcmp(constraintName,"allowed-instance-names") == 0) return(INSTANCE_NAME); else if (strcmp(constraintName,"allowed-floats") == 0) return(FLOAT); return(-1); } /*******************************************************//* GetConstraintTypeFromTypeName: Converts a type name *//* to its equivalent integer type restriction. *//*******************************************************/static int GetConstraintTypeFromTypeName(constraintName) char *constraintName; { if (strcmp(constraintName,"SYMBOL") == 0) return(SYMBOL); else if (strcmp(constraintName,"STRING") == 0) return(STRING); else if (strcmp(constraintName,"LEXEME") == 0) return(SYMBOL_OR_STRING); else if (strcmp(constraintName,"INTEGER") == 0) return(INTEGER); else if (strcmp(constraintName,"FLOAT") == 0) return(FLOAT); else if (strcmp(constraintName,"NUMBER") == 0) return(INTEGER_OR_FLOAT); else if (strcmp(constraintName,"INSTANCE-NAME") == 0) return(INSTANCE_NAME); else if (strcmp(constraintName,"INSTANCE-ADDRESS") == 0) return(INSTANCE_ADDRESS); else if (strcmp(constraintName,"INSTANCE") == 0) return(INSTANCE_OR_INSTANCE_NAME); else if (strcmp(constraintName,"EXTERNAL-ADDRESS") == 0) return(EXTERNAL_ADDRESS); else if (strcmp(constraintName,"FACT-ADDRESS") == 0) return(FACT_ADDRESS); return(-1); }/**************************************************************//* GetAttributeParseValue: Returns a boolean value indicating *//* whether a specific attribute has already been parsed. *//**************************************************************/static int GetAttributeParseValue(constraintName,parsedConstraints) char *constraintName; CONSTRAINT_PARSE_RECORD *parsedConstraints; { if (strcmp(constraintName,"type") == 0) { return(parsedConstraints->type); } else if (strcmp(constraintName,"range") == 0) { return(parsedConstraints->range); } else if (strcmp(constraintName,"cardinality") == 0) { return(parsedConstraints->cardinality); } else if (strcmp(constraintName,"allowed-values") == 0) { return(parsedConstraints->allowedValues); } else if (strcmp(constraintName,"allowed-symbols") == 0) { return(parsedConstraints->allowedSymbols); } else if (strcmp(constraintName,"allowed-strings") == 0) { return(parsedConstraints->allowedStrings); } else if (strcmp(constraintName,"allowed-lexemes") == 0) { return(parsedConstraints->allowedLexemes); } else if (strcmp(constraintName,"allowed-instance-names") == 0) { return(parsedConstraints->allowedInstanceNames); } else if (strcmp(constraintName,"allowed-integers") == 0) { return(parsedConstraints->allowedIntegers); } else if (strcmp(constraintName,"allowed-floats") == 0) { return(parsedConstraints->allowedFloats); } else if (strcmp(constraintName,"allowed-numbers") == 0) { return(parsedConstraints->allowedNumbers); } return(CLIPS_TRUE); } /**********************************************************//* SetRestrictionFlag: Sets the restriction flag of a *//* constraint record indicating whether a specific *//* type has an associated allowed-... restriction list. *//**********************************************************/static VOID SetRestrictionFlag(restriction,constraints,value) int restriction; CONSTRAINT_RECORD *constraints; int value; { switch (restriction) { case UNKNOWN_VALUE: constraints->anyRestriction = value; break; case SYMBOL: constraints->symbolRestriction = value; break; case STRING: constraints->stringRestriction = value; break; case INTEGER: constraints->integerRestriction = value; break; case FLOAT: constraints->floatRestriction = value; break; case INTEGER_OR_FLOAT: constraints->integerRestriction = value; constraints->floatRestriction = value; break; case SYMBOL_OR_STRING: constraints->symbolRestriction = value; constraints->stringRestriction = value; break; case INSTANCE_NAME: constraints->instanceNameRestriction = value; break; } } /********************************************************************//* SetParseFlag: Sets the flag in a parsed constraints data *//* structure indicating that a specific attribute has been parsed. *//********************************************************************/static VOID SetParseFlag(parsedConstraints,constraintName) CONSTRAINT_PARSE_RECORD *parsedConstraints; char *constraintName; { if (strcmp(constraintName,"range") == 0) { parsedConstraints->range = CLIPS_TRUE; } else if (strcmp(constraintName,"type") == 0) { parsedConstraints->type = CLIPS_TRUE; } else if (strcmp(constraintName,"cardinality") == 0) { parsedConstraints->cardinality = CLIPS_TRUE; } else if (strcmp(constraintName,"allowed-symbols") == 0) { parsedConstraints->allowedSymbols = CLIPS_TRUE; } else if (strcmp(constraintName,"allowed-strings") == 0) { parsedConstraints->allowedStrings = CLIPS_TRUE; } else if (strcmp(constraintName,"allowed-lexemes") == 0) { parsedConstraints->allowedLexemes = CLIPS_TRUE; } else if (strcmp(constraintName,"allowed-integers") == 0) { parsedConstraints->allowedIntegers = CLIPS_TRUE; } else if (strcmp(constraintName,"allowed-floats") == 0) { parsedConstraints->allowedFloats = CLIPS_TRUE; } else if (strcmp(constraintName,"allowed-numbers") == 0) { parsedConstraints->allowedNumbers = CLIPS_TRUE; } else if (strcmp(constraintName,"allowed-values") == 0) { parsedConstraints->allowedValues = CLIPS_TRUE; } } #endif /* (! RUN_TIME) && (! BLOAD_ONLY) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -