?? cstrnpsr.c
字號(hào):
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.24 07/01/05 */ /* */ /* CONSTRAINT PARSER MODULE */ /*******************************************************//*************************************************************//* Purpose: Provides functions for parsing constraint *//* declarations. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* Brian Donnell *//* *//* Revision History: *//* 6.23: Changed name of variable exp to theExp *//* because of Unix compiler warnings of shadowed *//* definitions. *//* *//* 6.24: Added allowed-classes slot facet. *//* *//* Renamed BOOLEAN macro type to intBool. *//* *//*************************************************************/#define _CSTRNPSR_SOURCE_#include <stdio.h>#define _STDIO_INCLUDED_#include <stdlib.h>#include "setup.h"#include "constant.h"#include "envrnmnt.h"#include "memalloc.h"#include "router.h"#include "scanner.h"#include "cstrnutl.h"#include "cstrnchk.h"#include "sysdep.h"#include "cstrnpsr.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if (! RUN_TIME) && (! BLOAD_ONLY) static intBool ParseRangeCardinalityAttribute(void *, char *,CONSTRAINT_RECORD *, CONSTRAINT_PARSE_RECORD *, char *,int); static intBool ParseTypeAttribute(void *,char *,CONSTRAINT_RECORD *); static void AddToRestrictionList(void *,int,CONSTRAINT_RECORD *, CONSTRAINT_RECORD *); static intBool ParseAllowedValuesAttribute(void *,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(void *,char *,char *);#endif/********************************************************************//* CheckConstraintParseConflicts: Determines if a constraint record *//* has any conflicts in the attribute specifications. Returns *//* TRUE if no conflicts were detected, otherwise FALSE. *//********************************************************************/globle intBool CheckConstraintParseConflicts( void *theEnv, CONSTRAINT_RECORD *constraints) { /*===================================================*/ /* Check to see if any of the allowed-... attributes */ /* conflict with the type attribute. */ /*===================================================*/ if (constraints->anyAllowed == TRUE) { /* Do Nothing */ } else if (constraints->symbolRestriction && (constraints->symbolsAllowed == FALSE)) { AttributeConflictErrorMessage(theEnv,"type","allowed-symbols"); return(FALSE); } else if (constraints->stringRestriction && (constraints->stringsAllowed == FALSE)) { AttributeConflictErrorMessage(theEnv,"type","allowed-strings"); return(FALSE); } else if (constraints->integerRestriction && (constraints->integersAllowed == FALSE)) { AttributeConflictErrorMessage(theEnv,"type","allowed-integers/numbers"); return(FALSE); } else if (constraints->floatRestriction && (constraints->floatsAllowed == FALSE)) { AttributeConflictErrorMessage(theEnv,"type","allowed-floats/numbers"); return(FALSE); } else if (constraints->classRestriction && (constraints->instanceAddressesAllowed == FALSE) && (constraints->instanceNamesAllowed == FALSE)) { AttributeConflictErrorMessage(theEnv,"type","allowed-classes"); return(FALSE); } else if (constraints->instanceNameRestriction && (constraints->instanceNamesAllowed == FALSE)) { AttributeConflictErrorMessage(theEnv,"type","allowed-instance-names"); return(FALSE); } else if (constraints->anyRestriction) { struct expr *theExp; for (theExp = constraints->restrictionList; theExp != NULL; theExp = theExp->nextArg) { if (ConstraintCheckValue(theEnv,theExp->type,theExp->value,constraints) != NO_VIOLATION) { AttributeConflictErrorMessage(theEnv,"type","allowed-values"); return(FALSE); } } } /*================================================================*/ /* Check to see if range attribute conflicts with type attribute. */ /*================================================================*/ if ((constraints->maxValue != NULL) && (constraints->anyAllowed == FALSE)) { if (((constraints->maxValue->type == INTEGER) && (constraints->integersAllowed == FALSE)) || ((constraints->maxValue->type == FLOAT) && (constraints->floatsAllowed == FALSE))) { AttributeConflictErrorMessage(theEnv,"type","range"); return(FALSE); } } if ((constraints->minValue != NULL) && (constraints->anyAllowed == FALSE)) { if (((constraints->minValue->type == INTEGER) && (constraints->integersAllowed == FALSE)) || ((constraints->minValue->type == FLOAT) && (constraints->floatsAllowed == FALSE))) { AttributeConflictErrorMessage(theEnv,"type","range"); return(FALSE); } } /*=========================================*/ /* Check to see if allowed-class attribute */ /* conflicts with type attribute. */ /*=========================================*/ if ((constraints->classList != NULL) && (constraints->anyAllowed == FALSE) && (constraints->instanceNamesAllowed == FALSE) && (constraints->instanceAddressesAllowed == FALSE)) { AttributeConflictErrorMessage(theEnv,"type","allowed-class"); return(FALSE); } /*=====================================================*/ /* Return TRUE to indicate no conflicts were detected. */ /*=====================================================*/ return(TRUE); }/********************************************************//* AttributeConflictErrorMessage: Generic error message *//* for a constraint attribute conflict. *//********************************************************/globle void AttributeConflictErrorMessage( void *theEnv, char *attribute1, char *attribute2) { PrintErrorID(theEnv,"CSTRNPSR",1,TRUE); EnvPrintRouter(theEnv,WERROR,"The "); EnvPrintRouter(theEnv,WERROR,attribute1); EnvPrintRouter(theEnv,WERROR," attribute conflicts with the "); EnvPrintRouter(theEnv,WERROR,attribute2); EnvPrintRouter(theEnv,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( CONSTRAINT_PARSE_RECORD *parsedConstraints) { parsedConstraints->type = FALSE; parsedConstraints->range = FALSE; parsedConstraints->allowedSymbols = FALSE; parsedConstraints->allowedStrings = FALSE; parsedConstraints->allowedLexemes = FALSE; parsedConstraints->allowedIntegers = FALSE; parsedConstraints->allowedFloats = FALSE; parsedConstraints->allowedNumbers = FALSE; parsedConstraints->allowedValues = FALSE; parsedConstraints->allowedInstanceNames = FALSE; parsedConstraints->allowedClasses = FALSE; parsedConstraints->cardinality = FALSE; }/************************************************************************//* StandardConstraint: Returns TRUE if the specified name is one of the *//* standard constraints parseable by the routines in this module. *//************************************************************************/globle intBool StandardConstraint( 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-classes") == 0) || (strcmp(constraintName,"allowed-values") == 0)) { return(TRUE); } return(FALSE); }/***********************************************************************//* ParseStandardConstraint: Parses a standard constraint. Returns TRUE *//* if the constraint was successfully parsed, otherwise FALSE. *//***********************************************************************/globle intBool ParseStandardConstraint( void *theEnv, char *readSource, char *constraintName, CONSTRAINT_RECORD *constraints, CONSTRAINT_PARSE_RECORD *parsedConstraints, int multipleValuesAllowed) { int rv = FALSE; /*=====================================================*/ /* Determine if the attribute has already been parsed. */ /*=====================================================*/ if (GetAttributeParseValue(constraintName,parsedConstraints)) { AlreadyParsedErrorMessage(theEnv,constraintName," attribute"); return(FALSE); } /*==========================================*/ /* If specified, parse the range attribute. */ /*==========================================*/ if (strcmp(constraintName,"range") == 0) { rv = ParseRangeCardinalityAttribute(theEnv,readSource,constraints,parsedConstraints, constraintName,multipleValuesAllowed); } /*================================================*/ /* If specified, parse the cardinality attribute. */ /*================================================*/ else if (strcmp(constraintName,"cardinality") == 0) { rv = ParseRangeCardinalityAttribute(theEnv,readSource,constraints,parsedConstraints, constraintName,multipleValuesAllowed); } /*=========================================*/ /* If specified, parse the type attribute. */ /*=========================================*/ else if (strcmp(constraintName,"type") == 0) { rv = ParseTypeAttribute(theEnv,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-classes") == 0) || (strcmp(constraintName,"allowed-values") == 0)) { rv = ParseAllowedValuesAttribute(theEnv,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 */
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -