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
00027 #define _PRCDRPSR_SOURCE_
00028
00029 #include <stdio.h>
00030 #define _STDIO_INCLUDED_
00031
00032 #include "setup.h"
00033
00034 #include "argacces.h"
00035 #include "constrnt.h"
00036 #include "cstrnchk.h"
00037 #include "cstrnops.h"
00038 #include "cstrnutl.h"
00039 #include "envrnmnt.h"
00040 #include "exprnpsr.h"
00041 #include "memalloc.h"
00042 #include "modulutl.h"
00043 #include "multifld.h"
00044 #include "router.h"
00045 #include "scanner.h"
00046 #include "utility.h"
00047
00048 #include "prcdrpsr.h"
00049
00050 #if DEFGLOBAL_CONSTRUCT
00051 #include "globldef.h"
00052 #include "globlpsr.h"
00053 #endif
00054
00055 #if ! RUN_TIME
00056 #define PRCDRPSR_DATA 12
00057
00058 struct procedureParserData
00059 {
00060 struct BindInfo *ListOfParsedBindNames;
00061 };
00062
00063 #define ProcedureParserData(theEnv) ((struct procedureParserData *) GetEnvironmentData(theEnv,PRCDRPSR_DATA))
00064 #endif
00065
00066
00067
00068
00069
00070 #if (! RUN_TIME) && (! BLOAD_ONLY)
00071 static struct expr *WhileParse(void *,struct expr *,char *);
00072 static struct expr *LoopForCountParse(void *,struct expr *,char *);
00073 static void ReplaceLoopCountVars(void *,SYMBOL_HN *,EXPRESSION *,int);
00074 static struct expr *IfParse(void *,struct expr *,char *);
00075 static struct expr *PrognParse(void *,struct expr *,char *);
00076 static struct expr *BindParse(void *,struct expr *,char *);
00077 static int AddBindName(void *,struct symbolHashNode *,CONSTRAINT_RECORD *);
00078 static struct expr *ReturnParse(void *,struct expr *,char *);
00079 static struct expr *BreakParse(void *,struct expr *,char *);
00080 static struct expr *SwitchParse(void *,struct expr *,char *);
00081 static void DeallocateProceduralFunctionData(void *);
00082 #endif
00083
00084 #if ! RUN_TIME
00085
00086
00087
00088 globle void ProceduralFunctionParsers(
00089 void *theEnv)
00090 {
00091 AllocateEnvironmentData(theEnv,PRCDRPSR_DATA,sizeof(struct procedureParserData),DeallocateProceduralFunctionData);
00092
00093 #if (! BLOAD_ONLY)
00094 AddFunctionParser(theEnv,"bind",BindParse);
00095 AddFunctionParser(theEnv,"progn",PrognParse);
00096 AddFunctionParser(theEnv,"if",IfParse);
00097 AddFunctionParser(theEnv,"while",WhileParse);
00098 AddFunctionParser(theEnv,"loop-for-count",LoopForCountParse);
00099 AddFunctionParser(theEnv,"return",ReturnParse);
00100 AddFunctionParser(theEnv,"break",BreakParse);
00101 AddFunctionParser(theEnv,"switch",SwitchParse);
00102 #endif
00103 }
00104
00105
00106
00107
00108
00109 static void DeallocateProceduralFunctionData(
00110 void *theEnv)
00111 {
00112 struct BindInfo *temp_bind;
00113
00114 while (ProcedureParserData(theEnv)->ListOfParsedBindNames != NULL)
00115 {
00116 temp_bind = ProcedureParserData(theEnv)->ListOfParsedBindNames->next;
00117 rtn_struct(theEnv,BindInfo,ProcedureParserData(theEnv)->ListOfParsedBindNames);
00118 ProcedureParserData(theEnv)->ListOfParsedBindNames = temp_bind;
00119 }
00120 }
00121
00122
00123
00124
00125 globle struct BindInfo *GetParsedBindNames(
00126 void *theEnv)
00127 {
00128 return(ProcedureParserData(theEnv)->ListOfParsedBindNames);
00129 }
00130
00131
00132
00133
00134 globle void SetParsedBindNames(
00135 void *theEnv,
00136 struct BindInfo *newValue)
00137 {
00138 ProcedureParserData(theEnv)->ListOfParsedBindNames = newValue;
00139 }
00140
00141
00142
00143
00144 globle void ClearParsedBindNames(
00145 void *theEnv)
00146 {
00147 struct BindInfo *temp_bind;
00148
00149 while (ProcedureParserData(theEnv)->ListOfParsedBindNames != NULL)
00150 {
00151 temp_bind = ProcedureParserData(theEnv)->ListOfParsedBindNames->next;
00152 RemoveConstraint(theEnv,ProcedureParserData(theEnv)->ListOfParsedBindNames->constraints);
00153 rtn_struct(theEnv,BindInfo,ProcedureParserData(theEnv)->ListOfParsedBindNames);
00154 ProcedureParserData(theEnv)->ListOfParsedBindNames = temp_bind;
00155 }
00156 }
00157
00158
00159
00160
00161 globle intBool ParsedBindNamesEmpty(
00162 void *theEnv)
00163 {
00164 if (ProcedureParserData(theEnv)->ListOfParsedBindNames != NULL) return(FALSE);
00165
00166 return(TRUE);
00167 }
00168
00169 #if (! BLOAD_ONLY)
00170
00171
00172
00173
00174
00175
00176 static struct expr *WhileParse(
00177 void *theEnv,
00178 struct expr *parse,
00179 char *infile)
00180 {
00181 struct token theToken;
00182 int read_first_paren;
00183
00184
00185
00186
00187
00188 SavePPBuffer(theEnv," ");
00189
00190 parse->argList = ParseAtomOrExpression(theEnv,infile,NULL);
00191 if (parse->argList == NULL)
00192 {
00193 ReturnExpression(theEnv,parse);
00194 return(NULL);
00195 }
00196
00197
00198
00199
00200
00201 GetToken(theEnv,infile,&theToken);
00202 if ((theToken.type == SYMBOL) && (strcmp(ValueToString(theToken.value),"do") == 0))
00203 {
00204 read_first_paren = TRUE;
00205 PPBackup(theEnv);
00206 SavePPBuffer(theEnv," ");
00207 SavePPBuffer(theEnv,theToken.printForm);
00208 IncrementIndentDepth(theEnv,3);
00209 PPCRAndIndent(theEnv);
00210 }
00211 else if (theToken.type == LPAREN)
00212 {
00213 read_first_paren = FALSE;
00214 PPBackup(theEnv);
00215 IncrementIndentDepth(theEnv,3);
00216 PPCRAndIndent(theEnv);
00217 SavePPBuffer(theEnv,theToken.printForm);
00218 }
00219 else
00220 {
00221 SyntaxErrorMessage(theEnv,"while function");
00222 ReturnExpression(theEnv,parse);
00223 return(NULL);
00224 }
00225
00226
00227
00228
00229 if (ExpressionData(theEnv)->svContexts->rtn == TRUE)
00230 ExpressionData(theEnv)->ReturnContext = TRUE;
00231 ExpressionData(theEnv)->BreakContext = TRUE;
00232 parse->argList->nextArg = GroupActions(theEnv,infile,&theToken,read_first_paren,NULL,FALSE);
00233
00234 if (parse->argList->nextArg == NULL)
00235 {
00236 ReturnExpression(theEnv,parse);
00237 return(NULL);
00238 }
00239 PPBackup(theEnv);
00240 PPBackup(theEnv);
00241 SavePPBuffer(theEnv,theToken.printForm);
00242
00243
00244
00245
00246
00247 if (theToken.type != RPAREN)
00248 {
00249 SyntaxErrorMessage(theEnv,"while function");
00250 ReturnExpression(theEnv,parse);
00251 return(NULL);
00252 }
00253
00254 DecrementIndentDepth(theEnv,3);
00255
00256 return(parse);
00257 }
00258
00259
00260
00261
00262
00263
00264
00265 static struct expr *LoopForCountParse(
00266 void *theEnv,
00267 struct expr *parse,
00268 char *infile)
00269 {
00270 struct token theToken;
00271 SYMBOL_HN *loopVar = NULL;
00272 EXPRESSION *tmpexp;
00273 int read_first_paren;
00274 struct BindInfo *oldBindList,*newBindList,*prev;
00275
00276
00277
00278
00279
00280 SavePPBuffer(theEnv," ");
00281 GetToken(theEnv,infile,&theToken);
00282
00283
00284
00285
00286 if (theToken.type != LPAREN)
00287 {
00288 parse->argList = GenConstant(theEnv,INTEGER,EnvAddLong(theEnv,1LL));
00289 parse->argList->nextArg = ParseAtomOrExpression(theEnv,infile,&theToken);
00290 if (parse->argList->nextArg == NULL)
00291 {
00292 ReturnExpression(theEnv,parse);
00293 return(NULL);
00294 }
00295 }
00296 else
00297 {
00298 GetToken(theEnv,infile,&theToken);
00299 if (theToken.type != SF_VARIABLE)
00300 {
00301 if (theToken.type != SYMBOL)
00302 goto LoopForCountParseError;
00303 parse->argList = GenConstant(theEnv,INTEGER,EnvAddLong(theEnv,1LL));
00304 parse->argList->nextArg = Function2Parse(theEnv,infile,ValueToString(theToken.value));
00305 if (parse->argList->nextArg == NULL)
00306 {
00307 ReturnExpression(theEnv,parse);
00308 return(NULL);
00309 }
00310 }
00311
00312
00313
00314
00315 else
00316 {
00317 loopVar = (SYMBOL_HN *) theToken.value;
00318 SavePPBuffer(theEnv," ");
00319 parse->argList = ParseAtomOrExpression(theEnv,infile,NULL);
00320 if (parse->argList == NULL)
00321 {
00322 ReturnExpression(theEnv,parse);
00323 return(NULL);
00324 }
00325 if (CheckArgumentAgainstRestriction(theEnv,parse->argList,(int) 'i'))
00326 goto LoopForCountParseError;
00327 SavePPBuffer(theEnv," ");
00328 GetToken(theEnv,infile,&theToken);
00329 if (theToken.type == RPAREN)
00330 {
00331 PPBackup(theEnv);
00332 PPBackup(theEnv);
00333 SavePPBuffer(theEnv,theToken.printForm);
00334 tmpexp = GenConstant(theEnv,INTEGER,EnvAddLong(theEnv,1LL));
00335 tmpexp->nextArg = parse->argList;
00336 parse->argList = tmpexp;
00337 }
00338 else
00339 {
00340 parse->argList->nextArg = ParseAtomOrExpression(theEnv,infile,&theToken);
00341 if (parse->argList->nextArg == NULL)
00342 {
00343 ReturnExpression(theEnv,parse);
00344 return(NULL);
00345 }
00346 GetToken(theEnv,infile,&theToken);
00347 if (theToken.type != RPAREN)
00348 goto LoopForCountParseError;
00349 }
00350 SavePPBuffer(theEnv," ");
00351 }
00352 }
00353
00354 if (CheckArgumentAgainstRestriction(theEnv,parse->argList->nextArg,(int) 'i'))
00355 goto LoopForCountParseError;
00356
00357
00358
00359
00360
00361 GetToken(theEnv,infile,&theToken);
00362 if ((theToken.type == SYMBOL) && (strcmp(ValueToString(theToken.value),"do") == 0))
00363 {
00364 read_first_paren = TRUE;
00365 PPBackup(theEnv);
00366 SavePPBuffer(theEnv," ");
00367 SavePPBuffer(theEnv,theToken.printForm);
00368 IncrementIndentDepth(theEnv,3);
00369 PPCRAndIndent(theEnv);
00370 }
00371 else if (theToken.type == LPAREN)
00372 {
00373 read_first_paren = FALSE;
00374 PPBackup(theEnv);
00375 IncrementIndentDepth(theEnv,3);
00376 PPCRAndIndent(theEnv);
00377 SavePPBuffer(theEnv,theToken.printForm);
00378 }
00379 else
00380 goto LoopForCountParseError;
00381
00382
00383
00384
00385 if (ExpressionData(theEnv)->svContexts->rtn == TRUE)
00386 ExpressionData(theEnv)->ReturnContext = TRUE;
00387 ExpressionData(theEnv)->BreakContext = TRUE;
00388 oldBindList = GetParsedBindNames(theEnv);
00389 SetParsedBindNames(theEnv,NULL);
00390 parse->argList->nextArg->nextArg =
00391 GroupActions(theEnv,infile,&theToken,read_first_paren,NULL,FALSE);
00392
00393 if (parse->argList->nextArg->nextArg == NULL)
00394 {
00395 SetParsedBindNames(theEnv,oldBindList);
00396 ReturnExpression(theEnv,parse);
00397 return(NULL);
00398 }
00399 newBindList = GetParsedBindNames(theEnv);
00400 prev = NULL;
00401 while (newBindList != NULL)
00402 {
00403 if ((loopVar == NULL) ? FALSE :
00404 (strcmp(ValueToString(newBindList->name),ValueToString(loopVar)) == 0))
00405 {
00406 ClearParsedBindNames(theEnv);
00407 SetParsedBindNames(theEnv,oldBindList);
00408 PrintErrorID(theEnv,"PRCDRPSR",1,TRUE);
00409 EnvPrintRouter(theEnv,WERROR,"Cannot rebind loop variable in function loop-for-count.\n");
00410 ReturnExpression(theEnv,parse);
00411 return(NULL);
00412 }
00413 prev = newBindList;
00414 newBindList = newBindList->next;
00415 }
00416 if (prev == NULL)
00417 SetParsedBindNames(theEnv,oldBindList);
00418 else
00419 prev->next = oldBindList;
00420 if (loopVar != NULL)
00421 ReplaceLoopCountVars(theEnv,loopVar,parse->argList->nextArg->nextArg,0);
00422 PPBackup(theEnv);
00423 PPBackup(theEnv);
00424 SavePPBuffer(theEnv,theToken.printForm);
00425
00426
00427
00428
00429
00430 if (theToken.type != RPAREN)
00431 {
00432 SyntaxErrorMessage(theEnv,"loop-for-count function");
00433 ReturnExpression(theEnv,parse);
00434 return(NULL);
00435 }
00436
00437 DecrementIndentDepth(theEnv,3);
00438
00439 return(parse);
00440
00441 LoopForCountParseError:
00442 SyntaxErrorMessage(theEnv,"loop-for-count function");
00443 ReturnExpression(theEnv,parse);
00444 return(NULL);
00445 }
00446
00447
00448
00449
00450 static void ReplaceLoopCountVars(
00451 void *theEnv,
00452 SYMBOL_HN *loopVar,
00453 EXPRESSION *theExp,
00454 int depth)
00455 {
00456 while (theExp != NULL)
00457 {
00458 if ((theExp->type != SF_VARIABLE) ? FALSE :
00459 (strcmp(ValueToString(theExp->value),ValueToString(loopVar)) == 0))
00460 {
00461 theExp->type = FCALL;
00462 theExp->value = (void *) FindFunction(theEnv,"(get-loop-count)");
00463 theExp->argList = GenConstant(theEnv,INTEGER,EnvAddLong(theEnv,(long long) depth));
00464 }
00465 else if (theExp->argList != NULL)
00466 {
00467 if ((theExp->type != FCALL) ? FALSE :
00468 (theExp->value == (void *) FindFunction(theEnv,"loop-for-count")))
00469 ReplaceLoopCountVars(theEnv,loopVar,theExp->argList,depth+1);
00470 else
00471 ReplaceLoopCountVars(theEnv,loopVar,theExp->argList,depth);
00472 }
00473 theExp = theExp->nextArg;
00474 }
00475 }
00476
00477
00478
00479
00480
00481
00482
00483 static struct expr *IfParse(
00484 void *theEnv,
00485 struct expr *top,
00486 char *infile)
00487 {
00488 struct token theToken;
00489
00490
00491
00492
00493
00494 SavePPBuffer(theEnv," ");
00495
00496 top->argList = ParseAtomOrExpression(theEnv,infile,NULL);
00497
00498 if (top->argList == NULL)
00499 {
00500 ReturnExpression(theEnv,top);
00501 return(NULL);
00502 }
00503
00504
00505
00506
00507
00508 IncrementIndentDepth(theEnv,3);
00509 PPCRAndIndent(theEnv);
00510
00511 GetToken(theEnv,infile,&theToken);
00512 if ((theToken.type != SYMBOL) || (strcmp(ValueToString(theToken.value),"then") != 0))
00513 {
00514 SyntaxErrorMessage(theEnv,"if function");
00515 ReturnExpression(theEnv,top);
00516 return(NULL);
00517 }
00518
00519
00520
00521
00522
00523 PPCRAndIndent(theEnv);
00524 if (ExpressionData(theEnv)->svContexts->rtn == TRUE)
00525 ExpressionData(theEnv)->ReturnContext = TRUE;
00526 if (ExpressionData(theEnv)->svContexts->brk == TRUE)
00527 ExpressionData(theEnv)->BreakContext = TRUE;
00528 top->argList->nextArg = GroupActions(theEnv,infile,&theToken,TRUE,"else",FALSE);
00529
00530 if (top->argList->nextArg == NULL)
00531 {
00532 ReturnExpression(theEnv,top);
00533 return(NULL);
00534 }
00535
00536 top->argList->nextArg = RemoveUnneededProgn(theEnv,top->argList->nextArg);
00537
00538
00539
00540
00541
00542 if (theToken.type == RPAREN)
00543 {
00544 DecrementIndentDepth(theEnv,3);
00545 PPBackup(theEnv);
00546 PPBackup(theEnv);
00547 SavePPBuffer(theEnv,theToken.printForm);
00548 return(top);
00549 }
00550
00551
00552
00553
00554
00555 if ((theToken.type != SYMBOL) || (strcmp(ValueToString(theToken.value),"else") != 0))
00556 {
00557 SyntaxErrorMessage(theEnv,"if function");
00558 ReturnExpression(theEnv,top);
00559 return(NULL);
00560 }
00561
00562
00563
00564
00565
00566 PPCRAndIndent(theEnv);
00567 top->argList->nextArg->nextArg = GroupActions(theEnv,infile,&theToken,TRUE,NULL,FALSE);
00568
00569 if (top->argList->nextArg->nextArg == NULL)
00570 {
00571 ReturnExpression(theEnv,top);
00572 return(NULL);
00573 }
00574
00575 top->argList->nextArg->nextArg = RemoveUnneededProgn(theEnv,top->argList->nextArg->nextArg);
00576
00577
00578
00579
00580
00581 if (theToken.type != RPAREN)
00582 {
00583 SyntaxErrorMessage(theEnv,"if function");
00584 ReturnExpression(theEnv,top);
00585 return(NULL);
00586 }
00587
00588
00589
00590
00591
00592 PPBackup(theEnv);
00593 PPBackup(theEnv);
00594 SavePPBuffer(theEnv,")");
00595 DecrementIndentDepth(theEnv,3);
00596 return(top);
00597 }
00598
00599
00600
00601
00602
00603
00604 static struct expr *PrognParse(
00605 void *theEnv,
00606 struct expr *top,
00607 char *infile)
00608 {
00609 struct token tkn;
00610 struct expr *tmp;
00611
00612 ReturnExpression(theEnv,top);
00613 ExpressionData(theEnv)->BreakContext = ExpressionData(theEnv)->svContexts->brk;
00614 ExpressionData(theEnv)->ReturnContext = ExpressionData(theEnv)->svContexts->rtn;
00615 IncrementIndentDepth(theEnv,3);
00616 PPCRAndIndent(theEnv);
00617 tmp = GroupActions(theEnv,infile,&tkn,TRUE,NULL,FALSE);
00618 DecrementIndentDepth(theEnv,3);
00619 PPBackup(theEnv);
00620 PPBackup(theEnv);
00621 SavePPBuffer(theEnv,tkn.printForm);
00622 return(tmp);
00623 }
00624
00625
00626
00627
00628
00629
00630 static struct expr *BindParse(
00631 void *theEnv,
00632 struct expr *top,
00633 char *infile)
00634 {
00635 struct token theToken;
00636 SYMBOL_HN *variableName;
00637 struct expr *texp;
00638 CONSTRAINT_RECORD *theConstraint = NULL;
00639 #if DEFGLOBAL_CONSTRUCT
00640 struct defglobal *theGlobal;
00641 int count;
00642 #endif
00643
00644 SavePPBuffer(theEnv," ");
00645
00646
00647
00648
00649
00650
00651 GetToken(theEnv,infile,&theToken);
00652 if ((theToken.type != SF_VARIABLE) && (theToken.type != GBL_VARIABLE))
00653 {
00654 if ((theToken.type != MF_VARIABLE) || ExpressionData(theEnv)->SequenceOpMode)
00655 {
00656 SyntaxErrorMessage(theEnv,"bind function");
00657 ReturnExpression(theEnv,top);
00658 return(NULL);
00659 }
00660 }
00661
00662
00663
00664
00665
00666 top->argList = GenConstant(theEnv,SYMBOL,theToken.value);
00667 variableName = (SYMBOL_HN *) theToken.value;
00668
00669 #if DEFGLOBAL_CONSTRUCT
00670 if ((theToken.type == GBL_VARIABLE) ?
00671 ((theGlobal = (struct defglobal *)
00672 FindImportedConstruct(theEnv,"defglobal",NULL,ValueToString(variableName),
00673 &count,TRUE,FALSE)) != NULL) :
00674 FALSE)
00675 {
00676 top->argList->type = DEFGLOBAL_PTR;
00677 top->argList->value = (void *) theGlobal;
00678 }
00679 else if (theToken.type == GBL_VARIABLE)
00680 {
00681 GlobalReferenceErrorMessage(theEnv,ValueToString(variableName));
00682 ReturnExpression(theEnv,top);
00683 return(NULL);
00684 }
00685 #endif
00686
00687 texp = get_struct(theEnv,expr);
00688 texp->argList = texp->nextArg = NULL;
00689 if (CollectArguments(theEnv,texp,infile) == NULL)
00690 {
00691 ReturnExpression(theEnv,top);
00692 return(NULL);
00693 }
00694
00695 top->argList->nextArg = texp->argList;
00696 rtn_struct(theEnv,expr,texp);
00697
00698 #if DEFGLOBAL_CONSTRUCT
00699 if (top->argList->type == DEFGLOBAL_PTR) return(top);
00700 #endif
00701
00702 if (top->argList->nextArg != NULL)
00703 { theConstraint = ExpressionToConstraintRecord(theEnv,top->argList->nextArg); }
00704
00705 AddBindName(theEnv,variableName,theConstraint);
00706
00707 return(top);
00708 }
00709
00710
00711
00712
00713 static struct expr *ReturnParse(
00714 void *theEnv,
00715 struct expr *top,
00716 char *infile)
00717 {
00718 int error_flag = FALSE;
00719 struct token theToken;
00720
00721 if (ExpressionData(theEnv)->svContexts->rtn == TRUE)
00722 ExpressionData(theEnv)->ReturnContext = TRUE;
00723 if (ExpressionData(theEnv)->ReturnContext == FALSE)
00724 {
00725 PrintErrorID(theEnv,"PRCDRPSR",2,TRUE);
00726 EnvPrintRouter(theEnv,WERROR,"The return function is not valid in this context.\n");
00727 ReturnExpression(theEnv,top);
00728 return(NULL);
00729 }
00730 ExpressionData(theEnv)->ReturnContext = FALSE;
00731
00732 SavePPBuffer(theEnv," ");
00733
00734 top->argList = ArgumentParse(theEnv,infile,&error_flag);
00735 if (error_flag)
00736 {
00737 ReturnExpression(theEnv,top);
00738 return(NULL);
00739 }
00740 else if (top->argList == NULL)
00741 {
00742 PPBackup(theEnv);
00743 PPBackup(theEnv);
00744 SavePPBuffer(theEnv,")");
00745 }
00746 else
00747 {
00748 SavePPBuffer(theEnv," ");
00749 GetToken(theEnv,infile,&theToken);
00750 if (theToken.type != RPAREN)
00751 {
00752 SyntaxErrorMessage(theEnv,"return function");
00753 ReturnExpression(theEnv,top);
00754 return(NULL);
00755 }
00756 PPBackup(theEnv);
00757 PPBackup(theEnv);
00758 SavePPBuffer(theEnv,")");
00759 }
00760 return(top);
00761 }
00762
00763
00764
00765
00766 static struct expr *BreakParse(
00767 void *theEnv,
00768 struct expr *top,
00769 char *infile)
00770 {
00771 struct token theToken;
00772
00773 if (ExpressionData(theEnv)->svContexts->brk == FALSE)
00774 {
00775 PrintErrorID(theEnv,"PRCDRPSR",2,TRUE);
00776 EnvPrintRouter(theEnv,WERROR,"The break function not valid in this context.\n");
00777 ReturnExpression(theEnv,top);
00778 return(NULL);
00779 }
00780
00781 SavePPBuffer(theEnv," ");
00782 GetToken(theEnv,infile,&theToken);
00783 if (theToken.type != RPAREN)
00784 {
00785 SyntaxErrorMessage(theEnv,"break function");
00786 ReturnExpression(theEnv,top);
00787 return(NULL);
00788 }
00789 PPBackup(theEnv);
00790 PPBackup(theEnv);
00791 SavePPBuffer(theEnv,")");
00792 return(top);
00793 }
00794
00795
00796
00797
00798 static struct expr *SwitchParse(
00799 void *theEnv,
00800 struct expr *top,
00801 char *infile)
00802 {
00803 struct token theToken;
00804 EXPRESSION *theExp,*chk;
00805 int default_count = 0;
00806
00807
00808
00809
00810 IncrementIndentDepth(theEnv,3);
00811 SavePPBuffer(theEnv," ");
00812 top->argList = theExp = ParseAtomOrExpression(theEnv,infile,NULL);
00813 if (theExp == NULL)
00814 goto SwitchParseError;
00815
00816
00817
00818
00819 GetToken(theEnv,infile,&theToken);
00820 while (theToken.type != RPAREN)
00821 {
00822 PPBackup(theEnv);
00823 PPCRAndIndent(theEnv);
00824 SavePPBuffer(theEnv,theToken.printForm);
00825 if (theToken.type != LPAREN)
00826 goto SwitchParseErrorAndMessage;
00827 GetToken(theEnv,infile,&theToken);
00828 SavePPBuffer(theEnv," ");
00829 if ((theToken.type == SYMBOL) &&
00830 (strcmp(ValueToString(theToken.value),"case") == 0))
00831 {
00832 if (default_count != 0)
00833 goto SwitchParseErrorAndMessage;
00834 theExp->nextArg = ParseAtomOrExpression(theEnv,infile,NULL);
00835 SavePPBuffer(theEnv," ");
00836 if (theExp->nextArg == NULL)
00837 goto SwitchParseError;
00838 for (chk = top->argList->nextArg ; chk != theExp->nextArg ; chk = chk->nextArg)
00839 {
00840 if ((chk->type == theExp->nextArg->type) &&
00841 (chk->value == theExp->nextArg->value) &&
00842 IdenticalExpression(chk->argList,theExp->nextArg->argList))
00843 {
00844 PrintErrorID(theEnv,"PRCDRPSR",3,TRUE);
00845 EnvPrintRouter(theEnv,WERROR,"Duplicate case found in switch function.\n");
00846 goto SwitchParseError;
00847 }
00848 }
00849 GetToken(theEnv,infile,&theToken);
00850 if ((theToken.type != SYMBOL) ? TRUE :
00851 (strcmp(ValueToString(theToken.value),"then") != 0))
00852 goto SwitchParseErrorAndMessage;
00853 }
00854 else if ((theToken.type == SYMBOL) &&
00855 (strcmp(ValueToString(theToken.value),"default") == 0))
00856 {
00857 if (default_count)
00858 goto SwitchParseErrorAndMessage;
00859 theExp->nextArg = GenConstant(theEnv,RVOID,NULL);
00860 default_count = 1;
00861 }
00862 else
00863 goto SwitchParseErrorAndMessage;
00864 theExp = theExp->nextArg;
00865 if (ExpressionData(theEnv)->svContexts->rtn == TRUE)
00866 ExpressionData(theEnv)->ReturnContext = TRUE;
00867 if (ExpressionData(theEnv)->svContexts->brk == TRUE)
00868 ExpressionData(theEnv)->BreakContext = TRUE;
00869 IncrementIndentDepth(theEnv,3);
00870 PPCRAndIndent(theEnv);
00871 theExp->nextArg = GroupActions(theEnv,infile,&theToken,TRUE,NULL,FALSE);
00872 DecrementIndentDepth(theEnv,3);
00873 ExpressionData(theEnv)->ReturnContext = FALSE;
00874 ExpressionData(theEnv)->BreakContext = FALSE;
00875 if (theExp->nextArg == NULL)
00876 goto SwitchParseError;
00877 theExp = theExp->nextArg;
00878 PPBackup(theEnv);
00879 PPBackup(theEnv);
00880 SavePPBuffer(theEnv,theToken.printForm);
00881 GetToken(theEnv,infile,&theToken);
00882 }
00883 DecrementIndentDepth(theEnv,3);
00884 return(top);
00885
00886 SwitchParseErrorAndMessage:
00887 SyntaxErrorMessage(theEnv,"switch function");
00888 SwitchParseError:
00889 ReturnExpression(theEnv,top);
00890 DecrementIndentDepth(theEnv,3);
00891 return(NULL);
00892 }
00893
00894
00895
00896
00897 globle int SearchParsedBindNames(
00898 void *theEnv,
00899 SYMBOL_HN *name_sought)
00900 {
00901 struct BindInfo *var_ptr;
00902 int theIndex = 1;
00903
00904 var_ptr = ProcedureParserData(theEnv)->ListOfParsedBindNames;
00905 while (var_ptr != NULL)
00906 {
00907 if (var_ptr->name == name_sought)
00908 { return(theIndex); }
00909 var_ptr = var_ptr->next;
00910 theIndex++;
00911 }
00912
00913 return(0);
00914 }
00915
00916
00917
00918
00919 globle struct constraintRecord *FindBindConstraints(
00920 void *theEnv,
00921 SYMBOL_HN *nameSought)
00922 {
00923 struct BindInfo *theVariable;
00924
00925 theVariable = ProcedureParserData(theEnv)->ListOfParsedBindNames;
00926 while (theVariable != NULL)
00927 {
00928 if (theVariable->name == nameSought)
00929 { return(theVariable->constraints); }
00930 theVariable = theVariable->next;
00931 }
00932
00933 return(NULL);
00934 }
00935
00936
00937
00938
00939
00940
00941 globle int CountParsedBindNames(
00942 void *theEnv)
00943 {
00944 struct BindInfo *theVariable;
00945 int theIndex = 0;
00946
00947 theVariable = ProcedureParserData(theEnv)->ListOfParsedBindNames;
00948 while (theVariable != NULL)
00949 {
00950 theVariable = theVariable->next;
00951 theIndex++;
00952 }
00953
00954 return(theIndex);
00955 }
00956
00957
00958
00959
00960
00961
00962 static int AddBindName(
00963 void *theEnv,
00964 SYMBOL_HN *variableName,
00965 CONSTRAINT_RECORD *theConstraint)
00966 {
00967 CONSTRAINT_RECORD *tmpConstraint;
00968 struct BindInfo *currentBind, *lastBind;
00969 int theIndex = 1;
00970
00971
00972
00973
00974
00975
00976
00977
00978 lastBind = NULL;
00979 currentBind = ProcedureParserData(theEnv)->ListOfParsedBindNames;
00980 while (currentBind != NULL)
00981 {
00982 if (currentBind->name == variableName)
00983 {
00984 if (theConstraint != NULL)
00985 {
00986 tmpConstraint = currentBind->constraints;
00987 currentBind->constraints = UnionConstraints(theEnv,theConstraint,currentBind->constraints);
00988 RemoveConstraint(theEnv,tmpConstraint);
00989 RemoveConstraint(theEnv,theConstraint);
00990 }
00991
00992 return(theIndex);
00993 }
00994 lastBind = currentBind;
00995 currentBind = currentBind->next;
00996 theIndex++;
00997 }
00998
00999
01000
01001
01002
01003
01004 currentBind = get_struct(theEnv,BindInfo);
01005 currentBind->name = variableName;
01006 currentBind->constraints = theConstraint;
01007 currentBind->next = NULL;
01008
01009 if (lastBind == NULL) ProcedureParserData(theEnv)->ListOfParsedBindNames = currentBind;
01010 else lastBind->next = currentBind;
01011
01012 return(theIndex);
01013 }
01014
01015
01016
01017
01018 globle void RemoveParsedBindName(
01019 void *theEnv,
01020 struct symbolHashNode *bname)
01021 {
01022 struct BindInfo *prv,*tmp;
01023
01024 prv = NULL;
01025 tmp = ProcedureParserData(theEnv)->ListOfParsedBindNames;
01026 while ((tmp != NULL) ? (tmp->name != bname) : FALSE)
01027 {
01028 prv = tmp;
01029 tmp = tmp->next;
01030 }
01031 if (tmp != NULL)
01032 {
01033 if (prv == NULL)
01034 ProcedureParserData(theEnv)->ListOfParsedBindNames = tmp->next;
01035 else
01036 prv->next = tmp->next;
01037
01038 RemoveConstraint(theEnv,tmp->constraints);
01039 rtn_struct(theEnv,BindInfo,tmp);
01040 }
01041 }
01042
01043 #endif
01044
01045 #endif
01046