⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cstrnpsr.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 4 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*               CONSTRAINT PARSER MODULE              */   /*******************************************************//*************************************************************//* Purpose: Provides functions for parsing constraint        *//*   declarations.                                           *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian Donnell                                        *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _CSTRNPSR_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#if ANSI_COMPILER#include <stdlib.h>#endif#include "setup.h"#include "constant.h"#include "clipsmem.h"#include "router.h"#include "scanner.h"#include "cstrnutl.h"#include "cstrnchk.h"#include "cstrnpsr.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if (! RUN_TIME) && (! BLOAD_ONLY)#if ANSI_COMPILER   static BOOLEAN                 ParseRangeCardinalityAttribute(char *,CONSTRAINT_RECORD *,                                                      CONSTRAINT_PARSE_RECORD *,char *,int);   static BOOLEAN                 ParseTypeAttribute(char *,CONSTRAINT_RECORD *);   static VOID                    AddToRestrictionList(int,CONSTRAINT_RECORD *,                                                       CONSTRAINT_RECORD *);   static BOOLEAN                 ParseAllowedValuesAttribute(char *,char *,                                                              CONSTRAINT_RECORD *,                                                              CONSTRAINT_PARSE_RECORD *);   static int                     GetConstraintTypeFromAllowedName(char *);   static int                     GetConstraintTypeFromTypeName(char *);   static int                     GetAttributeParseValue(char *,CONSTRAINT_PARSE_RECORD *);   static VOID                    SetRestrictionFlag(int,CONSTRAINT_RECORD *,int);   static VOID                    SetParseFlag(CONSTRAINT_PARSE_RECORD *,char *);   static VOID                    NoConjunctiveUseError(char *,char *);#else   static BOOLEAN                 ParseRangeCardinalityAttribute();   static BOOLEAN                 ParseTypeAttribute();   static VOID                    AddToRestrictionList();   static BOOLEAN                 ParseAllowedValuesAttribute();   static int                     GetConstraintTypeFromAllowedName();   static int                     GetConstraintTypeFromTypeName();   static int                     GetAttributeParseValue();   static VOID                    SetRestrictionFlag();   static VOID                    SetParseFlag();   static VOID                    NoConjunctiveUseError();#endif#endif  /********************************************************************//* CheckConstraintParseConflicts: Determines if a constraint record *//*   has any conflicts in the attribute specifications. Returns     *//*   TRUE if no conflicts were detected, otherwise FALSE.           *//********************************************************************/globle BOOLEAN CheckConstraintParseConflicts(constraints)  CONSTRAINT_RECORD *constraints;  {   /*===================================================*/   /* Check to see if any of the allowed-... attributes */   /* conflict with the type attribute.                 */   /*===================================================*/      if (constraints->anyAllowed == CLIPS_TRUE)     { /* Do Nothing */ }   else if (constraints->symbolRestriction &&             (constraints->symbolsAllowed == CLIPS_FALSE))     {      AttributeConflictErrorMessage("type","allowed-symbols");      return(CLIPS_FALSE);     }   else if (constraints->stringRestriction &&             (constraints->stringsAllowed == CLIPS_FALSE))     {      AttributeConflictErrorMessage("type","allowed-strings");      return(CLIPS_FALSE);     }   else if (constraints->integerRestriction &&             (constraints->integersAllowed == CLIPS_FALSE))     {      AttributeConflictErrorMessage("type","allowed-integers/numbers");      return(CLIPS_FALSE);     }   else if (constraints->floatRestriction &&             (constraints->floatsAllowed == CLIPS_FALSE))     {               AttributeConflictErrorMessage("type","allowed-floats/numbers");      return(CLIPS_FALSE);     }   else if (constraints->instanceNameRestriction &&             (constraints->instanceNamesAllowed == CLIPS_FALSE))     {               AttributeConflictErrorMessage("type","allowed-instance-names");      return(CLIPS_FALSE);     }   else if (constraints->anyRestriction)     {      struct expr *exp;            for (exp = constraints->restrictionList;            exp != NULL;           exp = exp->nextArg)        {         if (ConstraintCheckValue(exp->type,exp->value,constraints) != NO_VIOLATION)           {            AttributeConflictErrorMessage("type","allowed-values");            return(CLIPS_FALSE);           }        }     }   /*================================================================*/   /* Check to see if range attribute conflicts with type attribute. */   /*================================================================*/   if ((constraints->maxValue != NULL) &&       (constraints->anyAllowed == CLIPS_FALSE))     {      if (((constraints->maxValue->type == INTEGER) &&          (constraints->integersAllowed == CLIPS_FALSE)) ||          ((constraints->maxValue->type == FLOAT) &&           (constraints->floatsAllowed == CLIPS_FALSE)))        {         AttributeConflictErrorMessage("type","range");         return(CLIPS_FALSE);        }     }   if ((constraints->minValue != NULL) &&        (constraints->anyAllowed == CLIPS_FALSE))     {      if (((constraints->minValue->type == INTEGER) &&          (constraints->integersAllowed == CLIPS_FALSE)) ||          ((constraints->minValue->type == FLOAT) &&           (constraints->floatsAllowed == CLIPS_FALSE)))        {         AttributeConflictErrorMessage("type","range");         return(CLIPS_FALSE);        }     }        /*=====================================================*/   /* Return TRUE to indicate no conflicts were detected. */   /*=====================================================*/      return(CLIPS_TRUE);  }  /********************************************************//* AttributeConflictErrorMessage: Generic error message *//*   for a constraint attribute conflict.               *//********************************************************/globle VOID AttributeConflictErrorMessage(attribute1,attribute2)  char *attribute1, *attribute2;  {   PrintErrorID("CSTRNPSR",1,CLIPS_TRUE);   PrintCLIPS(WERROR,"The ");   PrintCLIPS(WERROR,attribute1);   PrintCLIPS(WERROR," attribute conflicts with the ");   PrintCLIPS(WERROR,attribute2);   PrintCLIPS(WERROR," attribute.\n");  }#if (! RUN_TIME) && (! BLOAD_ONLY)/***************************************************************************//* InitializeConstraintParseRecord: Initializes the values of a constraint *//*   parse record which is used to determine whether one of the standard   *//*   constraint specifications has already been parsed.                    *//***************************************************************************/globle VOID InitializeConstraintParseRecord(parsedConstraints)  CONSTRAINT_PARSE_RECORD *parsedConstraints;  {      parsedConstraints->type = CLIPS_FALSE;   parsedConstraints->range = CLIPS_FALSE;   parsedConstraints->allowedSymbols = CLIPS_FALSE;   parsedConstraints->allowedStrings = CLIPS_FALSE;   parsedConstraints->allowedLexemes = CLIPS_FALSE;   parsedConstraints->allowedIntegers = CLIPS_FALSE;   parsedConstraints->allowedFloats = CLIPS_FALSE;   parsedConstraints->allowedNumbers = CLIPS_FALSE;   parsedConstraints->allowedValues = CLIPS_FALSE;   parsedConstraints->allowedInstanceNames = CLIPS_FALSE;   parsedConstraints->cardinality = CLIPS_FALSE;  }  /************************************************************************//* StandardConstraint: Returns TRUE if the specified name is one of the *//*   standard constraints parseable by the routines in this module.     *//************************************************************************/globle BOOLEAN StandardConstraint(constraintName)  char *constraintName;  {      if ((strcmp(constraintName,"type") == 0) ||       (strcmp(constraintName,"range") == 0) ||       (strcmp(constraintName,"cardinality") == 0) ||       (strcmp(constraintName,"allowed-symbols") == 0) ||       (strcmp(constraintName,"allowed-strings") == 0) ||       (strcmp(constraintName,"allowed-lexemes") == 0) ||       (strcmp(constraintName,"allowed-integers") == 0) ||       (strcmp(constraintName,"allowed-floats") == 0) ||       (strcmp(constraintName,"allowed-numbers") == 0) ||       (strcmp(constraintName,"allowed-instance-names") == 0) ||       (strcmp(constraintName,"allowed-values") == 0))            { return(CLIPS_TRUE); }      return(CLIPS_FALSE);  }  /***********************************************************************//* ParseStandardConstraint: Parses a standard constraint. Returns TRUE *//*   if the constraint was successfully parsed, otherwise FALSE.       *//***********************************************************************/globle BOOLEAN ParseStandardConstraint(readSource,constraintName,                                       constraints,parsedConstraints,                                       multipleValuesAllowed)  char *readSource;  char *constraintName;  CONSTRAINT_RECORD *constraints;  CONSTRAINT_PARSE_RECORD *parsedConstraints;  int multipleValuesAllowed;  {      int rv = CLIPS_FALSE;      /*=====================================================*/   /* Determine if the attribute has already been parsed. */   /*=====================================================*/      if (GetAttributeParseValue(constraintName,parsedConstraints))     {      AlreadyParsedErrorMessage(constraintName," attribute");      return(CLIPS_FALSE);     }   /*==========================================*/   /* If specified, parse the range attribute. */   /*==========================================*/      if (strcmp(constraintName,"range") == 0)      {      rv = ParseRangeCardinalityAttribute(readSource,constraints,parsedConstraints,                                          constraintName,multipleValuesAllowed);     }        /*================================================*/   /* If specified, parse the cardinality attribute. */   /*================================================*/      else if (strcmp(constraintName,"cardinality") == 0)      {      rv = ParseRangeCardinalityAttribute(readSource,constraints,parsedConstraints,                                          constraintName,multipleValuesAllowed);     }        /*=========================================*/   /* If specified, parse the type attribute. */   /*=========================================*/      else if (strcmp(constraintName,"type") == 0)      { rv = ParseTypeAttribute(readSource,constraints); }        /*================================================*/   /* If specified, parse the allowed-... attribute. */   /*================================================*/      else if ((strcmp(constraintName,"allowed-symbols") == 0) ||            (strcmp(constraintName,"allowed-strings") == 0) ||            (strcmp(constraintName,"allowed-lexemes") == 0) ||            (strcmp(constraintName,"allowed-integers") == 0) ||            (strcmp(constraintName,"allowed-floats") == 0) ||            (strcmp(constraintName,"allowed-numbers") == 0) ||            (strcmp(constraintName,"allowed-instance-names") == 0) ||            (strcmp(constraintName,"allowed-values") == 0))     {      rv = ParseAllowedValuesAttribute(readSource,constraintName,                                         constraints,parsedConstraints);     }        /*=========================================*/   /* Remember which constraint attribute was */   /* parsed and return the error status.     */   /*=========================================*/      SetParseFlag(parsedConstraints,constraintName);   return(rv);  }/***********************************************************//* OverlayConstraint: Overlays fields of source constraint *//* record on destination based on which fields are set in  *//* the parsed constraint record. Assumes AddConstraint has *//* not yet been called for the destination constraint      *//* record.                                                 *//***********************************************************/globle VOID OverlayConstraint(pc,cdst,csrc)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -