📄 cstrnpsr.c
字号:
/* ParseRangeCardinalityAttribute: Parses the range/cardinality attribute. */
/***************************************************************************/
static intBool ParseRangeCardinalityAttribute(
void *theEnv,
char *readSource,
CONSTRAINT_RECORD *constraints,
CONSTRAINT_PARSE_RECORD *parsedConstraints,
char *constraintName,
int multipleValuesAllowed)
{
struct token inputToken;
int range;
char *tempPtr = NULL;
/*=================================*/
/* Determine if we're parsing the */
/* range or cardinality attribute. */
/*=================================*/
if (strcmp(constraintName,"range") == 0)
{
parsedConstraints->range = TRUE;
range = TRUE;
}
else
{
parsedConstraints->cardinality = TRUE;
range = FALSE;
}
/*===================================================================*/
/* The cardinality attribute can only be used with multifield slots. */
/*===================================================================*/
if ((range == FALSE) &&
(multipleValuesAllowed == FALSE))
{
PrintErrorID(theEnv,"CSTRNPSR",5,TRUE);
EnvPrintRouter(theEnv,WERROR,"The cardinality attribute ");
EnvPrintRouter(theEnv,WERROR,"can only be used with multifield slots.\n");
return(FALSE);
}
/*====================================================*/
/* The range attribute is not allowed with the */
/* allowed-values/numbers/integers/floats attributes. */
/*====================================================*/
if ((range == 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(theEnv,"range",tempPtr);
return(FALSE);
}
/*==========================*/
/* Parse the minimum value. */
/*==========================*/
SavePPBuffer(theEnv," ");
GetToken(theEnv,readSource,&inputToken);
if ((inputToken.type == INTEGER) || ((inputToken.type == FLOAT) && range))
{
if (range)
{
ReturnExpression(theEnv,constraints->minValue);
constraints->minValue = GenConstant(theEnv,inputToken.type,inputToken.value);
}
else
{
ReturnExpression(theEnv,constraints->minFields);
constraints->minFields = GenConstant(theEnv,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(theEnv,tempBuffer);
return(FALSE);
}
/*==========================*/
/* Parse the maximum value. */
/*==========================*/
SavePPBuffer(theEnv," ");
GetToken(theEnv,readSource,&inputToken);
if ((inputToken.type == INTEGER) || ((inputToken.type == FLOAT) && range))
{
if (range)
{
ReturnExpression(theEnv,constraints->maxValue);
constraints->maxValue = GenConstant(theEnv,inputToken.type,inputToken.value);
}
else
{
ReturnExpression(theEnv,constraints->maxFields);
constraints->maxFields = GenConstant(theEnv,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(theEnv,tempBuffer);
return(FALSE);
}
/*================================*/
/* Parse the closing parenthesis. */
/*================================*/
GetToken(theEnv,readSource,&inputToken);
if (inputToken.type != RPAREN)
{
SyntaxErrorMessage(theEnv,"range attribute");
return(FALSE);
}
/*====================================================*/
/* Minimum value must be less than the maximum value. */
/*====================================================*/
if (range)
{
if (CompareNumbers(theEnv,constraints->minValue->type,
constraints->minValue->value,
constraints->maxValue->type,
constraints->maxValue->value) == GREATER_THAN)
{
PrintErrorID(theEnv,"CSTRNPSR",2,TRUE);
EnvPrintRouter(theEnv,WERROR,"Minimum range value must be less than\n");
EnvPrintRouter(theEnv,WERROR,"or equal to the maximum range value\n");
return(FALSE);
}
}
else
{
if (CompareNumbers(theEnv,constraints->minFields->type,
constraints->minFields->value,
constraints->maxFields->type,
constraints->maxFields->value) == GREATER_THAN)
{
PrintErrorID(theEnv,"CSTRNPSR",2,TRUE);
EnvPrintRouter(theEnv,WERROR,"Minimum cardinality value must be less than\n");
EnvPrintRouter(theEnv,WERROR,"or equal to the maximum cardinality value\n");
return(FALSE);
}
}
/*====================================*/
/* Return TRUE to indicate that the */
/* attribute was successfully parsed. */
/*====================================*/
return(TRUE);
}
/******************************************************************/
/* GetConstraintTypeFromAllowedName: Returns the type restriction */
/* associated with an allowed-... attribute. */
/******************************************************************/
static int GetConstraintTypeFromAllowedName(
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-classes") == 0) return(INSTANCE_OR_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(
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(
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-classes") == 0)
{ return(parsedConstraints->allowedClasses); }
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(TRUE);
}
/**********************************************************/
/* SetRestrictionFlag: Sets the restriction flag of a */
/* constraint record indicating whether a specific */
/* type has an associated allowed-... restriction list. */
/**********************************************************/
static void SetRestrictionFlag(
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;
case INSTANCE_OR_INSTANCE_NAME:
constraints->classRestriction = value;
break;
}
}
/********************************************************************/
/* SetParseFlag: Sets the flag in a parsed constraints data */
/* structure indicating that a specific attribute has been parsed. */
/********************************************************************/
static void SetParseFlag(
CONSTRAINT_PARSE_RECORD *parsedConstraints,
char *constraintName)
{
if (strcmp(constraintName,"range") == 0)
{ parsedConstraints->range = TRUE; }
else if (strcmp(constraintName,"type") == 0)
{ parsedConstraints->type = TRUE; }
else if (strcmp(constraintName,"cardinality") == 0)
{ parsedConstraints->cardinality = TRUE; }
else if (strcmp(constraintName,"allowed-symbols") == 0)
{ parsedConstraints->allowedSymbols = TRUE; }
else if (strcmp(constraintName,"allowed-strings") == 0)
{ parsedConstraints->allowedStrings = TRUE; }
else if (strcmp(constraintName,"allowed-lexemes") == 0)
{ parsedConstraints->allowedLexemes = TRUE; }
else if (strcmp(constraintName,"allowed-integers") == 0)
{ parsedConstraints->allowedIntegers = TRUE; }
else if (strcmp(constraintName,"allowed-floats") == 0)
{ parsedConstraints->allowedFloats = TRUE; }
else if (strcmp(constraintName,"allowed-numbers") == 0)
{ parsedConstraints->allowedNumbers = TRUE; }
else if (strcmp(constraintName,"allowed-values") == 0)
{ parsedConstraints->allowedValues = TRUE; }
else if (strcmp(constraintName,"allowed-classes") == 0)
{ parsedConstraints->allowedClasses = TRUE; }
}
#endif /* (! RUN_TIME) && (! BLOAD_ONLY) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -