diff --git a/src/expr.c b/src/expr.c index 06d834e..112f8d3 100644 --- a/src/expr.c +++ b/src/expr.c @@ -117,11 +117,7 @@ int prstrm(int alwint) { prsval(FALSE, TRUE); //Parse Term - Disallow Registers if (valtyp == FUNCTION) ERROR("Function call only allowed in first term\n", 0, EXIT_FAILURE) strcpy(term, value); - if (valtyp == VARIABLE && varble.type == VTINT) { - if (!alwint) ERROR("Illegal Use of Integer Variable %s\n", term, EXIT_FAILURE) - prcvri(); //Process Integer Variable - return TRUE; - } + if (valtyp == VARIABLE && prcvar(alwint)) return TRUE; DEBUG("Parsed term %s\n", term) chkidx(); //Check for Array Index skpspc(); @@ -184,7 +180,7 @@ int chkadr(int adract, int alwstr) { return result; } -/* Parse Function Parameters or Return Values */ +/* Parse Function Argument or Return Values */ void prsfpr(char trmntr) { if (!chkadr(ADLDYX, TRUE) && isxpre() || match('?')) { if (!look('?')) {if (prsxpf(0)) goto prsfne;} @@ -193,7 +189,11 @@ void prsfpr(char trmntr) { if (prstrm(TRUE)) goto prsfne; asmlin("LDY", term); } - if (look(',')) { prsval(FALSE, TRUE); asmlin("LDX", value); } + if (look(',')) { + prsval(FALSE, TRUE); + if (valtyp > VARIABLE) ERROR("Illegal Value Function Argument\n", 0, EXIT_FAILURE); + if (valtyp == VARIABLE && varble.type != VTCHAR) ERROR("Illegal Variable Type\n", 0, EXIT_FAILURE); + asmlin("LDX", value); } } } prsfne: @@ -222,15 +222,31 @@ void prcvri(void) { asmlin("LDY", value); } +/* Process Variable in Term */ +int prcvar(int alwint) { + switch (varble.type) { + case VTINT: + if (!alwint) ERROR("Illegal Use of Integer Variable %s\n", word, EXIT_FAILURE) + prcvri(); + return TRUE; + case VTARRAY: + if (!alwint) ERROR("Illegal Reference to Array %s\n", word, EXIT_FAILURE) + prcadr(ADNONE, term); + return TRUE; + case VTSTRUCT: + if (!alwint) ERROR("Illegal Reference to Struct %s\n", word, EXIT_FAILURE) + prcadr(ADNONE, term); + return TRUE; + default: + return FALSE; + } +} + /* Process first term of expression */ int prcftm(int alwint) { DEBUG("Processing first term '%s'\n", value) strcpy(term, value); - if (valtyp == VARIABLE && varble.type == VTINT) { - if (!alwint) ERROR("Illegal Use of Integer Variable %s\n", word, EXIT_FAILURE) - prcvri(); - return TRUE; - } + if (valtyp == VARIABLE && prcvar(alwint)) return TRUE; if (valtyp == FUNCTION) prsfnc(0); //Parse Expression Function else if (wordis("A")) return FALSE; else if (wordis("X")) asmlin("TXA", ""); diff --git a/src/expr.h b/src/expr.h index 2a1261d..8626094 100644 --- a/src/expr.h +++ b/src/expr.h @@ -16,6 +16,7 @@ int chkadr(int adract, int alwstr); //Check for and Process Address or String void chkidx(); //Check for, Parse, and Process Index int prcftm(int alwint); //Process First Term void prcvri(void); //Process Integer Variable +int prcvar(int alwint); //Process Variable in Term void prsadr(int adract); //Parse and Compile Address of Operator void prsval(int alwreg, int alwcon); //Parse Value void prsfnc(char trmntr); //Parse function call diff --git a/src/parse.c b/src/parse.c index 8a75e5f..2c8418d 100644 --- a/src/parse.c +++ b/src/parse.c @@ -336,6 +336,7 @@ void prslit(void) { int gettyp(void) { if (match('(')) return FUNCTION; else if (match('[')) return ARRAY; + else if (match('.')) return STRUCTURE; else return VARIABLE; } diff --git a/src/stmnt.c b/src/stmnt.c index 1e7d8fa..05b7a49 100644 --- a/src/stmnt.c +++ b/src/stmnt.c @@ -143,7 +143,7 @@ int getidx(char* idx) { } /* Process Assignment Variable(s) */ -void prcvar(char trmntr) { +void prcavr(char trmntr) { chksym(TRUE, FALSE, word); if (varble.type == VTINT) { if (ispopr()) {if (prspst(trmntr, TRUE, word, "")) expctd("post operator");} @@ -151,7 +151,7 @@ void prcvar(char trmntr) { return; } strcpy(asnvar, word); //save variable to assign to - if (valtyp == VARIABLE && match('.')) prsmbr(asnvar); + if (valtyp == STRUCTURE) prsmbr(asnvar); asntyp = valtyp; //Set Assigned Variable Type DEBUG("Set STA variable to %s\n", asnvar) if (asntyp == VARIABLE && look(';')) { @@ -210,7 +210,7 @@ void pasm(void) { /* Parse and Compile an Assignment */ void prsasn(char trmntr) { getwrd(); //Get Variable to be Assigned - prcvar(trmntr); + prcavr(trmntr); } /* parse and compile 'break'/'continue' statement */ @@ -461,7 +461,7 @@ void prssym(void) { DEBUG("Parsing Identifier %s\n", word) valtyp = gettyp(); if (valtyp == FUNCTION) prsfns(); //Parse Statement Function Call - else prcvar(';'); //Parse Assignment + else prcavr(';'); //Parse Assignment } /* parse and compile program statement */ diff --git a/src/vars.c b/src/vars.c index 57e5983..0664abe 100644 --- a/src/vars.c +++ b/src/vars.c @@ -113,7 +113,7 @@ void prsvar(int alwreg, int alwcon) { if (valtyp != FUNCTION) chksym(alwreg, alwcon, word); strcpy(value, word); DEBUG("Parsed variable '%s'\n", value) - if (valtyp == VARIABLE && match('.')) prsmbr(value); + if (valtyp == STRUCTURE) prsmbr(value); } /* Require and Parse Variable Name * @@ -219,7 +219,7 @@ void setdat(void) { } datlen[varcnt] = dlen; dattyp[varcnt] = dtype; - DEBUG("Total data alllocated: %d bytes\n", dsize) + DEBUG("Total data allocated: %d bytes\n", dsize) } /* Parse and store variable data */ @@ -251,7 +251,6 @@ void setvar(int m, int t) { /* Parse and Compile Variable Declaration * * Uses: word - variable name */ void addvar(int m, int t) { - //if (t == VTINT) ERROR("Integer Variables not yet Implemented\n", 0, EXIT_FAILURE) strcpy(vrname, word); //Save Variable Name if (fndvar(vrname)) ERROR("Duplicate declaration of variable '%s\n", vrname, EXIT_FAILURE) if (t == VTVOID) ERROR("Illegal Variable Type\n", 0, EXIT_FAILURE) @@ -273,6 +272,7 @@ void addvar(int m, int t) { prsvar(FALSE, FALSE); if (t == VTINT && varble.type != t) ERROR("ALIAS Type Mismatch\n", 0, EXIT_FAILURE) + if (t > VTINT) ERROR("Type may not be ALIASed\n", 0, EXIT_FAILURE) } asmlin(EQUOP, word); strcpy(value, "*"); //Set Variable to Non Allocated @@ -285,6 +285,7 @@ void addvar(int m, int t) { DEBUG("Setting variable size to %d\n", 2) sprintf(value, "%d", 2); } else if (match('[')) { + t = VTARRAY; //Set Type to Array CCMNT('[') skpchr(); if (alcvar) { @@ -295,9 +296,12 @@ void addvar(int m, int t) { } else value[0] = 0; if (!alcvar) strcpy(value, "*"); - } + } + if (look('=')) { + prsdat(m, t); //Parse Variable Data + if (dtype > DTINT) t = VTARRAY; + } setvar(m, t); //Add to Variable Table - if (look('=')) prsdat(m, t); //Parse Variable Data varcnt++; //Increment Variable Counter } diff --git a/src/vars.h b/src/vars.h index 5b69c8f..511c0bf 100644 --- a/src/vars.h +++ b/src/vars.h @@ -44,7 +44,7 @@ int mbrcnt; //Number of Struct Members Defined int mbridx; //Index into Struct Member Tables int mbrofs; //Member Offset -enum vtypes {VTVOID, VTCHAR, VTINT, VTSTRUCT}; //Variable Types +enum vtypes {VTVOID, VTREG, VTCHAR, VTINT, VTARRAY, VTSTRUCT}; //Variable Types char datvar[DATASPC+1]; //Variable Data Storage int datlen[MAXVAR+1]; //Variable Data Length diff --git a/work/test.c02 b/work/test.c02 index aaad050..161848c 100644 --- a/work/test.c02 +++ b/work/test.c02 @@ -88,13 +88,17 @@ funcx: f = testfn(b); //Simple Variable f = testfn(r[i]); //Array Element f = testfn(r[i],b); //Two Parameters +f = testfn(r[i],b); //Two Parameters +f = testfn(r[b],r[c]); //Two Array Elements f = testfn(r[1],r[2]); //Two Array Elements f = testfn(r[1],r[2],b); //Three Parameters -f = testfn(&s); //Pointer -f = testfn(b,&s); //Byte and Pointer -f = testfn(r[i],&s); //Array Element and Pointer -f = testfn(r[1],&s); //Array Element and Pointer -f = testfn(b+c+d,&s); //Expression in Function Call +f = testfn(s); //Implicit Address +f = testfn(&s); //Explicit Address +f = testfn(b,s); //Byte and Implicit Address +f = testfn(b,&s); //Byte and Explicit Address +f = testfn(r[i],s); //Array Element and Implicit Address +f = testfn(r[1],&s); //Array Element and Explicit Address +f = testfn(b+c+d,r); //Expression in Function Call f = testfn(getkey(b)+c); //Nested Function Call funcs: @@ -102,7 +106,8 @@ prchr(b+c+d); testfn(prchr(b)); testfn(b,c,d); testfn(b+c+d,r[i],f); -testfn(&s); //Print a String +testfn(&s); //Explicit Address Reference +testfn(s); //Implicit Address Reference dofn(?,yy); dofn(?,yy,xx); dofn(aa,?,xx);