📄 default.c
字号:
{ return(AddDouble((double) ValueToLong(theConstraints->minValue->value))); } else if (theConstraints->maxValue->type == FLOAT) { return(theConstraints->maxValue->value); } else if (theConstraints->maxValue->type == INTEGER) { return(AddDouble((double) ValueToLong(theConstraints->maxValue->value))); } } /*======================================*/ /* Use the standard default value (such */ /* as nil if symbols are allowed). */ /*======================================*/ return(standardDefault); } #if (! RUN_TIME) && (! BLOAD_ONLY)/**********************************************//* ParseDefault: Parses a default value list. *//**********************************************/globle struct expr *ParseDefault(readSource,multifield,dynamic,evalStatic, noneSpecified,deriveSpecified,error) char *readSource; int multifield; int dynamic,evalStatic; int *noneSpecified,*deriveSpecified; int *error; { struct expr *defaultList = NULL, *lastDefault = NULL; struct expr *newItem, *tmpItem; struct token theToken; DATA_OBJECT theValue; CONSTRAINT_RECORD *rv; int specialVarCode; *noneSpecified = CLIPS_FALSE; *deriveSpecified = CLIPS_FALSE; SavePPBuffer(" "); GetToken(readSource,&theToken); /*===================================================*/ /* Read the items contained in the default attribute */ /* until a closing right parenthesis is encountered. */ /*===================================================*/ while (theToken.type != RPAREN) { /*========================================*/ /* Get the next item in the default list. */ /*========================================*/ newItem = ParseAtomOrExpression(readSource,&theToken); if (newItem == NULL) { ReturnExpression(defaultList); *error = CLIPS_TRUE; return(NULL); } /*===========================================================*/ /* Check for invalid variable usage. With the expection of */ /* ?NONE for the default attribute, local variables may not */ /* be used within the default or default-dynamic attributes. */ /*===========================================================*/ if ((newItem->type == SF_VARIABLE) || (newItem->type == MF_VARIABLE)) { if (strcmp(ValueToString(newItem->value),"NONE") == 0) { specialVarCode = 0; } else if (strcmp(ValueToString(newItem->value),"DERIVE") == 0) { specialVarCode = 1; } else { specialVarCode = -1; } if ((dynamic) || (newItem->type == MF_VARIABLE) || (specialVarCode == -1) || ((specialVarCode != -1) && (defaultList != NULL))) { if (dynamic) SyntaxErrorMessage("default-dynamic attribute"); else SyntaxErrorMessage("default attribute"); ReturnExpression(newItem); ReturnExpression(defaultList); *error = CLIPS_TRUE; return(NULL); } ReturnExpression(newItem); /*============================================*/ /* Check for the closing right parenthesis of */ /* the default or default dynamic attribute. */ /*============================================*/ GetToken(readSource,&theToken); if (theToken.type != RPAREN) { if (dynamic) SyntaxErrorMessage("default-dynamic attribute"); else SyntaxErrorMessage("default attribute"); PPBackup(); SavePPBuffer(" "); SavePPBuffer(theToken.printForm); *error = CLIPS_TRUE; } if (specialVarCode == 0) *noneSpecified = CLIPS_TRUE; else *deriveSpecified = CLIPS_TRUE; return(NULL); } /*====================================================*/ /* Look to see if any variables have been used within */ /* expressions contained within the default list. */ /*====================================================*/ if (ExpressionContainsVariables(newItem,FALSE) == TRUE) { ReturnExpression(defaultList); ReturnExpression(newItem); *error = TRUE; if (dynamic) SyntaxErrorMessage("default-dynamic attribute"); else SyntaxErrorMessage("default attribute"); return(NULL); } /*============================================*/ /* Add the default value to the default list. */ /*============================================*/ if (lastDefault == NULL) { defaultList = newItem; } else { lastDefault->nextArg = newItem; } lastDefault = newItem; /*=======================================*/ /* Begin parsing the next default value. */ /*=======================================*/ SavePPBuffer(" "); GetToken(readSource,&theToken); } /*=====================================*/ /* Fix up pretty print representation. */ /*=====================================*/ PPBackup(); PPBackup(); SavePPBuffer(")"); /*=========================================*/ /* A single field slot's default attribute */ /* must contain a single value. */ /*=========================================*/ if (multifield == CLIPS_FALSE) { if (defaultList == NULL) { *error = CLIPS_TRUE; } else if (defaultList->nextArg != NULL) { *error = CLIPS_TRUE; } else { rv = ExpressionToConstraintRecord(defaultList); rv->multifieldsAllowed = CLIPS_FALSE; if (UnmatchableConstraint(rv)) *error = CLIPS_TRUE; RemoveConstraint(rv); } if (*error) { PrintErrorID("DEFAULT",1,CLIPS_TRUE); PrintCLIPS(WERROR,"The default value for a single field slot must be a single field value\n"); ReturnExpression(defaultList); return(NULL); } } /*=======================================================*/ /* If the dynamic-default attribute is not being parsed, */ /* evaluate the expressions to make the default value. */ /*=======================================================*/ if (dynamic || (! evalStatic) || (defaultList == NULL)) return(defaultList); tmpItem = defaultList; newItem = defaultList; defaultList = NULL; while (newItem != NULL) { SetEvaluationError(CLIPS_FALSE); if (EvaluateExpression(newItem,&theValue)) *error = CLIPS_TRUE; if ((theValue.type == MULTIFIELD) && (multifield == CLIPS_FALSE) && (*error == CLIPS_FALSE)) { PrintErrorID("DEFAULT",1,CLIPS_TRUE); PrintCLIPS(WERROR,"The default value for a single field slot must be a single field value\n"); *error = CLIPS_TRUE; } if (*error) { ReturnExpression(tmpItem); ReturnExpression(defaultList); *error = CLIPS_TRUE; return(NULL); } lastDefault = ConvertValueToExpression(&theValue); defaultList = AppendExpressions(defaultList,lastDefault); newItem = newItem->nextArg; } ReturnExpression(tmpItem); /*==========================*/ /* Return the default list. */ /*==========================*/ return(defaultList); } #endif /* (! RUN_TIME) && (! BLOAD_ONLY) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -