static struct lhsParseNode *TestPattern( void *theEnv, EXEC_STATUS, char *readSource, int *error) { struct lhsParseNode *theNode; struct token theToken; struct expr *theExpression; /*================================================*/ /* Create the data specification for the test CE. */ /*================================================*/ SavePPBuffer(theEnv,execStatus," "); theNode = GetLHSParseNode(theEnv,execStatus); theNode->type = TEST_CE; theExpression = Function0Parse(theEnv,execStatus,readSource); theNode->expression = ExpressionToLHSParseNodes(theEnv,execStatus,theExpression); ReturnExpression(theEnv,execStatus,theExpression); if (theNode->expression == NULL) { *error = TRUE; ReturnLHSParseNodes(theEnv,execStatus,theNode); return(NULL); } /*=========================================================*/ /* Check for the closing right parenthesis of the test CE. */ /*=========================================================*/ GetToken(theEnv,execStatus,readSource,&theToken); if (theToken.type != RPAREN) { SyntaxErrorMessage(theEnv,execStatus,"test conditional element"); *error = TRUE; ReturnLHSParseNodes(theEnv,execStatus,theNode); return(NULL); } /*=====================*/ /* Return the test CE. */ /*=====================*/ return(theNode); }
static struct lhsParseNode *LiteralRestrictionParse( char *readSource, struct token *theToken, int *error) { struct lhsParseNode *topNode; struct expr *theExpression; /*============================================*/ /* Create a node to represent the constraint. */ /*============================================*/ topNode = GetLHSParseNode(); /*=================================================*/ /* Determine if the constraint has a '~' preceding */ /* it. If it does, then the field is negated */ /* (e.g. ~red means "not the constant red." */ /*=================================================*/ if (theToken->type == NOT_CONSTRAINT) { GetToken(readSource,theToken); topNode->negated = TRUE; } else { topNode->negated = FALSE; } /*===========================================*/ /* Determine if the constraint is one of the */ /* recognized types. These are ?variables, */ /* symbols, strings, numbers, :(expression), */ /* and =(expression). */ /*===========================================*/ topNode->type = theToken->type; /*============================================*/ /* Any symbol is valid, but an = signifies a */ /* return value constraint and an : signifies */ /* a predicate constraint. */ /*============================================*/ if (theToken->type == SYMBOL) { /*==============================*/ /* If the symbol is an =, parse */ /* a return value constraint. */ /*==============================*/ if (strcmp(ValueToString(theToken->value),"=") == 0) { theExpression = Function0Parse(readSource); if (theExpression == NULL) { *error = TRUE; ReturnLHSParseNodes(topNode); return(NULL); } topNode->type = RETURN_VALUE_CONSTRAINT; topNode->expression = ExpressionToLHSParseNodes(theExpression); ReturnExpression(theExpression); } /*=============================*/ /* If the symbol is a :, parse */ /* a predicate constraint. */ /*=============================*/ else if (strcmp(ValueToString(theToken->value),":") == 0) { theExpression = Function0Parse(readSource); if (theExpression == NULL) { *error = TRUE; ReturnLHSParseNodes(topNode); return(NULL); } topNode->type = PREDICATE_CONSTRAINT; topNode->expression = ExpressionToLHSParseNodes(theExpression); ReturnExpression(theExpression); } /*==============================================*/ /* Otherwise, treat the constraint as a symbol. */ /*==============================================*/ else { topNode->value = theToken->value; } } /*=====================================================*/ /* Single and multifield variables and float, integer, */ /* string, and instance name constants are also valid. */ /*=====================================================*/ else if ((theToken->type == SF_VARIABLE) || (theToken->type == MF_VARIABLE) || (theToken->type == FLOAT) || (theToken->type == INTEGER) || (theToken->type == STRING) || (theToken->type == INSTANCE_NAME)) { topNode->value = theToken->value; } /*===========================*/ /* Anything else is invalid. */ /*===========================*/ else { SyntaxErrorMessage("defrule"); *error = TRUE; ReturnLHSParseNodes(topNode); return(NULL); } /*===============================*/ /* Return the parsed constraint. */ /*===============================*/ return(topNode); }