📄 tmpltrhs.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* DEFTEMPLATE RHS PARSING HEADER FILE */ /*******************************************************//*************************************************************//* Purpose: Parses deftemplate fact patterns used with the *//* assert function. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//*************************************************************/#define _TMPLTRHS_SOURCE_#include "setup.h"#if DEFTEMPLATE_CONSTRUCT#include <stdio.h>#define _CLIPS_STDIO_#include "clipsmem.h"#include "prntutil.h"#include "router.h"#include "tmpltfun.h"#include "tmpltdef.h"#include "factrhs.h"#include "extnfunc.h"#include "modulutl.h"#include "default.h"#include "tmpltutl.h"#include "tmpltlhs.h"#include "tmpltrhs.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER static struct expr *ParseAssertSlotValues(char *,struct token *,struct templateSlot *,int *,int); static struct expr *ReorderAssertSlotValues(struct templateSlot *,struct expr *,int *); static struct expr *GetSlotAssertValues(struct templateSlot *,struct expr *,int *); static struct expr *FindAssertSlotItem(struct templateSlot *,struct expr *); static struct templateSlot *ParseSlotLabel(char *,struct token *,struct deftemplate *,int *,int);#else static struct expr *ParseAssertSlotValues(); static struct expr *ReorderAssertSlotValues(); static struct expr *GetSlotAssertValues(); static struct expr *FindAssertSlotItem(); static struct templateSlot *ParseSlotLabel();#endif/******************************************************************//* ParseAssertTemplate: Parses and builds the list of values that *//* are used for an assert of a fact with a deftemplate. *//******************************************************************/globle struct expr *ParseAssertTemplate(readSource,theToken,error,endType, constantsOnly,theDeftemplate) char *readSource; struct token *theToken; int *error; int endType, constantsOnly; struct deftemplate *theDeftemplate; { struct expr *firstSlot, *lastSlot, *nextSlot; struct expr *firstArg, *tempSlot; struct templateSlot *slotPtr; firstSlot = NULL; lastSlot = NULL; /*==============================================*/ /* Parse each of the slot fields in the assert. */ /*==============================================*/ while ((slotPtr = ParseSlotLabel(readSource,theToken,theDeftemplate,error,endType)) != NULL) { /*========================================================*/ /* Check to see that the slot hasn't already been parsed. */ /*========================================================*/ for (tempSlot = firstSlot; tempSlot != NULL; tempSlot = tempSlot->nextArg) { if (tempSlot->value == (VOID *) slotPtr->slotName) { AlreadyParsedErrorMessage("slot ",ValueToString(slotPtr->slotName)); *error = CLIPS_TRUE; ReturnExpression(firstSlot); return(NULL); } } /*============================================*/ /* Parse the values to be stored in the slot. */ /*============================================*/ nextSlot = ParseAssertSlotValues(readSource,theToken, slotPtr,error,constantsOnly); if (*error) { ReturnExpression(firstSlot); return(NULL); } /*============================================*/ /* Check to see if the values to be stored in */ /* the slot violate the slot's constraints. */ /*============================================*/ if (CheckRHSSlotTypes(nextSlot->argList,slotPtr,"assert") == 0) { *error = CLIPS_TRUE; ReturnExpression(firstSlot); ReturnExpression(nextSlot); return(NULL); } /*===================================================*/ /* Add the slot to the list of slots already parsed. */ /*===================================================*/ if (lastSlot == NULL) { firstSlot = nextSlot; } else { lastSlot->nextArg = nextSlot; } lastSlot = nextSlot; } /*=================================================*/ /* Return if an error occured parsing a slot name. */ /*=================================================*/ if (*error) { ReturnExpression(firstSlot); return(NULL); } /*=============================================================*/ /* Reorder the arguments to the order used by the deftemplate. */ /*=============================================================*/ firstArg = ReorderAssertSlotValues(theDeftemplate->slotList,firstSlot,error); ReturnExpression(firstSlot); /*==============================*/ /* Return the assert arguments. */ /*==============================*/ return(firstArg); } /****************************************************************//* ParseSlotLabel: Parses the beginning of a slot definition. *//* Checks for opening left parenthesis and a valid slot name. *//****************************************************************/static struct templateSlot *ParseSlotLabel(inputSource,tempToken,theDeftemplate,error,endType) char *inputSource; struct token *tempToken; struct deftemplate *theDeftemplate; int *error; int endType; { struct templateSlot *slotPtr; int position; /*========================*/ /* Initialize error flag. */ /*========================*/ *error = CLIPS_FALSE; /*============================================*/ /* If token is a right parenthesis, then fact */ /* template definition is complete. */ /*============================================*/ GetToken(inputSource,tempToken); if (tempToken->type == endType) { return(NULL); } /*=======================================*/ /* Put a space between the template name */ /* and the first slot definition. */ /*=======================================*/ PPBackup(); SavePPBuffer(" "); SavePPBuffer(tempToken->printForm); /*=======================================================*/ /* Slot definition begins with opening left parenthesis. */ /*=======================================================*/ if (tempToken->type != LPAREN) { SyntaxErrorMessage("deftemplate pattern"); *error = CLIPS_TRUE; return(NULL); } /*=============================*/ /* Slot name must be a symbol. */ /*=============================*/ GetToken(inputSource,tempToken); if (tempToken->type != SYMBOL) { SyntaxErrorMessage("deftemplate pattern"); *error = CLIPS_TRUE; return(NULL); } /*======================================================*/ /* Check that the slot name is valid for this template. */ /*======================================================*/ if ((slotPtr = FindSlot(theDeftemplate,tempToken->value,&position)) == NULL) { InvalidDeftemplateSlotMessage(ValueToString(tempToken->value), ValueToString(theDeftemplate->header.name)); *error = CLIPS_TRUE; return(NULL); } /*====================================*/ /* Return a pointer to the slot name. */ /*====================================*/ return(slotPtr); }/**************************************************************************//* ParseAssertSlotValues: Gets a single assert slot value for a template. *//**************************************************************************/static struct expr *ParseAssertSlotValues(inputSource,tempToken, slotPtr,error,constantsOnly) char *inputSource; struct token *tempToken; struct templateSlot *slotPtr; int *error; int constantsOnly; { struct expr *nextSlot; struct expr *newField, *valueList, *lastValue; int printError; /*=============================*/ /* Handle a single field slot. */ /*=============================*/ if (slotPtr->multislot == CLIPS_FALSE) { /*=====================*/ /* Get the slot value. */ /*=====================*/ SavePPBuffer(" "); newField = GetAssertArgument(inputSource,tempToken, error,RPAREN,constantsOnly,&printError); if (*error) { if (printError) SyntaxErrorMessage("deftemplate pattern"); return(NULL); } /*=================================================*/ /* A single field slot value must contain a value. */ /* Only a multifield slot can be empty. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -