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

📄 exprnops.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.24  06/05/06            */   /*                                                     */   /*             EXPRESSION OPERATIONS MODULE            */   /*******************************************************//*************************************************************//* Purpose: Provides utility routines for manipulating and   *//*   examining expressions.                                  *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*                                                           *//*      6.24: Renamed BOOLEAN macro type to intBool.         *//*                                                           *//*************************************************************/#define _EXPRNOPS_SOURCE_#include "setup.h"#include <stdio.h>#define _STDIO_INCLUDED_#include <stdlib.h>#include <string.h>#include <ctype.h>#include "memalloc.h"#include "envrnmnt.h"#include "router.h"#include "extnfunc.h"#include "cstrnchk.h"#include "prntutil.h"#include "cstrnutl.h"#include "cstrnops.h"#include "exprnops.h"#if (! RUN_TIME)/**************************************************************//* CheckArgumentAgainstRestriction: Compares an argument to a *//*   function to the set of restrictions for that function to *//*   determine if any incompatibilities exist. If so, the     *//*   value TRUE is returned, otherwise FALSE is returned.     *//*   Restrictions checked are:                                *//*     a - external address                                   *//*     d - float                                              *//*     e - instance address, instance name, or symbol         *//*     f - float                                              *//*     g - integer, float, or symbol                          *//*     h - instance address, instance name, fact address,     *//*         integer, or symbol                                 *//*     i - integer                                            *//*     j - symbol, string, or instance name                   *//*     k - symbol or string                                   *//*     l - integer                                            *//*     m - multifield                                         *//*     n - float or integer                                   *//*     o - instance name                                      *//*     p - instance name or symbol                            *//*     q - string, symbol, or multifield                      *//*     s - string                                             *//*     u - unknown (any type allowed)                         *//*     w - symbol                                             *//*     x - instance address                                   *//*     y - fact address                                       *//*     z - fact address, integer, or symbol (*)               *//**************************************************************/globle int CheckArgumentAgainstRestriction(  void *theEnv,  struct expr *theExpression,  int theRestriction)  {   CONSTRAINT_RECORD *cr1, *cr2, *cr3;   /*=============================================*/   /* Generate a constraint record for the actual */   /* argument passed to the function.            */   /*=============================================*/   cr1 = ExpressionToConstraintRecord(theEnv,theExpression);   /*================================================*/   /* Generate a constraint record based on the type */   /* of argument expected by the function.          */   /*================================================*/   cr2 = ArgumentTypeToConstraintRecord(theEnv,theRestriction);   /*===============================================*/   /* Intersect the two constraint records and then */   /* discard them.                                 */   /*===============================================*/   cr3 = IntersectConstraints(theEnv,cr1,cr2);   RemoveConstraint(theEnv,cr1);   RemoveConstraint(theEnv,cr2);   /*====================================================*/   /* If the intersection of the two constraint records  */   /* is empty, then the argument passed to the function */   /* doesn't satisfy the restrictions for the argument. */   /*====================================================*/   if (UnmatchableConstraint(cr3))     {      RemoveConstraint(theEnv,cr3);      return(TRUE);     }   /*===================================================*/   /* The argument satisfies the function restrictions. */   /*===================================================*/   RemoveConstraint(theEnv,cr3);   return(FALSE);  }#endif /* (! RUN_TIME) *//************************************************************//* ConstantExpression: Returns TRUE if the expression *//*   is a constant, otherwise FALSE.                  *//************************************************************/globle intBool ConstantExpression(  struct expr *testPtr)  {   while (testPtr != NULL)     {      if ((testPtr->type != SYMBOL) && (testPtr->type != STRING) &&#if OBJECT_SYSTEM          (testPtr->type != INSTANCE_NAME) && (testPtr->type != INSTANCE_ADDRESS) &&#endif          (testPtr->type != INTEGER) && (testPtr->type != FLOAT))        { return(FALSE); }      testPtr = testPtr->nextArg;     }   return(TRUE);  }/************************************************//* ConstantType: Returns TRUE if the type *//*   is a constant, otherwise FALSE.      *//************************************************/globle intBool ConstantType(  int theType)  {   switch (theType)     {      case SYMBOL:      case STRING:      case INTEGER:      case FLOAT:#if OBJECT_SYSTEM      case INSTANCE_NAME:      case INSTANCE_ADDRESS:#endif        return(TRUE);     }   return(FALSE);  }/*****************************************************************************//* IdenticalExpression: Determines if two expressions are identical. Returns *//*   TRUE if the expressions are identical, otherwise FALSE is returned.     *//*****************************************************************************/globle intBool IdenticalExpression(  struct expr *firstList,  struct expr *secondList)  {   /*==============================================*/   /* Compare each argument in both expressions by */   /* following the nextArg list.                  */   /*==============================================*/   for (;        (firstList != NULL) && (secondList != NULL);        firstList = firstList->nextArg, secondList = secondList->nextArg)     {      /*=========================*/      /* Compare type and value. */      /*=========================*/      if (firstList->type != secondList->type)        { return(FALSE); }      if (firstList->value != secondList->value)        { return (FALSE); }      /*==============================*/      /* Compare the arguments lists. */      /*==============================*/      if (IdenticalExpression(firstList->argList,secondList->argList) == FALSE)        { return(FALSE); }     }   /*=====================================================*/   /* If firstList and secondList aren't both NULL, then  */   /* one of the lists contains more expressions than the */   /* other.                                              */   /*=====================================================*/   if (firstList != secondList) return(FALSE);   /*============================*/   /* Expressions are identical. */   /*============================*/   return(TRUE);  }/****************************************************//* CountArguments: Returns the number of structures *//*   stored in an expression as traversed through   *//*   the nextArg pointer but not the argList        *//*   pointer.                                       *//****************************************************/globle int CountArguments(  struct expr *testPtr)  {   int size = 0;   while (testPtr != NULL)     {      size++;      testPtr = testPtr->nextArg;     }   return(size);  }/******************************************//* CopyExpresssion: Copies an expression. *//******************************************/globle struct expr *CopyExpression(  void *theEnv,  struct expr *original)  {   struct expr *topLevel, *next, *last;   if (original == NULL) return(NULL);   topLevel = GenConstant(theEnv,original->type,original->value);   topLevel->argList = CopyExpression(theEnv,original->argList);   last = topLevel;   original = original->nextArg;   while (original != NULL)     {      next = GenConstant(theEnv,original->type,original->value);      next->argList = CopyExpression(theEnv,original->argList);      last->nextArg = next;      last = next;      original = original->nextArg;     }   return(topLevel);  }

⌨️ 快捷键说明

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