static struct expr *ParseRuleRHS(
void *theEnv,
const char *readSource)
{
struct expr *actions;
struct token theToken;
/*=========================================================*/
/* Process the actions on the right hand side of the rule. */
/*=========================================================*/
SavePPBuffer(theEnv,"\n ");
SetIndentDepth(theEnv,3);
actions = GroupActions(theEnv,readSource,&theToken,TRUE,NULL,FALSE);
if (actions == NULL) return(NULL);
/*=============================*/
/* Reformat the closing token. */
/*=============================*/
PPBackup(theEnv);
PPBackup(theEnv);
SavePPBuffer(theEnv,theToken.printForm);
/*======================================================*/
/* Check for the closing right parenthesis of the rule. */
/*======================================================*/
if (theToken.type != RPAREN)
{
SyntaxErrorMessage(theEnv,"defrule");
ReturnExpression(theEnv,actions);
return(NULL);
}
/*========================*/
/* Return the rule's RHS. */
/*========================*/
return(actions);
}
/***************************************************
NAME : ReadUntilClosingParen
DESCRIPTION : Skips over tokens until a ')' is
encountered.
INPUTS : 1) The logical input source
2) A buffer for scanned tokens
RETURNS : TRUE if ')' read, FALSE
otherwise
SIDE EFFECTS : Tokens read
NOTES : Expects first token after opening
paren has already been scanned
***************************************************/
static intBool ReadUntilClosingParen(
void *theEnv,
char *readSource,
struct token *inputToken)
{
int cnt = 1,lparen_read = FALSE;
do
{
if (lparen_read == FALSE)
SavePPBuffer(theEnv," ");
GetToken(theEnv,readSource,inputToken);
if (inputToken->type == STOP)
{
SyntaxErrorMessage(theEnv,"message-handler declaration");
return(FALSE);
}
else if (inputToken->type == LPAREN)
{
lparen_read = TRUE;
cnt++;
}
else if (inputToken->type == RPAREN)
{
cnt--;
if (lparen_read == FALSE)
{
PPBackup(theEnv);
PPBackup(theEnv);
SavePPBuffer(theEnv,")");
}
lparen_read = FALSE;
}
else
lparen_read = FALSE;
}
while (cnt > 0);
return(TRUE);
}
开发者ID:nickmain,项目名称:CLIPS,代码行数:52,代码来源:classpsr.c
示例10: GetConstructNameAndComment
/*************************************************************
NAME : ParseDefinstancesName
DESCRIPTION : Parses definstance name and optional comment
and optional "active" keyword
INPUTS : 1) The logical name of the input source
2) Buffer to hold flag indicating if
definstances should cause pattern-matching
to occur during slot-overrides
RETURNS : Address of name symbol, or
NULL if there was an error
SIDE EFFECTS : Token after name or comment is scanned
NOTES : Assumes "(definstances" has already
been scanned.
*************************************************************/
static SYMBOL_HN *ParseDefinstancesName(
void *theEnv,
char *readSource,
int *active)
{
SYMBOL_HN *dname;
*active = FALSE;
dname = GetConstructNameAndComment(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken,(char*)"definstances",
EnvFindDefinstances,EnvUndefinstances,(char*)"@",
TRUE,FALSE,TRUE);
if (dname == NULL)
return(NULL);
#if DEFRULE_CONSTRUCT
if ((GetType(DefclassData(theEnv)->ObjectParseToken) != SYMBOL) ? FALSE :
(strcmp(ValueToString(GetValue(DefclassData(theEnv)->ObjectParseToken)),ACTIVE_RLN) == 0))
{
PPBackup(theEnv);
PPBackup(theEnv);
SavePPBuffer(theEnv,(char*)" ");
SavePPBuffer(theEnv,DefclassData(theEnv)->ObjectParseToken.printForm);
PPCRAndIndent(theEnv);
GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
*active = TRUE;
}
#endif
if (GetType(DefclassData(theEnv)->ObjectParseToken) == STRING)
{
PPBackup(theEnv);
PPBackup(theEnv);
SavePPBuffer(theEnv,(char*)" ");
SavePPBuffer(theEnv,DefclassData(theEnv)->ObjectParseToken.printForm);
PPCRAndIndent(theEnv);
GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken);
}
return(dname);
}
static struct expr *IfParse(
void *theEnv,
struct expr *top,
char *infile)
{
struct token theToken;
/*============================*/
/* Process the if expression. */
/*============================*/
SavePPBuffer(theEnv," ");
top->argList = ParseAtomOrExpression(theEnv,infile,NULL);
if (top->argList == NULL)
{
ReturnExpression(theEnv,top);
return(NULL);
}
/*========================================*/
/* Keyword 'then' must follow expression. */
/*========================================*/
IncrementIndentDepth(theEnv,3);
PPCRAndIndent(theEnv);
GetToken(theEnv,infile,&theToken);
if ((theToken.type != SYMBOL) || (strcmp(ValueToString(theToken.value),"then") != 0))
{
SyntaxErrorMessage(theEnv,"if function");
ReturnExpression(theEnv,top);
return(NULL);
}
/*==============================*/
/* Process the if then actions. */
/*==============================*/
PPCRAndIndent(theEnv);
if (ExpressionData(theEnv)->svContexts->rtn == TRUE)
ExpressionData(theEnv)->ReturnContext = TRUE;
if (ExpressionData(theEnv)->svContexts->brk == TRUE)
ExpressionData(theEnv)->BreakContext = TRUE;
top->argList->nextArg = GroupActions(theEnv,infile,&theToken,TRUE,"else",FALSE);
if (top->argList->nextArg == NULL)
{
ReturnExpression(theEnv,top);
return(NULL);
}
top->argList->nextArg = RemoveUnneededProgn(theEnv,top->argList->nextArg);
/*===========================================*/
/* A ')' signals an if then without an else. */
/*===========================================*/
if (theToken.type == RPAREN)
{
DecrementIndentDepth(theEnv,3);
PPBackup(theEnv);
PPBackup(theEnv);
SavePPBuffer(theEnv,theToken.printForm);
return(top);
}
/*=============================================*/
/* Keyword 'else' must follow if then actions. */
/*=============================================*/
if ((theToken.type != SYMBOL) || (strcmp(ValueToString(theToken.value),"else") != 0))
{
SyntaxErrorMessage(theEnv,"if function");
ReturnExpression(theEnv,top);
return(NULL);
}
/*==============================*/
/* Process the if else actions. */
/*==============================*/
PPCRAndIndent(theEnv);
top->argList->nextArg->nextArg = GroupActions(theEnv,infile,&theToken,TRUE,NULL,FALSE);
if (top->argList->nextArg->nextArg == NULL)
{
ReturnExpression(theEnv,top);
return(NULL);
}
top->argList->nextArg->nextArg = RemoveUnneededProgn(theEnv,top->argList->nextArg->nextArg);
/*======================================================*/
/* Check for the closing right parenthesis of the if. */
/*======================================================*/
if (theToken.type != RPAREN)
{
//.........这里部分代码省略.........
开发者ID:atextor,项目名称:derp,代码行数:101,代码来源:prcdrpsr.c
示例13: ParseDefglobal
globle intBool ParseDefglobal(
void *theEnv,
char *readSource)
{
int defglobalError = FALSE;
#if (MAC_MCW || IBM_MCW) && (RUN_TIME || BLOAD_ONLY)
#pragma unused(theEnv,readSource)
#endif
#if (! RUN_TIME) && (! BLOAD_ONLY)
struct token theToken;
int tokenRead = TRUE;
struct defmodule *theModule;
/*=====================================*/
/* Pretty print buffer initialization. */
/*=====================================*/
SetPPBufferStatus(theEnv,ON);
FlushPPBuffer(theEnv);
SetIndentDepth(theEnv,3);
SavePPBuffer(theEnv,"(defglobal ");
/*=================================================*/
/* Individual defglobal constructs can't be parsed */
/* while a binary load is in effect. */
/*=================================================*/
#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
if ((Bloaded(theEnv) == TRUE) && (! ConstructData(theEnv)->CheckSyntaxMode))
{
CannotLoadWithBloadMessage(theEnv,"defglobal");
return(TRUE);
}
#endif
/*===========================*/
/* Look for the module name. */
/*===========================*/
GetToken(theEnv,readSource,&theToken);
if (theToken.type == SYMBOL)
{
/*=================================================*/
/* The optional module name can't contain a module */
/* separator like other constructs. For example, */
/* (defrule X::foo is OK for rules, but the right */
/* syntax for defglobals is (defglobal X ?*foo*. */
/*=================================================*/
tokenRead = FALSE;
if (FindModuleSeparator(ValueToString(theToken.value)))
{
SyntaxErrorMessage(theEnv,"defglobal");
return(TRUE);
}
/*=================================*/
/* Determine if the module exists. */
/*=================================*/
theModule = (struct defmodule *) EnvFindDefmodule(theEnv,ValueToString(theToken.value));
if (theModule == NULL)
{
CantFindItemErrorMessage(theEnv,"defmodule",ValueToString(theToken.value));
return(TRUE);
}
/*=========================================*/
/* If the module name was OK, then set the */
/* current module to the specified module. */
/*=========================================*/
SavePPBuffer(theEnv," ");
EnvSetCurrentModule(theEnv,(void *) theModule);
}
/*===========================================*/
/* If the module name wasn't specified, then */
/* use the current module's name in the */
/* defglobal's pretty print representation. */
/*===========================================*/
else
{
PPBackup(theEnv);
SavePPBuffer(theEnv,EnvGetDefmoduleName(theEnv,((struct defmodule *) EnvGetCurrentModule(theEnv))));
SavePPBuffer(theEnv," ");
SavePPBuffer(theEnv,theToken.printForm);
}
/*======================*/
/* Parse the variables. */
/*======================*/
while (GetVariableDefinition(theEnv,readSource,&defglobalError,tokenRead,&theToken))
{
tokenRead = FALSE;
//.........这里部分代码省略.........
开发者ID:femto,项目名称:rbclips,代码行数:101,代码来源:globlpsr.c
示例14: SyntaxErrorMessage
globle struct expr *BuildRHSAssert(
char *logicalName,
struct token *theToken,
int *error,
int atLeastOne,
int readFirstParen,
char *whereParsed)
{
struct expr *lastOne, *nextOne, *assertList, *stub;
*error = FALSE;
/*===============================================================*/
/* If the first parenthesis of the RHS fact pattern has not been */
/* read yet, then get the next token. If a right parenthesis is */
/* encountered then exit (however, set the error return value if */
/* at least one fact was expected). */
/*===============================================================*/
if (readFirstParen == FALSE)
{
if (theToken->type == RPAREN)
{
if (atLeastOne)
{
*error = TRUE;
SyntaxErrorMessage(whereParsed);
}
return(NULL);
}
}
/*================================================*/
/* Parse the facts until no more are encountered. */
/*================================================*/
lastOne = assertList = NULL;
while ((nextOne = GetRHSPattern(logicalName,theToken,
error,FALSE,readFirstParen,
TRUE,RPAREN)) != NULL)
{
PPCRAndIndent();
stub = GenConstant(FCALL,(void *) FindFunction("assert"));
stub->argList = nextOne;
nextOne = stub;
if (lastOne == NULL)
{ assertList = nextOne; }
else
{ lastOne->nextArg = nextOne; }
lastOne = nextOne;
readFirstParen = TRUE;
}
/*======================================================*/
/* If an error was detected while parsing, then return. */
/*======================================================*/
if (*error)
{
ReturnExpression(assertList);
return(NULL);
}
/*======================================*/
/* Fix the pretty print representation. */
/*======================================*/
if (theToken->type == RPAREN)
{
PPBackup();
PPBackup();
SavePPBuffer(")");
}
/*==============================================================*/
/* If no facts are being asserted then return NULL. In addition */
/* if at least one fact was required, then signal an error. */
/*==============================================================*/
if (assertList == NULL)
{
if (atLeastOne)
{
*error = TRUE;
SyntaxErrorMessage(whereParsed);
}
return(NULL);
}
/*===============================================*/
/* If more than one fact is being asserted, then */
/* wrap the assert commands within a progn call. */
/*===============================================*/
if (assertList->nextArg != NULL)
{
stub = GenConstant(FCALL,(void *) FindFunction("progn"));
//.........这里部分代码省略.........
请发表评论