diff --git a/c02.c b/c02.c index d041b8d..8a7fab8 100644 --- a/c02.c +++ b/c02.c @@ -45,6 +45,7 @@ void init() vrwrtn = FALSE; zpaddr = 0; invasc = FALSE; + fcase = FALSE; } /* Reads and parses the next Word in Source File */ @@ -54,8 +55,12 @@ void pword() getwrd(); ACMNT(word); DEBUG("Parsing Word '%s'\n", word); - if (xstmnt[0] && !wordis(xstmnt)) + if (xstmnt[0]) { + if (wordis(xstmnt)) + xstmnt[0] = 0; //Clear xstmnt + else ERROR("Expected '%s' statement\n", xstmnt, EXIT_FAILURE); + } if (!pmodfr() && !ptype(MTNONE)) pstmnt(); //Parse Statement } diff --git a/common.h b/common.h index 2895685..5c8a4ed 100644 --- a/common.h +++ b/common.h @@ -56,6 +56,7 @@ char inpnam[FNAMLEN]; //Include File Name int alcvar; //Allocate Variables Flag int inblck; //Multiline Block Flag int lsrtrn; //Last Statement was a Return +int fcase; //First Case Statement void exterr(int errnum); //Print current file name & position and exit void expctd(char *expected); //Print Expected message and exit diff --git a/stmnt.c b/stmnt.c index 05a7ba6..f3d89aa 100644 --- a/stmnt.c +++ b/stmnt.c @@ -323,8 +323,9 @@ void pslct() { expect('('); prsxpr(')'); //Parse Expression newlbl(endlbl); //Create New Label - pshlbl(LTSLCT,endlbl); //Push Onto Stack + pshlbl(LTSLCT,endlbl); //Push Onto Stack bgnblk('{'); //Require Beginning of Block + fcase = TRUE; strcpy(xstmnt, "CASE"); //Require Next Statement to be CASE } @@ -341,10 +342,7 @@ void ecase() { /* parse and compile select statement */ void pcase() { - int fcase = (strcmp(xstmnt, "CASE") == 0); - if (fcase) - xstmnt[0] = 0; //Clear xstmnt - else + if (!fcase) ecase("CASE"); //Process end of case block skplbl[0] = 0; //Clear Skip Label newlbl(cndlbl); //Create Conditional Label @@ -365,6 +363,7 @@ void pcase() { } if (skplbl[0]) setlbl(skplbl); //Set CASE block label if defined + fcase = FALSE; } /* parse and compile default statement */