mirror of
https://github.com/RevCurtisP/C02.git
synced 2025-02-23 02:29:21 +00:00
Removed extraneous semicolons after DEBUG macro invocations
This commit is contained in:
parent
f84affdb4a
commit
90c9162971
@ -35,7 +35,7 @@ void asmlin(char *opcode, char *oprnd) {
|
||||
|
||||
/* output a single comment line */
|
||||
void cmtlin(void) {
|
||||
DEBUG("Writing Comment Line: %s\n", cmtasm);
|
||||
DEBUG("Writing Comment Line: %s\n", cmtasm)
|
||||
fprintf(outfil, "; %s\n", cmtasm);
|
||||
setcmt("");
|
||||
}
|
||||
|
71
src/c02.c
71
src/c02.c
@ -27,7 +27,7 @@
|
||||
|
||||
/* Initilize Compiler Variables */
|
||||
void init(void) {
|
||||
DEBUG("Initializing Compiler Variables\n",0);
|
||||
DEBUG("Initializing Compiler Variables\n",0)
|
||||
defcnt = 0;
|
||||
varcnt = 0;
|
||||
lblcnt = 0;
|
||||
@ -52,15 +52,12 @@ void init(void) {
|
||||
void pword(void) {
|
||||
lsrtrn = FALSE; //Clear RETURN flag
|
||||
getwrd();
|
||||
DEBUG("Parsing Word '%s'\n", word);
|
||||
DEBUG("Parsing Word '%s'\n", word)
|
||||
if (xstmnt[0]) {
|
||||
if (wordis(xstmnt))
|
||||
xstmnt[0] = 0; //Clear xstmnt
|
||||
else
|
||||
ERROR("Expected '%s' statement\n", xstmnt, EXIT_FAILURE)
|
||||
if (wordis(xstmnt)) xstmnt[0] = 0; //Clear xstmnt
|
||||
else ERROR("Expected '%s' statement\n", xstmnt, EXIT_FAILURE)
|
||||
}
|
||||
if (!pmodfr() && !ptype(MTNONE))
|
||||
pstmnt(); //Parse Statement
|
||||
if (!pmodfr() && !ptype(MTNONE)) pstmnt(); //Parse Statement
|
||||
}
|
||||
|
||||
/* Process a directive */
|
||||
@ -68,7 +65,7 @@ void pdrctv(void) {
|
||||
skpchr(); //skip '#'
|
||||
CCMNT('#');
|
||||
getwrd(); //read directive into word
|
||||
DEBUG("Processing directive '%s'\n", word);
|
||||
DEBUG("Processing directive '%s'\n", word)
|
||||
if (wordis("DEFINE")) pdefin(); //Parse Define
|
||||
else if (wordis("ENUM")) penumd(); //Parse Enum Directive
|
||||
else if (wordis("INCLUDE")) pincfl(); //Parse Include File
|
||||
@ -78,7 +75,7 @@ void pdrctv(void) {
|
||||
}
|
||||
|
||||
void prolog(void) {
|
||||
DEBUG("Writing Assembly Prolog\n", 0);
|
||||
DEBUG("Writing Assembly Prolog\n", 0)
|
||||
asmlin(CPUOP,CPUARG);
|
||||
setcmt("Program ");
|
||||
addcmt(srcnam);
|
||||
@ -91,26 +88,19 @@ void epilog(void) {
|
||||
|
||||
/* Compile Source Code*/
|
||||
void compile(void) {
|
||||
DEBUG("Starting Compilation\n", 0);
|
||||
DEBUG("Starting Compilation\n", 0)
|
||||
prolog();
|
||||
phdrfl(); //Process Header File specified on Command Line
|
||||
skpchr();
|
||||
DEBUG("Parsing Code\n", 0);
|
||||
DEBUG("Parsing Code\n", 0)
|
||||
while (TRUE) {
|
||||
skpspc();
|
||||
//DEBUG("Checking next character '%c'\n", nxtchr);
|
||||
if (match(EOF))
|
||||
break;
|
||||
else if (match('}'))
|
||||
endblk(TRUE); //End Multi-Line Program Block
|
||||
else if (match('#'))
|
||||
pdrctv(); //Parse Directive
|
||||
else if (match('/'))
|
||||
skpcmt(); //Skip Comment
|
||||
else if (isalph())
|
||||
pword(); //Parse Word
|
||||
else
|
||||
ERROR("Unexpected character '%c'\n", nxtchr, EXIT_FAILURE)
|
||||
if (match(EOF)) break; //Stop Parsing (End of File)
|
||||
else if (match('}')) endblk(TRUE); //End Multi-Line Program Block
|
||||
else if (match('#')) pdrctv(); //Parse Directive
|
||||
else if (match('/')) skpcmt(); //Skip Comment
|
||||
else if (isalph()) pword(); //Parse Word
|
||||
else ERROR("Unexpected character '%c'\n", nxtchr, EXIT_FAILURE)
|
||||
}
|
||||
epilog();
|
||||
}
|
||||
@ -127,19 +117,17 @@ int popt(int arg, int argc, char *argv[]) {
|
||||
char opt; //Option
|
||||
char optarg[32]; //Option Argument
|
||||
strncpy (argstr, argv[arg], 31);
|
||||
if (strlen(argstr) != 2)
|
||||
ERROR("malformed option %s\n", argstr, EXIT_FAILURE)
|
||||
if (strlen(argstr) != 2) ERROR("malformed option %s\n", argstr, EXIT_FAILURE)
|
||||
opt = toupper(argstr[1]);
|
||||
if (strchr("H", opt)) {
|
||||
if (++arg >= argc)
|
||||
ERROR("Option -%c requires an argument\n", opt, EXIT_FAILURE)
|
||||
if (++arg >= argc) ERROR("Option -%c requires an argument\n", opt, EXIT_FAILURE)
|
||||
strncpy(optarg, argv[arg], 31);
|
||||
}
|
||||
DEBUG("Processing Command Line Option -%c\n", argstr[1]);
|
||||
DEBUG("Processing Command Line Option -%c\n", argstr[1])
|
||||
switch (opt) {
|
||||
case 'H':
|
||||
strcpy(hdrnam, optarg);
|
||||
DEBUG("Header Name set to '%s'\n", hdrnam);
|
||||
DEBUG("Header Name set to '%s'\n", hdrnam)
|
||||
break;
|
||||
default:
|
||||
ERROR("Illegal option -%c\n", opt, EXIT_FAILURE)
|
||||
@ -154,24 +142,17 @@ void pargs(int argc, char *argv[]) {
|
||||
int arg;
|
||||
srcnam[0] = 0;
|
||||
outnam[0] = 0;
|
||||
DEBUG("Parsing %d arguments\n", argc);
|
||||
DEBUG("Parsing %d arguments\n", argc)
|
||||
if (argc == 0) usage(); //at least one argument is required
|
||||
for (arg = 1; arg<argc; arg++) {
|
||||
DEBUG("Parsing argument %d\n", arg);
|
||||
if (argv[arg][0] == '-') {
|
||||
arg = popt(arg, argc, argv);
|
||||
}
|
||||
else if (srcnam[0] == 0) {
|
||||
strcpy(srcnam, argv[arg]); //set Source File Name to first arg
|
||||
DEBUG("srcnam set to '%s'\n", srcnam);
|
||||
}
|
||||
else if (outnam[0] == 0) {
|
||||
strcpy(outnam, argv[arg]); //set Out File Name to second arg
|
||||
DEBUG("outnam set to '%s'\n", outnam);
|
||||
}
|
||||
else
|
||||
ERROR("Unexpected argument '%s'\n", argv[arg], EXIT_FAILURE)
|
||||
if (argv[arg][0] == '-') arg = popt(arg, argc, argv); //Process Command Line Option
|
||||
else if (srcnam[0] == 0) strcpy(srcnam, argv[arg]); //set Source File Name to first arg
|
||||
else if (outnam[0] == 0) strcpy(outnam, argv[arg]); //set Out File Name to second arg
|
||||
else ERROR("Unexpected argument '%s'\n", argv[arg], EXIT_FAILURE)
|
||||
}
|
||||
if (srcnam[0]) DEBUG("srcnam set to '%s'\n", srcnam)
|
||||
if (outnam[0]) DEBUG("outnam set to '%s'\n", outnam)
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
@ -30,8 +30,8 @@
|
||||
#define FALSE 0
|
||||
|
||||
void prtpos(); //Print current file name and position
|
||||
#define DEBUG(fmt, val) if (debug) {prtpos(); printf(fmt, val);}
|
||||
#define DETAIL(fmt, val) if (debug) {printf(fmt, val);}
|
||||
#define DEBUG(fmt, val) {if (debug) {prtpos(); printf(fmt, val);}}
|
||||
#define DETAIL(fmt, val) {if (debug) printf(fmt, val);}
|
||||
#define ERROR(fmt, val, err) {fprintf(stderr, fmt, val);exterr(err);}
|
||||
|
||||
int debug; //Print Debug Info (TRUE or FALSE)
|
||||
|
12
src/cond.c
12
src/cond.c
@ -22,7 +22,7 @@ int cmpenc; //Encoded Comparator Character
|
||||
* Returns: Comparison Operator Bit Mask */
|
||||
int enccmp(char c) {
|
||||
int e;
|
||||
DEBUG("Encoding Comparison Character '%c'", c);
|
||||
DEBUG("Encoding Comparison Character '%c'", c)
|
||||
switch(c) {
|
||||
case '=': e = 1; break;
|
||||
case '<': e = 2; break;
|
||||
@ -42,7 +42,7 @@ int enccmp(char c) {
|
||||
* Uses: term - Term Being Compared Against *
|
||||
* label - Branch Target if Comparison is FALSE */
|
||||
void prccmp(void) {
|
||||
DEBUG("Processing comparitor %d\n", cmprtr);
|
||||
DEBUG("Processing comparitor %d\n", cmprtr)
|
||||
switch(cmprtr) {
|
||||
case 0: // Raw Expression (Skip)
|
||||
asmlin("BEQ", cndlbl);
|
||||
@ -96,12 +96,12 @@ void prscmp(int revrse) {
|
||||
prstrm();
|
||||
cmprtr = (cmprtr ^ revrse) & 7;
|
||||
prccmp();
|
||||
DEBUG("Parsed comparator %d\n", cmprtr);
|
||||
DEBUG("Parsed comparator %d\n", cmprtr)
|
||||
}
|
||||
|
||||
/* Parse Flag Operator */
|
||||
void prsflg(int revrse) {
|
||||
DEBUG("Parsing Flag Operator '%c'\n", nxtchr);
|
||||
DEBUG("Parsing Flag Operator '%c'\n", nxtchr)
|
||||
if (match('+'))
|
||||
cmprtr = 0;
|
||||
else if (match('-'))
|
||||
@ -119,10 +119,10 @@ void prsflg(int revrse) {
|
||||
/* Parse and Compile Conditional Expression *
|
||||
* Condition = <expression> <comparator> <term> */
|
||||
void prscnd(char trmntr, int revrse) {
|
||||
DEBUG("Parsing condition with revrse=%d\n", revrse);
|
||||
DEBUG("Parsing condition with revrse=%d\n", revrse)
|
||||
if (look('!')) {
|
||||
revrse = (revrse) ? FALSE: TRUE;
|
||||
DEBUG("Set revrse to %d\n", revrse);
|
||||
DEBUG("Set revrse to %d\n", revrse)
|
||||
}
|
||||
if (!look('*'))
|
||||
prsxpr(0);
|
||||
|
@ -55,7 +55,7 @@ void addfnc(void) {
|
||||
|
||||
/* (Check For and) Parse Variable Declaration*/
|
||||
void pdecl(int m, int t) {
|
||||
DEBUG("Processing variable declarations(s) of type %d\n", t);
|
||||
DEBUG("Processing variable declarations(s) of type %d\n", t)
|
||||
while(TRUE) {
|
||||
getwrd();
|
||||
if (match('(')) {
|
||||
@ -70,7 +70,7 @@ void pdecl(int m, int t) {
|
||||
break;
|
||||
}
|
||||
expect(';');
|
||||
DEBUG("Variable Declaration Completed\n", 0);
|
||||
DEBUG("Variable Declaration Completed\n", 0)
|
||||
SCMNT(""); //Clear Assembler Comment
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ int ptype(int m) {
|
||||
|
||||
/* Check for and Parse Modifier */
|
||||
int pmodfr(void) {
|
||||
DEBUG("Parsing modifier '%s'\n", word);
|
||||
DEBUG("Parsing modifier '%s'\n", word)
|
||||
int result = TRUE;
|
||||
if (wordis("ALIGNED")) {
|
||||
getwrd();
|
||||
|
30
src/expr.c
30
src/expr.c
@ -18,7 +18,7 @@
|
||||
* Sets: value - the value (as a string) *
|
||||
* valtyp - value type */
|
||||
void prsval(int alwreg) {
|
||||
DEBUG("Parsing value\n", 0);
|
||||
DEBUG("Parsing value\n", 0)
|
||||
skpspc();
|
||||
if (iscpre())
|
||||
prscon(); //Parse Constant
|
||||
@ -27,7 +27,7 @@ void prsval(int alwreg) {
|
||||
}
|
||||
else
|
||||
expctd("constant or variable");
|
||||
DEBUG("Parsed value of type %d\n", valtyp);
|
||||
DEBUG("Parsed value of type %d\n", valtyp)
|
||||
skpspc();
|
||||
}
|
||||
|
||||
@ -37,13 +37,13 @@ void prsval(int alwreg) {
|
||||
void prsidx(void) {
|
||||
expect('[');
|
||||
prsval(TRUE);
|
||||
DEBUG("Parsed array index '%s'\n", value);
|
||||
DEBUG("Parsed array index '%s'\n", value)
|
||||
expect(']');
|
||||
}
|
||||
|
||||
/* Check for, Parse, and Process Index */
|
||||
void chkidx(void) {
|
||||
//DEBUG("Checking for Array Index with valtyp=%d\n", valtyp);
|
||||
//DEBUG("Checking for Array Index with valtyp=%d\n", valtyp)
|
||||
if (valtyp == ARRAY) {
|
||||
prsidx();
|
||||
if (valtyp == CONSTANT) {
|
||||
@ -65,20 +65,20 @@ void chkidx(void) {
|
||||
/* Parse Term in Expression *
|
||||
* Sets: term - the term (as a string) */
|
||||
void prstrm(void) {
|
||||
DEBUG("Parsing term\n", 0);
|
||||
DEBUG("Parsing term\n", 0)
|
||||
prsval(FALSE);
|
||||
if (valtyp == FUNCTION)
|
||||
ERROR("Function call only allowed in first term\n", 0, EXIT_FAILURE)
|
||||
|
||||
strcpy(term, value);
|
||||
DEBUG("Parsed term %s\n", term);
|
||||
DEBUG("Parsed term %s\n", term)
|
||||
chkidx(); //Check for Array Index
|
||||
skpspc();
|
||||
}
|
||||
|
||||
/* Process Address Reference */
|
||||
void prcadr(int adract, char* symbol) {
|
||||
DEBUG("Processing address '%s'\n", word);
|
||||
DEBUG("Processing address '%s'\n", word)
|
||||
strcpy(word,"#>");
|
||||
strcat(word,symbol);
|
||||
if (adract == 1) {
|
||||
@ -99,7 +99,7 @@ void prcadr(int adract, char* symbol) {
|
||||
|
||||
/* Parse and Compile Address of Operator */
|
||||
void prsadr(int adract) {
|
||||
DEBUG("Parsing address\n", 0);
|
||||
DEBUG("Parsing address\n", 0)
|
||||
if (isnpre())
|
||||
prsnum(0xFFFF);
|
||||
else
|
||||
@ -109,7 +109,7 @@ void prsadr(int adract) {
|
||||
|
||||
/* Parse and Create Anonymous String */
|
||||
void prsstr(int adract) {
|
||||
DEBUG("Parsing anonymous string\n", 0);
|
||||
DEBUG("Parsing anonymous string\n", 0)
|
||||
newlbl(vrname); //Generate Variable Name
|
||||
value[0] = 0; //Use Variable Size 0
|
||||
setvar(MTNONE, VTCHAR); //Set Variable Name, Type, and Size
|
||||
@ -121,7 +121,7 @@ void prsstr(int adract) {
|
||||
|
||||
/* Check for and Process Address or String */
|
||||
int chkadr(int adract) {
|
||||
DEBUG("Checking for Address or String\n", 0);
|
||||
DEBUG("Checking for Address or String\n", 0)
|
||||
int result = TRUE;
|
||||
if (look('&'))
|
||||
prsadr(adract);
|
||||
@ -135,7 +135,7 @@ int chkadr(int adract) {
|
||||
|
||||
/* Parse function call */
|
||||
void prsfnc(char trmntr) {
|
||||
DEBUG("Processing Function Call '%s'...\n", term);
|
||||
DEBUG("Processing Function Call '%s'\n", term)
|
||||
if (fnscnt >= MAXFNS)
|
||||
ERROR("Maximum Function Call Depth Exceeded", 0, EXIT_FAILURE)
|
||||
strcpy(fnstck[fnscnt++], term);
|
||||
@ -168,7 +168,7 @@ void prsfnc(char trmntr) {
|
||||
* First term can include function calls */
|
||||
void prsftm(void) {
|
||||
prsval(TRUE);
|
||||
DEBUG("Processing first term '%s'...\n", value);
|
||||
DEBUG("Processing first term '%s'\n", value)
|
||||
strcpy(term, value);
|
||||
if (valtyp == FUNCTION) {
|
||||
prsfnc(0); //Parse Expression Function
|
||||
@ -189,7 +189,7 @@ void prsftm(void) {
|
||||
/* Process Arithmetic or Bitwise Operator *
|
||||
* and the term that follows it */
|
||||
void prcopr(void) {
|
||||
DEBUG("Processing operator '%c'\n", oper);
|
||||
DEBUG("Processing operator '%c'\n", oper)
|
||||
switch(oper)
|
||||
{
|
||||
case '+':
|
||||
@ -219,10 +219,10 @@ void prcopr(void) {
|
||||
|
||||
/* Parse and compile expression */
|
||||
void prsxpr(char trmntr) {
|
||||
DEBUG("Parsing expression\n", 0);
|
||||
DEBUG("Parsing expression\n", 0)
|
||||
skpspc();
|
||||
if (match('-')) {
|
||||
DEBUG("Processing unary minus", 0);
|
||||
DEBUG("Processing unary minus", 0)
|
||||
asmlin("LDA", "#$00"); //Handle Unary Minus
|
||||
}
|
||||
else
|
||||
|
14
src/files.c
14
src/files.c
@ -22,10 +22,10 @@ void extsys(char *s) {
|
||||
* Uses: srcnam - Source File Name *
|
||||
* Sets: srcfil - Source File Handle */
|
||||
void opnsrc(void) {
|
||||
DEBUG("Processing Source File Name '%s'\n", srcnam);
|
||||
DEBUG("Processing Source File Name '%s'\n", srcnam)
|
||||
if (strrchr(srcnam, '.') == NULL) //if no extension
|
||||
strcat(srcnam, ".c02"); // add ".c02"
|
||||
DEBUG("opening Source File '%s'\n", srcnam);
|
||||
DEBUG("opening Source File '%s'\n", srcnam)
|
||||
srcfil = fopen(srcnam, "r"); //open file
|
||||
if (srcfil == NULL) extsys(srcnam);
|
||||
}
|
||||
@ -39,17 +39,17 @@ void clssrc(void) {
|
||||
* Uses: outnam - Output File Name *
|
||||
* Sets: outfil - Output File Handle */
|
||||
void opnout(void) {
|
||||
DEBUG("Processing Output File Name '%s'\n", outnam);
|
||||
DEBUG("Processing Output File Name '%s'\n", outnam)
|
||||
if (strlen(outnam) == 0) //if Output File not specified
|
||||
{
|
||||
strcpy(outnam, srcnam); //copy Source Name to Ouput Name
|
||||
char *dot = strrchr(outnam, '.'); //find extension
|
||||
if (dot != NULL) *dot = 0; //and remove it
|
||||
DEBUG("Set Output File Name to '%s'\n", outnam);
|
||||
DEBUG("Set Output File Name to '%s'\n", outnam)
|
||||
}
|
||||
if (strrchr(outnam, '.') == NULL) //if no extension
|
||||
strcat(outnam, ".asm"); // add ".asm"
|
||||
DEBUG("Opening Output File '%s'\n", outnam);
|
||||
DEBUG("Opening Output File '%s'\n", outnam)
|
||||
outfil = fopen(outnam, "w"); //open file
|
||||
if (outfil == NULL) extsys(outnam);
|
||||
}
|
||||
@ -68,7 +68,7 @@ void opnlog(void) {
|
||||
char *dot = strrchr(lognam, '.'); //find file extension
|
||||
if (dot != NULL) *dot = 0; //and remove it
|
||||
strcat(lognam, ".log"); //add extension ".asm"
|
||||
DEBUG("Opening Log File '%s'\n", lognam);
|
||||
DEBUG("Opening Log File '%s'\n", lognam)
|
||||
logfil = fopen(lognam, "w");
|
||||
if (logfil == NULL) extsys(lognam);
|
||||
}
|
||||
@ -84,7 +84,7 @@ void clslog(void) {
|
||||
* Sets: incfil - Include File Handle */
|
||||
void opninc(void)
|
||||
{
|
||||
DEBUG("Opening include file '%s'\n", incnam);
|
||||
DEBUG("Opening include file '%s'\n", incnam)
|
||||
incfil = fopen(incnam, "r");
|
||||
if (incfil == NULL) extsys(incnam);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ void incasm(void) {
|
||||
addcmt(" =======");
|
||||
cmtlin();
|
||||
while (fgets(line, sizeof line, incfil) != NULL) {
|
||||
DEBUG("Writing line: %s", line);
|
||||
DEBUG("Writing line: %s", line)
|
||||
fputs(line, outfil);
|
||||
}
|
||||
setcmt("==========================================");
|
||||
@ -60,14 +60,14 @@ void incasm(void) {
|
||||
/* Process define directive */
|
||||
void pdefin(void) {
|
||||
getwrd(); //get defined identifier
|
||||
DEBUG("Defining '%s'\n", word);
|
||||
DEBUG("Defining '%s'\n", word)
|
||||
strncpy(defnam[defcnt], word, VARLEN);
|
||||
setlbl(word); //Set label Assembler Line
|
||||
expect('=');
|
||||
defval[defcnt++] = prsbyt(); //Get Value
|
||||
ACMNT(word); //comment value
|
||||
asmlin(EQUOP, value); //Write Definition
|
||||
DEBUG("Defined as '%s'\n", value);
|
||||
DEBUG("Defined as '%s'\n", value)
|
||||
}
|
||||
|
||||
/* Process enum directive */
|
||||
@ -75,13 +75,13 @@ void penumd(void) {
|
||||
int enmval = 0;
|
||||
do {
|
||||
getwrd(); //get defined identifier
|
||||
DEBUG("Enumerating '%s'\n", word);
|
||||
DEBUG("Enumerating '%s'\n", word)
|
||||
strncpy(defnam[defcnt], word, VARLEN);
|
||||
setlbl(word); //Set label Assembler Line
|
||||
defval[defcnt++] = enmval; //Set Value
|
||||
sprintf(value, "%d", enmval);
|
||||
asmlin(EQUOP, value); //Write Definition
|
||||
DEBUG("Defined as '%s'\n", value);
|
||||
DEBUG("Defined as '%s'\n", value)
|
||||
enmval++;
|
||||
} while (look(','));
|
||||
}
|
||||
@ -103,13 +103,13 @@ void pascii(void) {
|
||||
void porign(void) {
|
||||
prsnum(0xFFFF); //Get Origin Address
|
||||
asmlin(ORGOP, value); //Emit Origin Instruction
|
||||
DEBUG("Set origin to %s\n", value);
|
||||
DEBUG("Set origin to %s\n", value)
|
||||
}
|
||||
|
||||
/* Parse Zeropage Subdirective */
|
||||
void prszpg(void) {
|
||||
zpaddr = prsnum(0xFF); //Set Zero Page Address to Constant
|
||||
DEBUG("Set zero page address to %d\n", zpaddr);
|
||||
DEBUG("Set zero page address to %d\n", zpaddr)
|
||||
}
|
||||
|
||||
/* Process Vartable Subdirective */
|
||||
@ -123,7 +123,7 @@ void pvrtbl(void) {
|
||||
/* Parse Pragma Directive */
|
||||
void pprgma(void) {
|
||||
getwrd(); //Get Pragma Subdirective
|
||||
DEBUG("Parsing pragma directive '%s'\n", word);
|
||||
DEBUG("Parsing pragma directive '%s'\n", word)
|
||||
if (wordis("ASCII"))
|
||||
pascii(); //Parse Ascii
|
||||
else if (wordis("ORIGIN"))
|
||||
@ -140,7 +140,7 @@ void pprgma(void) {
|
||||
void pincdr(void) {
|
||||
skpchr(); //skip '#'
|
||||
getwrd(); //read directive into word
|
||||
DEBUG("Processing include file directive '%s'\n", word);
|
||||
DEBUG("Processing include file directive '%s'\n", word)
|
||||
if (wordis("DEFINE"))
|
||||
pdefin();
|
||||
else if (wordis("PRAGMA"))
|
||||
@ -209,7 +209,7 @@ void inchdr(void) {
|
||||
{
|
||||
skpspc();
|
||||
if (match(EOF)) break;
|
||||
DEBUG("Checking next character '%c'\n", nxtchr);
|
||||
DEBUG("Checking next character '%c'\n", nxtchr)
|
||||
if (match('#'))
|
||||
pincdr();
|
||||
else if (match('/'))
|
||||
@ -217,7 +217,7 @@ void inchdr(void) {
|
||||
else if (isalph())
|
||||
phdwrd();
|
||||
else {
|
||||
fprintf(stderr, "Unexpected character '%c'\n", nxtchr);
|
||||
fprintf(stderr, "Unexpected character '%c'\n", nxtchr);
|
||||
exterr(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -229,7 +229,7 @@ void inchdr(void) {
|
||||
/* Process Header File specified on Command Line */
|
||||
void phdrfl(void) {
|
||||
if (hdrnam[0] == 0) return;
|
||||
DEBUG("Processing Header '%s'\n", hdrnam);
|
||||
DEBUG("Processing Header '%s'\n", hdrnam)
|
||||
setinm(".h02");
|
||||
inchdr();
|
||||
setinm(".a02");
|
||||
@ -239,7 +239,7 @@ void phdrfl(void) {
|
||||
/* Process include file */
|
||||
void pincfl(void) {
|
||||
pincnm(); //Parse Include File Name
|
||||
DEBUG("Processing include file '%s'\n", incnam);
|
||||
DEBUG("Processing include file '%s'\n", incnam)
|
||||
char *dot = strrchr(incnam, '.'); //find extension
|
||||
if (dot == NULL) {
|
||||
fprintf(stderr, "Invalid include file name '%sn", incnam);
|
||||
|
20
src/label.c
20
src/label.c
@ -23,12 +23,12 @@ const char lblflg[] = {LFNONE, LFNONE, LFBGN, LFEND, LFBGN, LFEND, LFEND, LFNONE
|
||||
* (-1 if not found) */
|
||||
int lstlbl(int lbflag) {
|
||||
int i;
|
||||
DEBUG("Searching for label flag %d\n", lbflag);
|
||||
DEBUG("Searching for label flag %d\n", lbflag)
|
||||
for (i = lblcnt - 1; i>-1; i--) {
|
||||
//DEBUG("Comparing against flag %d", lblflg[lbltyp[i]]);
|
||||
//DEBUG("Comparing against flag %d", lblflg[lbltyp[i]])
|
||||
if (lblflg[lbltyp[i]] == lbflag) break;
|
||||
}
|
||||
DEBUG("Search produced label index %d\n", i);
|
||||
DEBUG("Search produced label index %d\n", i)
|
||||
if (i>=0)
|
||||
strcpy(tmplbl, lblnam[i]);
|
||||
return i;
|
||||
@ -43,7 +43,7 @@ void setblk(int blkflg) {
|
||||
* Assembly Language Code *
|
||||
* to word */
|
||||
void setlbl(char *lblset) {
|
||||
DEBUG("Setting Label '%s'\n", lblset);
|
||||
DEBUG("Setting Label '%s'\n", lblset)
|
||||
if (strlen(lblasm) > 0) {
|
||||
DEBUG("Emitting Label '%s'\n'", lblasm);
|
||||
asmlin("",""); //Emit Block End Label on it's own line
|
||||
@ -55,7 +55,7 @@ void setlbl(char *lblset) {
|
||||
|
||||
/* parse label in code */
|
||||
void prslbl(void) {
|
||||
DEBUG("Parsing Label '%s''\n", word);
|
||||
DEBUG("Parsing Label '%s''\n", word)
|
||||
CCMNT(nxtchr);
|
||||
skpchr(); //skip ':'
|
||||
setlbl(word);
|
||||
@ -64,7 +64,7 @@ void prslbl(void) {
|
||||
/* generate new label */
|
||||
void newlbl(char* lbname) {
|
||||
sprintf(lbname, LABFMT, lblnxt++);
|
||||
DEBUG("Generated new label '%s'\n", lbname);
|
||||
DEBUG("Generated new label '%s'\n", lbname)
|
||||
}
|
||||
|
||||
/* Check Label Contents *
|
||||
@ -90,7 +90,7 @@ void reqlbl(char* lbname) {
|
||||
/* Pop Label from Stack and Emit on Next Line */
|
||||
int poplbl(void) {
|
||||
int lbtype = lbltyp[--lblcnt];
|
||||
DEBUG("Popped label type %d\n", lbtype);
|
||||
DEBUG("Popped label type %d\n", lbtype)
|
||||
if (lbtype == LTLOOP)
|
||||
asmlin("JMP", lblnam[lblcnt--]); //Jump to Beginning of Loop
|
||||
if (lbtype == LTFUNC) {
|
||||
@ -114,7 +114,7 @@ int poplbl(void) {
|
||||
int toplbl(char *rtlbl) {
|
||||
if (lblcnt) {
|
||||
strcpy(rtlbl, lblnam[lblcnt-1]);
|
||||
DEBUG("Found top label %s\n", rtlbl);
|
||||
DEBUG("Found top label %s\n", rtlbl)
|
||||
return lbltyp[lblcnt-1];
|
||||
}
|
||||
rtlbl[0] = 0; //Clear Label
|
||||
@ -125,9 +125,9 @@ int toplbl(char *rtlbl) {
|
||||
* Args: lbltyp - Label type *
|
||||
* Uses: curlbl - Label to push */
|
||||
void pshlbl(int lbtype, char* lbname) {
|
||||
DEBUG("Pushing label type %d\n", lbtype);
|
||||
DEBUG("Pushing label type %d\n", lbtype)
|
||||
strcpy(lblnam[lblcnt], lbname);
|
||||
lbltyp[lblcnt] = lbtype;
|
||||
lblblk[lblcnt++] = FALSE;
|
||||
DEBUG("Pushed label '%s' onto stack\n", lbname);
|
||||
DEBUG("Pushed label '%s' onto stack\n", lbname)
|
||||
}
|
||||
|
34
src/parse.c
34
src/parse.c
@ -38,7 +38,7 @@ int isxpre(void) {return TF(isvpre() || match('-'));}
|
||||
char prcchr(char c) {
|
||||
if (invasc) c = isalpha(c) ? (islower(c)?toupper(c):tolower(c)) : c;
|
||||
if (mskasc) c = c | 0x80;
|
||||
if (invasc || mskasc) DEBUG("Character converted to '%c'\n", c);
|
||||
if (invasc || mskasc) DEBUG("Character converted to '%c'\n", c)
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ char getnxt(void) {
|
||||
|
||||
/* Advance Input File to next printable character */
|
||||
void skpspc(void) {
|
||||
//DEBUG("Skipping Spaces\n", 0);
|
||||
//DEBUG("Skipping Spaces\n", 0)
|
||||
if (isspc()) CCMNT(' '); //Add only the first space to comments
|
||||
while (isspc())
|
||||
getnxt();
|
||||
@ -100,7 +100,7 @@ void expect(char c) {
|
||||
/* Advance Input File to next printable character */
|
||||
void skpchr(void) {
|
||||
char skip = getnxt();
|
||||
DEBUG("Skipped character '%c'\n", skip);
|
||||
DEBUG("Skipped character '%c'\n", skip)
|
||||
}
|
||||
|
||||
/* Advance Input File to end of line */
|
||||
@ -110,7 +110,7 @@ void skpeol(void) {while (!isnl()) getnxt();}
|
||||
* Recognizes both C and C++ style comments */
|
||||
void skpcmt(void)
|
||||
{
|
||||
DEBUG("Skipping Comment\n", 0);
|
||||
DEBUG("Skipping Comment\n", 0)
|
||||
skpchr(); //skip initial /
|
||||
if (match('/')) //if C style comment
|
||||
skpeol(); // skip rest of line
|
||||
@ -146,7 +146,7 @@ void getwrd(void) {
|
||||
|
||||
/* Escape Character */
|
||||
char escape(char c) {
|
||||
DEBUG("Escaping character '%c'\n", c);
|
||||
DEBUG("Escaping character '%c'\n", c)
|
||||
switch (c) {
|
||||
case 'r': return 0x0d;
|
||||
default: return c;
|
||||
@ -157,7 +157,7 @@ char escape(char c) {
|
||||
void getstr(void) {
|
||||
char strdel;
|
||||
int wrdlen = 0, escnxt = FALSE;
|
||||
DEBUG("Parsing string\n", 0);
|
||||
DEBUG("Parsing string\n", 0)
|
||||
strdel = getnxt(); //Get String Delimiter
|
||||
CCMNT(strdel);
|
||||
while(match(strdel) == escnxt) {
|
||||
@ -230,7 +230,7 @@ int prshex(void) {
|
||||
int wrdlen = 0;
|
||||
int digit;
|
||||
int number = 0;
|
||||
DEBUG("Parsing hexadecimal constant '", 0);
|
||||
DEBUG("Parsing hexadecimal constant '", 0)
|
||||
if (!match('$'))
|
||||
expctd("hexadecimal number");
|
||||
word[wrdlen++] = getnxt();
|
||||
@ -256,13 +256,13 @@ int prshex(void) {
|
||||
int prschr(void) {
|
||||
int wrdlen = 0;
|
||||
char c;
|
||||
DEBUG("Parsing character constant\n", 0);
|
||||
DEBUG("Parsing character constant\n", 0)
|
||||
expect('\'');
|
||||
word[wrdlen++] = '\'';
|
||||
if (match('\\'))
|
||||
word[wrdlen++] = getnxt();
|
||||
c = getnxt();
|
||||
DEBUG("Extracted character %c\n", c);
|
||||
DEBUG("Extracted character %c\n", c)
|
||||
word[wrdlen++] = prcchr(c);
|
||||
expect('\'');
|
||||
word[wrdlen++] = '\'';
|
||||
@ -292,8 +292,8 @@ int prsnum(int maxval) {
|
||||
default:
|
||||
number = prsdec();
|
||||
}
|
||||
DEBUG("Parsed number '%s' ", word);
|
||||
DETAIL("with value '%d'\n", number);
|
||||
DEBUG("Parsed number '%s' ", word)
|
||||
DETAIL("with value '%d'\n", number)
|
||||
|
||||
if (number > maxval)
|
||||
ERROR("Out of bounds constant '%d';\n", number, EXIT_FAILURE)
|
||||
@ -310,7 +310,7 @@ int prsbyt(void) {return prsnum(0xFF);}
|
||||
|
||||
/* Find Defined Constant */
|
||||
void fnddef(char *name) {
|
||||
DEBUG("Looking up defined constant '%s'\n", word);
|
||||
DEBUG("Looking up defined constant '%s'\n", word)
|
||||
for (defidx=0; defidx<defcnt; defidx++) {
|
||||
if (strcmp(defnam[defidx], name) == 0)
|
||||
return;
|
||||
@ -349,7 +349,7 @@ void prscon(void) {
|
||||
strcpy(word, value); //Patch for DASM
|
||||
strcpy(value, "#");
|
||||
strcat(value, word);
|
||||
DEBUG("Generated constant '%s'\n", value);
|
||||
DEBUG("Generated constant '%s'\n", value)
|
||||
}
|
||||
|
||||
/* Get Value Type */
|
||||
@ -364,7 +364,7 @@ void prsopr(void) {
|
||||
if (!isoper())
|
||||
expctd("Arithmetic or bitwise operator");
|
||||
oper = getnxt();
|
||||
DEBUG("Parsed operator '%c'\n", oper);
|
||||
DEBUG("Parsed operator '%c'\n", oper)
|
||||
CCMNT(oper);
|
||||
skpspc();
|
||||
}
|
||||
@ -378,7 +378,7 @@ void poperr(char* name) {
|
||||
|
||||
/* Process Post Operator */
|
||||
void prcpst(char* name, char *index) {
|
||||
DEBUG("Processing post operation '%c'\n", oper);
|
||||
DEBUG("Processing post operation '%c'\n", oper)
|
||||
if (strlen(index)) {
|
||||
asmlin("LDX", index);
|
||||
strcat(name,",X");
|
||||
@ -434,7 +434,7 @@ void prcpst(char* name, char *index) {
|
||||
int prspst(char trmntr, char* name, char* index) {
|
||||
oper = getnxt();
|
||||
CCMNT(oper);
|
||||
DEBUG("Checking for post operation '%c'\n", oper);
|
||||
DEBUG("Checking for post operation '%c'\n", oper)
|
||||
if (nxtchr == oper) {
|
||||
skpchr();
|
||||
CCMNT(oper);
|
||||
@ -443,7 +443,7 @@ int prspst(char trmntr, char* name, char* index) {
|
||||
oper = 0;
|
||||
}
|
||||
else {
|
||||
DEBUG("Not a post operation\n", 0);
|
||||
DEBUG("Not a post operation\n", 0)
|
||||
}
|
||||
return oper;
|
||||
}
|
||||
|
66
src/stmnt.c
66
src/stmnt.c
@ -19,14 +19,14 @@
|
||||
|
||||
/* Begin Program Block */
|
||||
void bgnblk(char blkchr) {
|
||||
DEBUG("Begining program block\n", 0);
|
||||
DEBUG("Begining program block\n", 0)
|
||||
if (blkchr) {
|
||||
expect(blkchr);
|
||||
inblck = TRUE;
|
||||
}
|
||||
else
|
||||
inblck = look('{');
|
||||
DEBUG("Set inblck to %d\n", inblck);
|
||||
DEBUG("Set inblck to %d\n", inblck)
|
||||
setblk(inblck);
|
||||
}
|
||||
|
||||
@ -34,9 +34,9 @@ void bgnblk(char blkchr) {
|
||||
* Args: blkflg: End of Multiline Block */
|
||||
void endblk(int blkflg) {
|
||||
int lbtype;
|
||||
DEBUG("Ending program block with flag %d\n", blkflg);
|
||||
DEBUG("Ending program block with flag %d\n", blkflg)
|
||||
expect('}'); //Block End Character
|
||||
DEBUG("Found inblck set to %d\n", inblck);
|
||||
DEBUG("Found inblck set to %d\n", inblck)
|
||||
if (inblck != blkflg)
|
||||
ERROR("Encountered '}' without matching '{'\n", 0, EXIT_FAILURE)
|
||||
lbtype = poplbl();
|
||||
@ -79,19 +79,19 @@ void prcasn(char trmntr) {
|
||||
prssif(trmntr); //Parse Shortcut If
|
||||
else
|
||||
prsxpr(trmntr); //Parse Expression
|
||||
DEBUG("Processing X assignment variable '%s'\n", xsnvar);
|
||||
DEBUG("Processing X assignment variable '%s'\n", xsnvar)
|
||||
if (xsnvar[0]) {
|
||||
asmlin("STX", xsnvar);
|
||||
xsnvar[0] = 0;
|
||||
}
|
||||
DEBUG("Processing Y assignment variable '%s'\n", ysnvar);
|
||||
DEBUG("Processing Y assignment variable '%s'\n", ysnvar)
|
||||
if (ysnvar[0]) {
|
||||
if (strlen(ysnidx))
|
||||
prcidx(ysnivt, ysnvar, ysnidx);
|
||||
asmlin("STY", ysnvar);
|
||||
ysnvar[0] = 0;
|
||||
}
|
||||
DEBUG("Processing assignment variable '%s'\n", asnvar);
|
||||
DEBUG("Processing assignment variable '%s'\n", asnvar)
|
||||
if (strcmp(asnvar, "X")==0)
|
||||
asmlin("TAX", "");
|
||||
else if (strcmp(asnvar, "Y")==0)
|
||||
@ -111,7 +111,7 @@ int getidx(char* idx) {
|
||||
strncpy(idx, word, VARLEN);
|
||||
else
|
||||
strncpy(idx, value, VARLEN);
|
||||
DEBUG("Set assigned index to %s\n", asnidx);
|
||||
DEBUG("Set assigned index to %s\n", asnidx)
|
||||
return valtyp;
|
||||
}
|
||||
|
||||
@ -120,15 +120,15 @@ void prcvar(char trmntr) {
|
||||
chksym(TRUE, word);
|
||||
strcpy(asnvar, word); //save variable to assign to
|
||||
asntyp = valtyp; //Set Assigned Varable Type
|
||||
DEBUG("Set STA variable to %s\n", asnvar);
|
||||
DEBUG("Set STA variable to %s\n", asnvar)
|
||||
if (asntyp == VARIABLE && look(';')) {
|
||||
asmlin("STA", asnvar);
|
||||
return;
|
||||
}
|
||||
if (asntyp == ARRAY) {
|
||||
asnivt = getidx(asnidx); //Get Array Index and Type
|
||||
DEBUG("Set STA index to %s\n", asnidx);
|
||||
DEBUG("Set STA index type to %d\n", asnivt);
|
||||
DEBUG("Set STA index to %s\n", asnidx)
|
||||
DEBUG("Set STA index type to %d\n", asnivt)
|
||||
}
|
||||
else
|
||||
asnidx[0] = 0;
|
||||
@ -144,18 +144,18 @@ void prcvar(char trmntr) {
|
||||
|
||||
prsvar(FALSE); //get variable name
|
||||
strcpy(ysnvar, word);
|
||||
DEBUG("Set STY variable to %s\n", ysnvar);
|
||||
DEBUG("Set STY variable to %s\n", ysnvar)
|
||||
if (valtyp == ARRAY) {
|
||||
ysnivt = getidx(ysnidx); //Get Array Index and Type
|
||||
DEBUG("Set STY index to %s\n", ysnidx);
|
||||
DEBUG("Set STY index type to %d\n", ysnivt);
|
||||
DEBUG("Set STY index to %s\n", ysnidx)
|
||||
DEBUG("Set STY index type to %d\n", ysnivt)
|
||||
}
|
||||
else
|
||||
ysnidx[0] = 0;
|
||||
if (look(',')) {
|
||||
prsvar(FALSE); //get variable name
|
||||
strcpy(xsnvar, word);
|
||||
DEBUG("Set STX variable to %s\n", xsnvar);
|
||||
DEBUG("Set STX variable to %s\n", xsnvar)
|
||||
if (valtyp == ARRAY)
|
||||
ERROR("Array element not allowed in third assignment\n", 0, EXIT_FAILURE)
|
||||
|
||||
@ -197,17 +197,17 @@ void prsasn(char trmntr) {
|
||||
/* parse and compile 'break'/'continue' statement */
|
||||
void pbrcnt(int lbflag)
|
||||
{
|
||||
DEBUG("Parsing BREAK/CONTINUE statement\n", 0);
|
||||
DEBUG("Parsing BREAK/CONTINUE statement\n", 0)
|
||||
if (lstlbl(lbflag) < 0)
|
||||
ERROR("Break/continue statement outside of loop\n", 0, EXIT_FAILURE)
|
||||
DEBUG("Found Label '%s'\n", tmplbl);
|
||||
DEBUG("Found Label '%s'\n", tmplbl)
|
||||
asmlin("JMP", tmplbl);
|
||||
expect(';');
|
||||
}
|
||||
|
||||
/* parse and compile 'do' statement */
|
||||
void pdo(void) {
|
||||
DEBUG("Parsing DO statement '%c'\n", nxtchr);
|
||||
DEBUG("Parsing DO statement '%c'\n", nxtchr)
|
||||
newlbl(endlbl); //Create End Label
|
||||
pshlbl(LTDWHL, endlbl); //and Push onto Stack
|
||||
reqlbl(loplbl); //Get or Create/Set Loop Label
|
||||
@ -219,7 +219,7 @@ void pdo(void) {
|
||||
|
||||
/* parse and compile 'while' after 'do' statement */
|
||||
void pdowhl(void) {
|
||||
DEBUG("Parsing WHILE after DO '%c'\n", nxtchr);
|
||||
DEBUG("Parsing WHILE after DO '%c'\n", nxtchr)
|
||||
getwrd(); //Check for While
|
||||
if (!wordis("WHILE"))
|
||||
expctd("while statement");
|
||||
@ -258,7 +258,7 @@ void pfor(void) {
|
||||
|
||||
/* parse and compile if statement */
|
||||
void pif(void) {
|
||||
DEBUG("Parsing IF statement\n", 0);
|
||||
DEBUG("Parsing IF statement\n", 0)
|
||||
expect('(');
|
||||
newlbl(cndlbl); //Create New Label
|
||||
pshlbl(LTIF,cndlbl); //Push Onto Stack
|
||||
@ -268,7 +268,7 @@ void pif(void) {
|
||||
|
||||
/* parse and compile else statement */
|
||||
void pelse(void) {
|
||||
DEBUG("Parsing ELSE statement\n", 0);
|
||||
DEBUG("Parsing ELSE statement\n", 0)
|
||||
strcpy(lbltmp, lblasm); //Save Line Label
|
||||
lblasm[0] = 0; //and Clear It
|
||||
newlbl(skplbl); //Create Skip Label
|
||||
@ -280,7 +280,7 @@ void pelse(void) {
|
||||
|
||||
/* parse and compile if statement */
|
||||
void pgoto(void) {
|
||||
DEBUG("Parsing GOTO statement\n", 0);
|
||||
DEBUG("Parsing GOTO statement\n", 0)
|
||||
getwrd();
|
||||
expect(';');
|
||||
asmlin("JMP", word);
|
||||
@ -288,9 +288,9 @@ void pgoto(void) {
|
||||
|
||||
/* parse and compile inline statement */
|
||||
void pinlne(void) {
|
||||
DEBUG("Parsing INLINE statement\n", 0);
|
||||
DEBUG("Parsing INLINE statement\n", 0)
|
||||
do {
|
||||
DEBUG("Parsing inline parameter\n", 0);
|
||||
DEBUG("Parsing inline parameter\n", 0)
|
||||
if (look('&')) {
|
||||
reqvar(FALSE); //Get Variable Name
|
||||
strcpy(word, "<");
|
||||
@ -322,7 +322,7 @@ void pinlne(void) {
|
||||
|
||||
/* parse and compile pop statement */
|
||||
void ppop(void) {
|
||||
DEBUG("Parsing POP statement\n", 0);
|
||||
DEBUG("Parsing POP statement\n", 0)
|
||||
do {
|
||||
asmlin("PLA", ""); //Pop Value off Stack
|
||||
if (!look('*')) {
|
||||
@ -337,7 +337,7 @@ void ppop(void) {
|
||||
|
||||
/* parse and compile push statement */
|
||||
void ppush(void) {
|
||||
DEBUG("Parsing PUSH statement\n", 0);
|
||||
DEBUG("Parsing PUSH statement\n", 0)
|
||||
do {
|
||||
if (!chkadr(1)) {
|
||||
prsxpr(0); //Parse Expression
|
||||
@ -349,7 +349,7 @@ void ppush(void) {
|
||||
|
||||
/* parse and compile return statement */
|
||||
void pretrn(void) {
|
||||
DEBUG("Parsing RETURN statement\n", 0);
|
||||
DEBUG("Parsing RETURN statement\n", 0)
|
||||
if (!look(';'))
|
||||
prsxpr(';');
|
||||
asmlin("RTS", "");
|
||||
@ -358,7 +358,7 @@ void pretrn(void) {
|
||||
|
||||
/* parse and compile select statement */
|
||||
void pslct(void) {
|
||||
DEBUG("Parsing SELECT statement\n", 0);
|
||||
DEBUG("Parsing SELECT statement\n", 0)
|
||||
expect('(');
|
||||
prsxpr(')'); //Parse Expression
|
||||
newlbl(endlbl); //Create New Label
|
||||
@ -370,7 +370,7 @@ void pslct(void) {
|
||||
|
||||
/* process end of case block */
|
||||
void ecase(void) {
|
||||
DEBUG("Processing end of CASE block\n", 0);
|
||||
DEBUG("Processing end of CASE block\n", 0)
|
||||
if (poplbl(cndlbl) != LTCASE)
|
||||
ERROR("%s not at end of CASE block\n", word, EXIT_FAILURE)
|
||||
if (toplbl(endlbl) != LTSLCT)
|
||||
@ -413,7 +413,7 @@ void pdflt(void) {
|
||||
|
||||
/* parse and compile while statement */
|
||||
void pwhile(void) {
|
||||
DEBUG("Parsing WHILE statement '%c'\n", nxtchr);
|
||||
DEBUG("Parsing WHILE statement '%c'\n", nxtchr)
|
||||
expect('(');
|
||||
newlbl(endlbl); //Create End Label
|
||||
pshlbl(LTEND, endlbl); //and Push onto Stack
|
||||
@ -444,7 +444,7 @@ void prsfns(void) {
|
||||
|
||||
/* parse and compile identifier (variable or function call) */
|
||||
void prssym(void) {
|
||||
DEBUG("Parsing Identifier %s\n", word);
|
||||
DEBUG("Parsing Identifier %s\n", word)
|
||||
valtyp = gettyp();
|
||||
if (valtyp == FUNCTION)
|
||||
prsfns(); //Parse Statement Function Call
|
||||
@ -454,7 +454,7 @@ void prssym(void) {
|
||||
|
||||
/* parse and compile program statement */
|
||||
void pstmnt(void) {
|
||||
DEBUG("Parsing statement '%s'\n", word);
|
||||
DEBUG("Parsing statement '%s'\n", word)
|
||||
if (wordis("DO")) {
|
||||
pdo();
|
||||
return;
|
||||
@ -513,7 +513,7 @@ void pstmnt(void) {
|
||||
else
|
||||
prssym();
|
||||
if (lblcnt && !inblck) {
|
||||
DEBUG("Ending implied block\n", 0);
|
||||
DEBUG("Ending implied block\n", 0)
|
||||
if (poplbl() == LTDO)
|
||||
pdowhl(); //Parse While at End of Do Loop
|
||||
}
|
||||
|
34
src/vars.c
34
src/vars.c
@ -20,7 +20,7 @@
|
||||
* varcnt if not found *
|
||||
* Returns: TRUE if found, otherwise FALSE */
|
||||
int fndvar(char *name) {
|
||||
DEBUG("Looking up variable '%s'\n", word);
|
||||
DEBUG("Looking up variable '%s'\n", word)
|
||||
for (varidx=0; varidx<varcnt; varidx++) {
|
||||
if (strcmp(varnam[varidx], name) == 0)
|
||||
return TRUE;
|
||||
@ -53,7 +53,7 @@ void prsvar(int alwreg) {
|
||||
valtyp = gettyp();
|
||||
if (valtyp != FUNCTION) chksym(alwreg, word);
|
||||
strcpy(value, word);
|
||||
DEBUG("Parsed variable '%s'\n", value);
|
||||
DEBUG("Parsed variable '%s'\n", value)
|
||||
}
|
||||
|
||||
/* Require and Parse Variable Name *
|
||||
@ -85,7 +85,7 @@ void prsdts(void) {
|
||||
dtype = DTSTR;
|
||||
getstr();
|
||||
strcpy(value, word);
|
||||
DEBUG("Parsed Data String '%s'\n", value);
|
||||
DEBUG("Parsed Data String '%s'\n", value)
|
||||
}
|
||||
|
||||
/* Store variable data *
|
||||
@ -95,29 +95,29 @@ void prsdts(void) {
|
||||
void setdat(void) {
|
||||
int i;
|
||||
if (dtype == DTBYTE) {
|
||||
DEBUG("Setting variable data to '%d'\n", cnstnt);
|
||||
DEBUG("Setting variable data to '%d'\n", cnstnt)
|
||||
dlen = 1;
|
||||
datvar[dsize++] = cnstnt;
|
||||
}
|
||||
else if (dtype == DTARRY) {
|
||||
DEBUG("Setting variable data to array of length %d\n", dlen);
|
||||
DEBUG("Setting variable data to array of length %d\n", dlen)
|
||||
for (i=0; i<dlen; i++)
|
||||
datvar[dsize++] = dattmp[i];
|
||||
}
|
||||
else {
|
||||
DEBUG("Setting variable data to '%s'\n", value);
|
||||
DEBUG("Setting variable data to '%s'\n", value)
|
||||
dlen = strlen(value);
|
||||
for (i=0; i<dlen; i++)
|
||||
datvar[dsize++] = value[i];
|
||||
}
|
||||
datlen[varcnt] = dlen;
|
||||
dattyp[varcnt] = dtype;
|
||||
DEBUG("Total data alllocated: %d bytes\n", dsize);
|
||||
DEBUG("Total data alllocated: %d bytes\n", dsize)
|
||||
}
|
||||
|
||||
/* Parse and store variable data */
|
||||
void prsdat(void) {
|
||||
DEBUG("Checking for variable data\n", 0);
|
||||
DEBUG("Checking for variable data\n", 0)
|
||||
if (!look('=')) {
|
||||
datlen[varcnt] = 0;
|
||||
return;
|
||||
@ -163,12 +163,12 @@ void addvar(int m, int t) {
|
||||
strcpy(value, "*"); //Set Variable Type to Zero Page
|
||||
}
|
||||
else {
|
||||
DEBUG("Checking for array definition\n", 0);
|
||||
DEBUG("Checking for array definition\n", 0)
|
||||
value[0] = 0;
|
||||
if (match('[')) {
|
||||
skpchr();
|
||||
if (alcvar) {
|
||||
DEBUG("Parsing array size\n", 0);
|
||||
DEBUG("Parsing array size\n", 0)
|
||||
sprintf(value, "%d", prsnum(0xFF) + 1);
|
||||
}
|
||||
expect(']');
|
||||
@ -185,21 +185,21 @@ void addvar(int m, int t) {
|
||||
/* Write Variable Table */
|
||||
void vartbl(void) {
|
||||
int i, j;
|
||||
DEBUG("Writing Variable Table", 0);
|
||||
DEBUG("Writing Variable Table", 0)
|
||||
fprintf(logfil, "\n%-31s %s %s %s\n", "Variable", "Type", "Size", "Data");
|
||||
dlen = 0;
|
||||
for (i=0; i<varcnt; i++) {
|
||||
fprintf(logfil, "%-31s %4d %4s %1d-%d\n", varnam[i], vartyp[i], varsiz[i], dattyp[i], datlen[i]);
|
||||
strcpy(lblasm, varnam[i]);
|
||||
DEBUG("Set Label to '%s'\n", lblasm);
|
||||
DEBUG("Set Label to '%s'\n", lblasm)
|
||||
if (strcmp(varsiz[i], "*") == 0)
|
||||
continue;
|
||||
if (varmod[i] == MTALGN) {
|
||||
DEBUG("Alligning variable '%s'\n", varnam[i]);
|
||||
DEBUG("Alligning variable '%s'\n", varnam[i])
|
||||
asmlin(ALNOP, "256");
|
||||
}
|
||||
if (datlen[i]) {
|
||||
DEBUG("Building Data for Variable '%s'\n", varnam[i]);
|
||||
DEBUG("Building Data for Variable '%s'\n", varnam[i])
|
||||
value[0] = 0;
|
||||
for (j=0; j<datlen[i]; j++) {
|
||||
if (j) strcat(value,",");
|
||||
@ -207,15 +207,15 @@ void vartbl(void) {
|
||||
strcat(value, word);
|
||||
}
|
||||
if (dattyp[i] == DTSTR) strcat(value, ",$00");
|
||||
DEBUG("Allocating Data for Variable '%s'\n", varnam[i]);
|
||||
DEBUG("Allocating Data for Variable '%s'\n", varnam[i])
|
||||
asmlin(BYTEOP, value);
|
||||
}
|
||||
else if (strlen(varsiz[i]) > 0) {
|
||||
DEBUG("Allocating array '%s'\n", varnam[i]);
|
||||
DEBUG("Allocating array '%s'\n", varnam[i])
|
||||
asmlin(STROP, varsiz[i]);
|
||||
}
|
||||
else {
|
||||
DEBUG("Allocating variable '%s'\n", varnam[i]);
|
||||
DEBUG("Allocating variable '%s'\n", varnam[i])
|
||||
asmlin(BYTEOP, "0");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user