📄 cstrnpsr.c
字号:
constantParsed = CLIPS_TRUE; break; #if OBJECT_SYSTEM case INSTANCE_NAME: if ((expectedType != UNKNOWN_VALUE) && (expectedType != INSTANCE_NAME)) error = CLIPS_TRUE; constantParsed = CLIPS_TRUE; break;#endif case SF_VARIABLE: if (strcmp(inputToken.printForm,"?VARIABLE") == 0) { variableParsed = CLIPS_TRUE; } else { char tempBuffer[120]; sprintf(tempBuffer,"%s attribute",constraintName); SyntaxErrorMessage(tempBuffer); return(CLIPS_FALSE); } break; default: { char tempBuffer[120]; sprintf(tempBuffer,"%s attribute",constraintName); SyntaxErrorMessage(tempBuffer); } return(CLIPS_FALSE); } /*=====================================*/ /* Signal an error if an inappropriate */ /* value was found. */ /*=====================================*/ if (error) { PrintErrorID("CSTRNPSR",4,CLIPS_TRUE); PrintCLIPS(WERROR,"Value does not match the expected type for the "); PrintCLIPS(WERROR,constraintName); PrintCLIPS(WERROR," attribute\n"); return(CLIPS_FALSE); } /*======================================*/ /* The ?VARIABLE argument can't be used */ /* in conjunction with constants. */ /*======================================*/ if (constantParsed && variableParsed) { char tempBuffer[120]; sprintf(tempBuffer,"%s attribute",constraintName); SyntaxErrorMessage(tempBuffer); return(CLIPS_FALSE); } /*===========================================*/ /* Add the constant to the restriction list. */ /*===========================================*/ newValue = GenConstant(inputToken.type,inputToken.value); if (lastValue == NULL) { constraints->restrictionList = newValue; } else { lastValue->nextArg = newValue; } lastValue = newValue; /*=======================================*/ /* Begin parsing the next allowed value. */ /*=======================================*/ GetToken(readSource,&inputToken); } /*======================================================*/ /* There must be at least one value for this attribute. */ /*======================================================*/ if ((! constantParsed) && (! variableParsed)) { char tempBuffer[120]; sprintf(tempBuffer,"%s attribute",constraintName); SyntaxErrorMessage(tempBuffer); return(CLIPS_FALSE); } /*======================================*/ /* If ?VARIABLE was parsed, then remove */ /* the restrictions for the type being */ /* restricted. */ /*======================================*/ if (variableParsed) { switch(expectedType) { case UNKNOWN_VALUE: constraints->anyRestriction = CLIPS_FALSE; break; case SYMBOL: constraints->symbolRestriction = CLIPS_FALSE; break; case STRING: constraints->stringRestriction = CLIPS_FALSE; break; case INTEGER: constraints->integerRestriction = CLIPS_FALSE; break; case FLOAT: constraints->floatRestriction = CLIPS_FALSE; break; case INTEGER_OR_FLOAT: constraints->floatRestriction = CLIPS_FALSE; constraints->integerRestriction = CLIPS_FALSE; break; case SYMBOL_OR_STRING: constraints->symbolRestriction = CLIPS_FALSE; constraints->stringRestriction = CLIPS_FALSE; break; case INSTANCE_NAME: constraints->instanceNameRestriction = CLIPS_FALSE; break; } } /*=====================================*/ /* Fix up pretty print representation. */ /*=====================================*/ PPBackup(); PPBackup(); SavePPBuffer(")"); /*=======================================*/ /* Return TRUE to indicate the attribute */ /* was successfully parsed. */ /*=======================================*/ return(CLIPS_TRUE); } /***********************************************************//* NoConjunctiveUseError: Generic error message indicating *//* that two attributes can't be used in conjunction. *//***********************************************************/static VOID NoConjunctiveUseError(attribute1,attribute2) char *attribute1; char *attribute2; { PrintErrorID("CSTRNPSR",3,CLIPS_TRUE); PrintCLIPS(WERROR,"The "); PrintCLIPS(WERROR,attribute1); PrintCLIPS(WERROR," attribute cannot be used\n"); PrintCLIPS(WERROR,"in conjunction with the "); PrintCLIPS(WERROR,attribute2); PrintCLIPS(WERROR," attribute.\n"); } /**************************************************//* ParseTypeAttribute: Parses the type attribute. *//**************************************************/static BOOLEAN ParseTypeAttribute(readSource,constraints) char *readSource; CONSTRAINT_RECORD *constraints; { int typeParsed = CLIPS_FALSE; int variableParsed = CLIPS_FALSE; int theType; struct token inputToken; /*======================================*/ /* Continue parsing types until a right */ /* parenthesis is encountered. */ /*======================================*/ SavePPBuffer(" "); for (GetToken(readSource,&inputToken); inputToken.type != RPAREN; GetToken(readSource,&inputToken)) { SavePPBuffer(" "); /*==================================*/ /* If the token is a symbol then... */ /*==================================*/ if (inputToken.type == SYMBOL) { /*==============================================*/ /* ?VARIABLE can't be used with type constants. */ /*==============================================*/ if (variableParsed == CLIPS_TRUE) { SyntaxErrorMessage("type attribute"); return(CLIPS_FALSE); } /*========================================*/ /* Check for an appropriate type constant */ /* (e.g. SYMBOL, FLOAT, INTEGER, etc.). */ /*========================================*/ theType = GetConstraintTypeFromTypeName(ValueToString(inputToken.value)); if (theType < 0) { SyntaxErrorMessage("type attribute"); return(CLIPS_FALSE); } /*==================================================*/ /* Change the type restriction flags to reflect the */ /* type restriction. If the type restriction was */ /* already specified, then a error is generated. */ /*==================================================*/ if (SetConstraintType(theType,constraints)) { SyntaxErrorMessage("type attribute"); return(CLIPS_FALSE); } constraints->anyAllowed = CLIPS_FALSE; /*===========================================*/ /* Remember that a type constant was parsed. */ /*===========================================*/ typeParsed = CLIPS_TRUE; } /*==============================================*/ /* Otherwise if the token is a variable then... */ /*==============================================*/ else if (inputToken.type == SF_VARIABLE) { /*========================================*/ /* The only variable allowd is ?VARIABLE. */ /*========================================*/ if (strcmp(inputToken.printForm,"?VARIABLE") != 0) { SyntaxErrorMessage("type attribute"); return(CLIPS_FALSE); } /*===================================*/ /* ?VARIABLE can't be used more than */ /* once or with type constants. */ /*===================================*/ if (typeParsed || variableParsed) { SyntaxErrorMessage("type attribute"); return(CLIPS_FALSE); } /*======================================*/ /* Remember that a variable was parsed. */ /*======================================*/ variableParsed = CLIPS_TRUE; } /*====================================*/ /* Otherwise this is an invalid value */ /* for the type attribute. */ /*====================================*/ else { SyntaxErrorMessage("type attribute"); return(CLIPS_FALSE); } } /*=====================================*/ /* Fix up pretty print representation. */ /*=====================================*/ PPBackup(); PPBackup(); SavePPBuffer(")"); /*=======================================*/ /* The type attribute must have a value. */ /*=======================================*/ if ((! typeParsed) && (! variableParsed)) { SyntaxErrorMessage("type attribute"); return(CLIPS_FALSE); } /*===========================================*/ /* Return TRUE indicating the type attibuted */ /* was successfully parsed. */ /*===========================================*/ return(CLIPS_TRUE); } /***************************************************************************//* ParseRangeCardinalityAttribute: Parses the range/cardinality attribute. *//***************************************************************************/static BOOLEAN ParseRangeCardinalityAttribute(readSource,constraints,parsedConstraints, constraintName,multipleValuesAllowed) char *readSource; CONSTRAINT_RECORD *constraints;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -