00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #define _FACTLHS_SOURCE_
00027
00028 #include "setup.h"
00029
00030 #if DEFTEMPLATE_CONSTRUCT && DEFRULE_CONSTRUCT && (! RUN_TIME) && (! BLOAD_ONLY)
00031
00032 #include <stdio.h>
00033 #define _STDIO_INCLUDED_
00034
00035 #include "cstrcpsr.h"
00036 #include "envrnmnt.h"
00037 #include "pattern.h"
00038 #include "router.h"
00039 #include "reorder.h"
00040 #include "tmpltpsr.h"
00041 #include "tmpltdef.h"
00042 #include "tmpltlhs.h"
00043 #include "tmpltutl.h"
00044 #include "modulutl.h"
00045 #include "modulpsr.h"
00046
00047 #include "factlhs.h"
00048
00049
00050
00051
00052
00053
00054
00055
00056 globle struct lhsParseNode *SequenceRestrictionParse(
00057 void *theEnv,
00058 char *readSource,
00059 struct token *theToken)
00060 {
00061 struct lhsParseNode *topNode;
00062 struct lhsParseNode *nextField;
00063
00064
00065
00066
00067
00068 topNode = GetLHSParseNode(theEnv);
00069 topNode->type = SF_WILDCARD;
00070 topNode->negated = FALSE;
00071 topNode->exists = FALSE;
00072 topNode->index = -1;
00073 topNode->slotNumber = 1;
00074 topNode->bottom = GetLHSParseNode(theEnv);
00075 topNode->bottom->type = SYMBOL;
00076 topNode->bottom->negated = FALSE;
00077 topNode->bottom->exists = FALSE;
00078 topNode->bottom->value = (void *) theToken->value;
00079
00080
00081
00082
00083
00084
00085 SavePPBuffer(theEnv," ");
00086 GetToken(theEnv,readSource,theToken);
00087 if ((theToken->type == OR_CONSTRAINT) || (theToken->type == AND_CONSTRAINT))
00088 {
00089 ReturnLHSParseNodes(theEnv,topNode);
00090 SyntaxErrorMessage(theEnv,"the first field of a pattern");
00091 return(NULL);
00092 }
00093
00094
00095
00096
00097
00098
00099 nextField = RestrictionParse(theEnv,readSource,theToken,TRUE,NULL,1,NULL,1);
00100 if (nextField == NULL)
00101 {
00102 ReturnLHSParseNodes(theEnv,topNode);
00103 return(NULL);
00104 }
00105 topNode->right = nextField;
00106
00107
00108
00109
00110
00111 if (theToken->type != RPAREN)
00112 {
00113 PPBackup(theEnv);
00114 SavePPBuffer(theEnv," ");
00115 SavePPBuffer(theEnv,theToken->printForm);
00116 SyntaxErrorMessage(theEnv,"fact patterns");
00117 ReturnLHSParseNodes(theEnv,topNode);
00118 return(NULL);
00119 }
00120
00121
00122
00123
00124
00125
00126 if (nextField->bottom == NULL)
00127 {
00128 PPBackup(theEnv);
00129 PPBackup(theEnv);
00130 SavePPBuffer(theEnv,")");
00131 }
00132
00133
00134
00135
00136
00137 return(topNode);
00138 }
00139
00140
00141
00142
00143
00144 globle struct lhsParseNode *CreateInitialFactPattern(
00145 void *theEnv)
00146 {
00147 struct lhsParseNode *topNode;
00148 struct deftemplate *theDeftemplate;
00149 int count;
00150
00151
00152
00153
00154
00155
00156 theDeftemplate = (struct deftemplate *)
00157 FindImportedConstruct(theEnv,"deftemplate",NULL,"initial-fact",
00158 &count,TRUE,NULL);
00159 if (theDeftemplate == NULL)
00160 {
00161 PrintWarningID(theEnv,"FACTLHS",1,FALSE);
00162 EnvPrintRouter(theEnv,WWARNING,"Creating implied initial-fact deftemplate in module ");
00163 EnvPrintRouter(theEnv,WWARNING,EnvGetDefmoduleName(theEnv,EnvGetCurrentModule(theEnv)));
00164 EnvPrintRouter(theEnv,WWARNING,".\n");
00165 EnvPrintRouter(theEnv,WWARNING," You probably want to import this deftemplate from the MAIN module.\n");
00166 CreateImpliedDeftemplate(theEnv,(SYMBOL_HN *) EnvAddSymbol(theEnv,"initial-fact"),FALSE);
00167 }
00168
00169
00170
00171
00172
00173 topNode = GetLHSParseNode(theEnv);
00174 topNode->type = SF_WILDCARD;
00175 topNode->index = 0;
00176 topNode->slotNumber = 1;
00177
00178 topNode->bottom = GetLHSParseNode(theEnv);
00179 topNode->bottom->type = SYMBOL;
00180 topNode->bottom->value = (void *) EnvAddSymbol(theEnv,"initial-fact");
00181
00182
00183
00184
00185
00186 return(topNode);
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 #if WIN_BTC
00198 #pragma argsused
00199 #endif
00200 globle int FactPatternParserFind(
00201 SYMBOL_HN *theRelation)
00202 {
00203 #if MAC_MCW || WIN_MCW || MAC_XCD
00204 #pragma unused(theRelation)
00205 #endif
00206 return(TRUE);
00207 }
00208
00209
00210
00211
00212
00213 globle struct lhsParseNode *FactPatternParse(
00214 void *theEnv,
00215 char *readSource,
00216 struct token *theToken)
00217 {
00218 struct deftemplate *theDeftemplate;
00219 int count;
00220
00221
00222
00223
00224
00225
00226 if (FindModuleSeparator(ValueToString(theToken->value)))
00227 {
00228 IllegalModuleSpecifierMessage(theEnv);
00229 return(NULL);
00230 }
00231
00232
00233
00234
00235
00236 theDeftemplate = (struct deftemplate *)
00237 FindImportedConstruct(theEnv,"deftemplate",NULL,ValueToString(theToken->value),
00238 &count,TRUE,NULL);
00239
00240 if (count > 1)
00241 {
00242 AmbiguousReferenceErrorMessage(theEnv,"deftemplate",ValueToString(theToken->value));
00243 return(NULL);
00244 }
00245
00246
00247
00248
00249
00250
00251 if (theDeftemplate == NULL)
00252 {
00253 #if DEFMODULE_CONSTRUCT
00254 if (FindImportExportConflict(theEnv,"deftemplate",((struct defmodule *) EnvGetCurrentModule(theEnv)),ValueToString(theToken->value)))
00255 {
00256 ImportExportConflictMessage(theEnv,"implied deftemplate",ValueToString(theToken->value),NULL,NULL);
00257 return(NULL);
00258 }
00259 #endif
00260
00261 if (! ConstructData(theEnv)->CheckSyntaxMode)
00262 { theDeftemplate = CreateImpliedDeftemplate(theEnv,(SYMBOL_HN *) theToken->value,TRUE); }
00263 else
00264 { theDeftemplate = NULL; }
00265 }
00266
00267
00268
00269
00270
00271
00272 if ((theDeftemplate != NULL) && (theDeftemplate->implied == FALSE))
00273 { return(DeftemplateLHSParse(theEnv,readSource,theDeftemplate)); }
00274
00275
00276
00277
00278
00279 return(SequenceRestrictionParse(theEnv,readSource,theToken));
00280 }
00281
00282 #endif
00283
00284
00285