diff --git a/src/expr.c b/src/expr.c index 627313d..9148ff9 100644 --- a/src/expr.c +++ b/src/expr.c @@ -122,31 +122,38 @@ void prstrm(void) { skpspc(); } -/* Process Address Reference */ +/* Process Address Reference + * Args: adract = Address Action (adacts) * + * symbol = Symbol to Process */ void prcadr(int adract, char* symbol) { DEBUG("Processing address '%s'\n", word) strcpy(word,"#>("); strcat(word,symbol); strcat(word,")"); - if (adract == 1) { asmlin("LDA", word); asmlin("PHA", ""); } + if (adract == ADPUSH) { asmlin("LDA", word); asmlin("PHA", ""); } else asmlin("LDY", word); strcpy(word,"#<("); strcat(word,symbol); strcat(word,")"); - if (adract == 1) { asmlin("LDA", word); asmlin("PHA", ""); } + if (adract == ADPUSH) { asmlin("LDA", word); asmlin("PHA", ""); } else asmlin("LDX", word); } -/* Parse and Compile Address of Operator */ +/* Parse and Compile Address of Operator * + * Args: adract = Address Action */ void prsadr(int adract) { DEBUG("Parsing address\n", 0) if (isnpre()) prsnum(0xFFFF); else prsvar(FALSE, TRUE); - prcadr(adract, value); //Compile Address Reference + if (adract) prcadr(adract, value); //Compile Address Reference + else strcpy(word, value); //Save for Calling Routine } -/* Parse and Create Anonymous String */ -void prsstr(int adract) { +/* Parse and Create Anonymous String * + * Args: adract = Address Action * + * alwstr = Allow String */ +void prsstr(int adract, int alwstr) { + if (!alwstr) ERROR("Illegal String Reference", 0, EXIT_FAILURE) DEBUG("Parsing anonymous string\n", 0) newlbl(vrname); //Generate Variable Name value[0] = 0; //Use Variable Size 0 @@ -154,15 +161,18 @@ void prsstr(int adract) { prsdts(); //Parse Data String setdat(); //Set Variable Data varcnt++; //Increment Variable Counter - prcadr(adract, vrname); //Compile Address Reference + if (adract) prcadr(adract, vrname); //Compile Address Reference + else strcpy(word, vrname); //Save for Calling Routine } -/* Check for and Process Address or String */ -int chkadr(int adract) { +/* Check for and Process Address or String * + * Args: adract = Address Action * + * alwstr = Allow String */ +int chkadr(int adract, int alwstr) { DEBUG("Checking for Address or String\n", 0) int result = TRUE; if (look('&')) prsadr(adract); - else if (match('"')) prsstr(adract); + else if (match('"')) prsstr(adract, alwstr); else result = FALSE; skpspc(); return result; @@ -175,9 +185,9 @@ void prsfnc(char trmntr) { pshtrm(); //Push Function Name onto Term Stack skpchr(); //skip open paren CCMNT('('); - if (!chkadr(0) && isxpre() || match('*')) { + if (!chkadr(ADLDYX, TRUE) && isxpre() || match('*')) { if (!look('*')) prsxpr(0); - if (look(',') && !chkadr(0)) { + if (look(',') && !chkadr(ADLDYX, TRUE)) { if (!look('*')) { prstrm(); asmlin("LDY", term); } diff --git a/src/expr.h b/src/expr.h index a80d561..a8f5de9 100644 --- a/src/expr.h +++ b/src/expr.h @@ -2,6 +2,8 @@ * C02 Expession Parsing Routines * **********************************/ +enum adacts {ADNONE, ADLDYX, ADPUSH}; + char term[255]; //Term parsed from equation char oprstk[MAXTRM]; //Operator Stack @@ -10,7 +12,7 @@ int trmidx; //Next Index in Stack int trmcnt; //Number of total terms in current expression -int chkadr(int adract); //Check for and Process Address or String +int chkadr(int adract, int alwstr); //Check for and Process Address or String void chkidx(); //Check for, Parse, and Process Index void prcftm(); //Process First Term void prsadr(int adract); //Parse and Compile Address of Operator diff --git a/src/parse.h b/src/parse.h index 024eee5..bfadb46 100644 --- a/src/parse.h +++ b/src/parse.h @@ -4,7 +4,7 @@ #define TF(x) (x) ? TRUE : FALSE; -enum stypes {LITERAL, VARIABLE, REGISTER, ARRAY, STRUCTURE, FUNCTION}; //Symbol Types +enum stypes {LITERAL, VARIABLE, REGISTER, ARRAY, STRUCTURE, FUNCTION, ADDRESS, INTEGER}; //Symbol Types enum etypes {ETDEF, ETMAC}; //Definition Types char nxtwrd[LINELEN]; //Next Word (from DEFINE lookup) diff --git a/src/stmnt.c b/src/stmnt.c index d5fcc51..b94d7fd 100644 --- a/src/stmnt.c +++ b/src/stmnt.c @@ -274,7 +274,7 @@ void pelse(void) { /* parse and compile if statement */ void pgoto(void) { DEBUG("Parsing GOTO statement\n", 0) - getwrd(); + if (!chkadr(ADNONE, FALSE)) getwrd(); expect(';'); asmlin("JMP", word); } @@ -333,7 +333,7 @@ void ppop(void) { void ppush(void) { DEBUG("Parsing PUSH statement\n", 0) do { - if (!chkadr(1)) { + if (!chkadr(ADPUSH, TRUE)) { prsxpr(0); //Parse Expression asmlin("PHA",""); //Push Result on Stack } diff --git a/src/vars.h b/src/vars.h index b6171f7..0598041 100644 --- a/src/vars.h +++ b/src/vars.h @@ -57,6 +57,12 @@ enum dtypes {DTBYTE, DTSTR, DTARRY}; //Variable Data Types #define MTZP 4 //Zero Page #define MTALGN 128 //Aligned +/*Value Parsing Flags (BitMask) */ +#define ALWDEF 0 //Allow Default +#define ALWREG 1 //Allow Register +#define ALWCON 2 //Allow CONST Variable +#define ALWINT 4 //Allow Integer + int symdef(char *name); //Is Variable defined (TRUE or FALSE) int rambas; //RAM Base Address (0=None) int wrtbas; //Write Base Address (0=None)