mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-22 01:31:33 +00:00
Upgrades to c02 compiler
This commit is contained in:
parent
80c75bdb5e
commit
0d45fa4cbd
@ -79,7 +79,7 @@ void prscmp(int revrse) {
|
||||
if (cmpenc != 0) cmprtr = cmprtr | cmpenc; //Combine Encoded Comparator
|
||||
}
|
||||
skpspc();
|
||||
if (cmprtr) prstrm(FALSE);
|
||||
if (cmprtr) prstrm(FALSE, TRUE);
|
||||
//prccmp(); - Do after check for logical operator
|
||||
DEBUG("Parsed comparator %d\n", cmprtr)
|
||||
}
|
||||
|
27
src/expr.c
27
src/expr.c
@ -21,7 +21,7 @@ void pshtrm(void) {
|
||||
strcpy(trmstk[trmidx], term); //Put Current Term on Stack
|
||||
trmidx++; //Increment Stack Pointer
|
||||
DEBUG("expr.pshtrm: Pushed term %s ", term)
|
||||
DETAIL("and operator '%onto stack'\n", oper)
|
||||
DETAIL("and operator '%c' onto stack\n", oper)
|
||||
}
|
||||
|
||||
/* Pop Term and Operator off Stack */
|
||||
@ -153,7 +153,7 @@ int prcptr(void) {
|
||||
} else if (cmos) {
|
||||
sprintf(word, "(%s)", term);
|
||||
} else {
|
||||
asmlin("LDY","0");
|
||||
asmlin("LDY","#0");
|
||||
sprintf(word, "(%s),Y", term);
|
||||
}
|
||||
strcpy(term, word);
|
||||
@ -161,12 +161,17 @@ int prcptr(void) {
|
||||
return FALSE; //Return Value Not an Integer
|
||||
}
|
||||
|
||||
/* Parse Term in Expression *
|
||||
* Sets: term - the term (as a string) *
|
||||
* Returns: TRUE if term is an integer */
|
||||
int prstrm(int alwint) {
|
||||
/* Parse Term in Expression *
|
||||
* Args: alwint: Allow Integer Value *
|
||||
* alwptr: Allow Pointer Dereference *
|
||||
* Sets: term - the term (as a string) *
|
||||
* Returns: TRUE if term is an integer */
|
||||
int prstrm(int alwint, int alwptr) {
|
||||
DEBUG("expr.prstrm: Parsing term\n", 0)
|
||||
if (match('*')) return prcptr(); //Parse and Deference Pointer
|
||||
if (match('*')) {
|
||||
if (alwptr)return prcptr(); //Parse and Deference Pointer
|
||||
else ERROR("Pointer dereference not allowed\n", 0, EXIT_FAILURE)
|
||||
}
|
||||
prsval(FALSE, TRUE); //Parse Value - Disallow Registers, Allow Constants
|
||||
if (valtyp == FUNCTION) ERROR("Function call only allowed in first term\n", 0, EXIT_FAILURE)
|
||||
strcpy(term, value);
|
||||
@ -263,16 +268,14 @@ void prsfpr(char trmntr) {
|
||||
if (look('.')) pusha = 255;
|
||||
else {if (prsxpf(0)) goto prsfne;}
|
||||
if (look(',') && !chkadr(ADLDYX, TRUE)) {
|
||||
if (look('.')) {
|
||||
pushy = -1;
|
||||
}
|
||||
if (look('.')) { pushy = -1; }
|
||||
else {
|
||||
if (look('(')) {
|
||||
if (pusha==0) {pusha = 1; asmlin("PHA","");} //Save A on Stack
|
||||
prsxpr(')'); asmlin("TAY", ""); //Evaluate Expression, and Copy to Y
|
||||
}
|
||||
else {
|
||||
if (prstrm(TRUE)) goto prsfne;
|
||||
if (prstrm(TRUE, FALSE)) goto prsfne;
|
||||
asmlin("LDY", term);
|
||||
}
|
||||
}
|
||||
@ -389,7 +392,7 @@ void prsrxp(char trmntr) {
|
||||
while (isoper()) {
|
||||
trmcnt++; //Increment Expression Depth
|
||||
prsopr(); //Parse Operator
|
||||
prstrm(FALSE); //Parse Term
|
||||
prstrm(FALSE, TRUE); //Parse Term
|
||||
prcopr(); //Process Operator
|
||||
trmcnt--; //Decrement Expression Depth
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ void prsfnc(char trmntr); //Parse function call
|
||||
void prsfpr(char trmntr); //Parse Function Paraeters or Return
|
||||
void prsidx(); //Parse Array Index
|
||||
void prsptr(void); //Parse Pointer
|
||||
int prstrm(int alwint); //Parse Term in Expression
|
||||
int prstrm(int alwint, int alwptr); //Parse Term in Expression
|
||||
void prsrxp(char trmntr); //Parse Rest of Expression
|
||||
int prsxpf(char trmntr); //Parse Expression in Function Call
|
||||
void prsxpr(char trmntr); //Parse Expression
|
||||
|
@ -21,11 +21,13 @@
|
||||
/* Read next include file name from Source File *
|
||||
* Sets: incnam - the include file name */
|
||||
void pincnm(void) {
|
||||
DEBUG("Parsing include file name", 0)
|
||||
char dlmtr;
|
||||
int inclen = 0;
|
||||
int sublen[SUBMAX];
|
||||
skpspc();
|
||||
dlmtr = getnxt();
|
||||
DETAIL(" with delimiter '%c'\n", dlmtr)
|
||||
if (dlmtr == '<') {
|
||||
strcpy(incnam, incdir);
|
||||
inclen = strlen(incnam);
|
||||
|
@ -38,7 +38,7 @@ int isspc(void) {return isspace(nxtchr);}
|
||||
int isszop(void) {return match('@');}
|
||||
int isvpre(void) {return TF(isalph() || islpre());}
|
||||
int isxfop(void) {return match('?');}
|
||||
int isxpre(void) {return TF(isvpre() || match('-'));}
|
||||
int isxpre(void) {return TF(isvpre() || match('-') || match('*'));}
|
||||
|
||||
/* Process ASCII Character */
|
||||
char prcchr(char c) {
|
||||
|
45
src/stmnt.c
45
src/stmnt.c
@ -198,16 +198,21 @@ void prcavr(char trmntr) {
|
||||
prsvar(FALSE, FALSE); //get variable name
|
||||
strcpy(ysnvar, word);
|
||||
DEBUG("stmnt.prcvar: Set STY variable to %s\n", ysnvar)
|
||||
if (valtyp == ARRAY) ysnivt = getidx(ysnidx); //Get Array Index and Type
|
||||
else ysnidx[0] = 0;
|
||||
DEBUG("stmnt.prcvar: Set STY index to '%s'", ysnidx) DETAIL(" and type to %d\n", ysnivt)
|
||||
if (look(',')) {
|
||||
prsvar(FALSE, FALSE); //get variable name
|
||||
strcpy(xsnvar, word);
|
||||
DEBUG("stmnt.prcvar: Set STX variable to %s\n", xsnvar)
|
||||
//if (valtyp == ARRAY) ERROR("Array element not allowed in third assignment\n", 0, EXIT_FAILURE)
|
||||
if (valtyp == ARRAY) xsnivt = getidx(xsnidx); //Get Array Index and Type
|
||||
else xsnidx[0] = 0;
|
||||
if (vartyp == VTINT) {
|
||||
strcpy(xsnvar, ysnvar); //Set Assignment LSB
|
||||
strcat(ysnvar, "+1"); //Set Assignment MSB
|
||||
} else {
|
||||
if (valtyp == ARRAY) ysnivt = getidx(ysnidx); //Get Array Index and Type
|
||||
else ysnidx[0] = 0;
|
||||
DEBUG("stmnt.prcvar: Set STY index to '%s'", ysnidx) DETAIL(" and type to %d\n", ysnivt)
|
||||
if (look(',')) {
|
||||
prsvar(FALSE, FALSE); //get variable name
|
||||
strcpy(xsnvar, word);
|
||||
DEBUG("stmnt.prcvar: Set STX variable to %s\n", xsnvar)
|
||||
//if (valtyp == ARRAY) ERROR("Array element not allowed in third assignment\n", 0, EXIT_FAILURE)
|
||||
if (valtyp == ARRAY) xsnivt = getidx(xsnidx); //Get Array Index and Type
|
||||
else xsnidx[0] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
prcasn(trmntr, FALSE);
|
||||
@ -348,17 +353,23 @@ void pgoto(void) {
|
||||
|
||||
/* parse and compile inline statement */
|
||||
void pinlne(void) {
|
||||
int i; //For Parsing Integers
|
||||
DEBUG("stmnt.pinlne: Parsing INLINE statement\n", 0)
|
||||
do {
|
||||
DEBUG("stmnt.pinlne: Parsing inline parameter\n", 0)
|
||||
if (look('&')) {
|
||||
reqvar(FALSE); //Get Variable Name
|
||||
strcpy(word, "<");
|
||||
strcat(word, value);
|
||||
strcat(word, ", >");
|
||||
strcat(word, value);
|
||||
if (isnpre()) {
|
||||
i = prsnum(0xFFFF);
|
||||
sprintf(word, "$%02x,$%02x", i & 0xFF, i >> 8);
|
||||
} else {
|
||||
reqvar(FALSE); //Get Variable Name
|
||||
strcpy(word, "<");
|
||||
strcat(word, value);
|
||||
strcat(word, ", >");
|
||||
strcat(word, value);
|
||||
}
|
||||
asmlin(BYTEOP, word);
|
||||
}
|
||||
}
|
||||
else if (look('"')) {
|
||||
value[0] = 0;
|
||||
while (!match('"')) {
|
||||
@ -456,7 +467,7 @@ void pcase(void) {
|
||||
newlbl(cndlbl); //Create Conditional Label
|
||||
pshlbl(LTCASE, cndlbl); //and Push onto Stack
|
||||
while(TRUE) {
|
||||
prstrm(FALSE); //Parse CASE argument
|
||||
prstrm(FALSE, TRUE); //Parse CASE argument
|
||||
if (!fcase || valtyp != LITERAL || litval)
|
||||
asmlin("CMP", term); //Emit Comparison
|
||||
if (look(',')) {
|
||||
|
Loading…
Reference in New Issue
Block a user