1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-09-29 12:54:55 +00:00

Fixed C compiler warnings

This commit is contained in:
Curtis F Kaylor 2018-03-03 22:32:39 -05:00
parent f713118fe6
commit 1156f3b47b
13 changed files with 172 additions and 290 deletions

View File

@ -14,8 +14,7 @@
#include "asm.h" #include "asm.h"
/* Process comment */ /* Process comment */
void prccmt() void prccmt(void) {
{
if (strlen(cmtasm)) { if (strlen(cmtasm)) {
strcpy(asmcmt, ";"); strcpy(asmcmt, ";");
strcat(asmcmt, cmtasm); strcat(asmcmt, cmtasm);
@ -26,8 +25,7 @@ void prccmt()
} }
/* output a single line of assembly code */ /* output a single line of assembly code */
void asmlin(char *opcode, char *oprnd) void asmlin(char *opcode, char *oprnd) {
{
if (strlen(lblasm)) strcat(lblasm, LABSFX); if (strlen(lblasm)) strcat(lblasm, LABSFX);
prccmt(); prccmt();
fprintf(outfil, ASMFMT, lblasm, opcode, oprnd, asmcmt); fprintf(outfil, ASMFMT, lblasm, opcode, oprnd, asmcmt);
@ -36,8 +34,7 @@ void asmlin(char *opcode, char *oprnd)
} }
/* output a single comment line */ /* output a single comment line */
void cmtlin() void cmtlin(void) {
{
DEBUG("Writing Comment Line: %s\n", cmtasm); DEBUG("Writing Comment Line: %s\n", cmtasm);
fprintf(outfil, "; %s\n", cmtasm); fprintf(outfil, "; %s\n", cmtasm);
setcmt(""); setcmt("");

View File

@ -26,8 +26,7 @@
#include "include.h" //Include File Parsing #include "include.h" //Include File Parsing
/* Initilize Compiler Variables */ /* Initilize Compiler Variables */
void init() void init(void) {
{
DEBUG("Initializing Compiler Variables\n",0); DEBUG("Initializing Compiler Variables\n",0);
defcnt = 0; defcnt = 0;
varcnt = 0; varcnt = 0;
@ -50,8 +49,7 @@ void init()
} }
/* Reads and parses the next Word in Source File */ /* Reads and parses the next Word in Source File */
void pword() void pword(void) {
{
lsrtrn = FALSE; //Clear RETURN flag lsrtrn = FALSE; //Clear RETURN flag
getwrd(); getwrd();
DEBUG("Parsing Word '%s'\n", word); DEBUG("Parsing Word '%s'\n", word);
@ -66,8 +64,7 @@ void pword()
} }
/* Process a directive */ /* Process a directive */
void pdrctv() void pdrctv(void) {
{
skpchr(); //skip '#' skpchr(); //skip '#'
CCMNT('#'); CCMNT('#');
getwrd(); //read directive into word getwrd(); //read directive into word
@ -87,8 +84,7 @@ void pdrctv()
ERROR("Illegal directive %s encountered\n", word, EXIT_FAILURE); ERROR("Illegal directive %s encountered\n", word, EXIT_FAILURE);
} }
void prolog() void prolog(void) {
{
DEBUG("Writing Assembly Prolog\n", 0); DEBUG("Writing Assembly Prolog\n", 0);
asmlin(CPUOP,CPUARG); asmlin(CPUOP,CPUARG);
setcmt("Program "); setcmt("Program ");
@ -96,21 +92,18 @@ void prolog()
cmtlin(); cmtlin();
} }
void epilog() void epilog(void) {
{
if (!vrwrtn) vartbl(); //Write Variable Table if (!vrwrtn) vartbl(); //Write Variable Table
} }
/* Compile Source Code*/ /* Compile Source Code*/
void compile() void compile(void) {
{
DEBUG("Starting Compilation\n", 0); DEBUG("Starting Compilation\n", 0);
prolog(); prolog();
phdrfl(); //Process Header File specified on Command Line phdrfl(); //Process Header File specified on Command Line
skpchr(); skpchr();
DEBUG("Parsing Code\n", 0); DEBUG("Parsing Code\n", 0);
while (TRUE) while (TRUE) {
{
skpspc(); skpspc();
//DEBUG("Checking next character '%c'\n", nxtchr); //DEBUG("Checking next character '%c'\n", nxtchr);
if (match(EOF)) if (match(EOF))
@ -130,15 +123,13 @@ void compile()
} }
/* Display "Usage" text and exit*/ /* Display "Usage" text and exit*/
void usage() void usage(void) {
{
printf("Usage: c02 sourcefile.c02\n"); printf("Usage: c02 sourcefile.c02\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* Parse Command Line Option */ /* Parse Command Line Option */
int popt(int arg, int argc, char *argv[]) int popt(int arg, int argc, char *argv[]) {
{
char argstr[32]; //Argument String char argstr[32]; //Argument String
char opt; //Option char opt; //Option
char optarg[32]; //Option Argument char optarg[32]; //Option Argument
@ -166,8 +157,7 @@ int popt(int arg, int argc, char *argv[])
/* Parse Command Line Arguments * /* Parse Command Line Arguments *
* Sets: srcnam - Source File Name (from first arg) * * Sets: srcnam - Source File Name (from first arg) *
* outnam - Output File Name (from optional second arg) */ * outnam - Output File Name (from optional second arg) */
void pargs(int argc, char *argv[]) void pargs(int argc, char *argv[]) {
{
int arg; int arg;
srcnam[0] = 0; srcnam[0] = 0;
outnam[0] = 0; outnam[0] = 0;
@ -191,8 +181,7 @@ void pargs(int argc, char *argv[])
} }
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{
debug = TRUE; //Output Debug Info debug = TRUE; //Output Debug Info
gencmt = TRUE; //Generate Assembly Language Comments gencmt = TRUE; //Generate Assembly Language Comments

View File

@ -11,8 +11,7 @@
#include "common.h" #include "common.h"
/* Error - Print Input File name & position and exit */ /* Error - Print Input File name & position and exit */
void exterr(int errnum) void exterr(int errnum) {
{
fprintf(stderr, "Line %d Column %d of File %s\n", curlin, curcol, inpnam); fprintf(stderr, "Line %d Column %d of File %s\n", curlin, curcol, inpnam);
exit(errnum); exit(errnum);
} }
@ -20,33 +19,28 @@ void exterr(int errnum)
/* Error - print "Expected" error message * /* Error - print "Expected" error message *
and exit with general failure code * and exit with general failure code *
Args: expected - Description of what was expected */ Args: expected - Description of what was expected */
void expctd(char *expstr) void expctd(char *expstr) {
{
fprintf(stderr, "Expected %s, but found '%c'\n", expstr, nxtchr); fprintf(stderr, "Expected %s, but found '%c'\n", expstr, nxtchr);
exterr(EXIT_FAILURE); exterr(EXIT_FAILURE);
} }
/* Print current position in file */ /* Print current position in file */
void prtpos() void prtpos(void) {
{
printf("(%s: %d,%d) ", inpnam, curlin, curcol); printf("(%s: %d,%d) ", inpnam, curlin, curcol);
} }
/* Set comment to string */ /* Set comment to string */
void setcmt(char *s) void setcmt(char *s) {
{
strcpy(cmtasm, s); strcpy(cmtasm, s);
} }
/* Append string to comment */ /* Append string to comment */
void addcmt(char *s) void addcmt(char *s) {
{
strcat(cmtasm, s); strcat(cmtasm, s);
} }
/* Append character to comment */ /* Append character to comment */
void chrcmt(char c) void chrcmt(char c) {
{
if (cmtasm[0] == 0 && c == ' ') return; if (cmtasm[0] == 0 && c == ' ') return;
int i = strlen(cmtasm); int i = strlen(cmtasm);
cmtasm[i++] = c; cmtasm[i++] = c;

View File

@ -32,7 +32,7 @@
void prtpos(); //Print current file name and position void prtpos(); //Print current file name and position
#define DEBUG(fmt, val) if (debug) {prtpos(); printf(fmt, val);} #define DEBUG(fmt, val) if (debug) {prtpos(); printf(fmt, val);}
#define DETAIL(fmt, val) if (debug) {printf(fmt, val);} #define DETAIL(fmt, val) if (debug) {printf(fmt, val);}
#define ERROR(fmt, val, err) if (debug) {fprintf(stderr, fmt, val);exterr(err);} #define ERROR(fmt, val, err) {fprintf(stderr, fmt, val);exterr(err);}
int debug; //Print Debug Info (TRUE or FALSE) int debug; //Print Debug Info (TRUE or FALSE)

View File

@ -20,12 +20,10 @@ int cmpenc; //Encoded Comparator Character
/* Encode Comparison Operator Character * /* Encode Comparison Operator Character *
* Args: Comparison Operator Character * * Args: Comparison Operator Character *
* Returns: Comparison Operator Bit Mask */ * Returns: Comparison Operator Bit Mask */
int enccmp(char c) int enccmp(char c) {
{
int e; int e;
DEBUG("Encoding Comparison Character '%c'\n", c); DEBUG("Encoding Comparison Character '%c'", c);
switch(c) switch(c) {
{
case '=': e = 1; break; case '=': e = 1; break;
case '<': e = 2; break; case '<': e = 2; break;
case '>': e = 4; break; case '>': e = 4; break;
@ -35,7 +33,7 @@ int enccmp(char c)
CCMNT(c); CCMNT(c);
skpchr(); skpchr();
} }
DEBUG("Encoded as %d\n", e); DETAIL(", encoded as %d\n", e);
return e; return e;
} }
@ -43,9 +41,8 @@ int enccmp(char c)
* Args: comparator - Encoded Comparison Operator * * Args: comparator - Encoded Comparison Operator *
* Uses: term - Term Being Compared Against * * Uses: term - Term Being Compared Against *
* label - Branch Target if Comparison is FALSE */ * label - Branch Target if Comparison is FALSE */
void prccmp() void prccmp(void) {
{ DEBUG("Processing comparitor %d\n", cmprtr);
DEBUG("Processing comparison operator %d\n", cmprtr);
switch(cmprtr) { switch(cmprtr) {
case 0: // Raw Expression (Skip) case 0: // Raw Expression (Skip)
asmlin("BEQ", cndlbl); asmlin("BEQ", cndlbl);
@ -80,14 +77,12 @@ void prccmp()
asmlin("BNE", cndlbl); asmlin("BNE", cndlbl);
break; break;
default: default:
fprintf(stderr, "Unsupported comparison operator index %d\n", cmprtr); ERROR("Unsupported comparison operator index %d\n", cmprtr, EXIT_FAILURE);
exterr(EXIT_FAILURE);
} }
} }
/* Parse Comparison */ /* Parse Comparison */
int prscmp(int revrse) void prscmp(int revrse) {
{
skpspc(); skpspc();
cmpenc = enccmp(nxtchr); //Encode Comparison Character cmpenc = enccmp(nxtchr); //Encode Comparison Character
cmprtr = cmpenc; //Set Encoded Comparator cmprtr = cmpenc; //Set Encoded Comparator
@ -99,14 +94,13 @@ int prscmp(int revrse)
skpspc(); skpspc();
if (cmprtr) if (cmprtr)
prstrm(); prstrm();
cmprtr = cmprtr ^ revrse & 7; cmprtr = (cmprtr ^ revrse) & 7;
prccmp(); prccmp();
DEBUG("Parsed comparator %d\n", cmprtr); DEBUG("Parsed comparator %d\n", cmprtr);
} }
/* Parse Flag Operator */ /* Parse Flag Operator */
void prsflg(int revrse) void prsflg(int revrse) {
{
DEBUG("Parsing Flag Operator '%c'\n", nxtchr); DEBUG("Parsing Flag Operator '%c'\n", nxtchr);
if (match('+')) if (match('+'))
cmprtr = 0; cmprtr = 0;
@ -115,7 +109,7 @@ void prsflg(int revrse)
else else
expctd("Flag operator"); expctd("Flag operator");
skpchr(); skpchr();
cmprtr = cmprtr ^ revrse & 1; cmprtr = (cmprtr ^ revrse) & 1;
if (cmprtr) if (cmprtr)
asmlin("BPL", cndlbl); asmlin("BPL", cndlbl);
else else
@ -124,8 +118,7 @@ void prsflg(int revrse)
/* Parse and Compile Conditional Expression * /* Parse and Compile Conditional Expression *
* Condition = <expression> <comparator> <term> */ * Condition = <expression> <comparator> <term> */
void prscnd(char trmntr, int revrse) void prscnd(char trmntr, int revrse) {
{
DEBUG("Parsing condition with revrse=%d\n", revrse); DEBUG("Parsing condition with revrse=%d\n", revrse);
if (look('!')) { if (look('!')) {
revrse = (revrse) ? FALSE: TRUE; revrse = (revrse) ? FALSE: TRUE;

View File

@ -18,8 +18,7 @@
#include "dclrtn.h" #include "dclrtn.h"
/* Add Function Definition */ /* Add Function Definition */
void addfnc() void addfnc(void) {
{
expect('('); expect('(');
strcpy(fncnam, word); //Save Function Name strcpy(fncnam, word); //Save Function Name
prmcnt = 0; //Set Number of Parameters prmcnt = 0; //Set Number of Parameters
@ -55,8 +54,7 @@ void addfnc()
} }
/* (Check For and) Parse Variable Declaration*/ /* (Check For and) Parse Variable Declaration*/
void pdecl(int m, int t) 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) { while(TRUE) {
getwrd(); getwrd();
@ -77,8 +75,7 @@ void pdecl(int m, int t)
} }
/* Check for and Parse Type Keyword */ /* Check for and Parse Type Keyword */
int ptype(int m) int ptype(int m) {
{
int result = TRUE; int result = TRUE;
if (wordis("VOID")) if (wordis("VOID"))
pdecl(m, VTVOID); //Parse 'void' declaration pdecl(m, VTVOID); //Parse 'void' declaration
@ -91,8 +88,7 @@ int ptype(int m)
} }
/* Check for and Parse Modifier */ /* Check for and Parse Modifier */
int pmodfr() int pmodfr(void) {
{
DEBUG("Parsing modifier '%s'\n", word); DEBUG("Parsing modifier '%s'\n", word);
int result = TRUE; int result = TRUE;
if (wordis("ALIGNED")) { if (wordis("ALIGNED")) {

View File

@ -17,8 +17,7 @@
/* Parse value (constant or identifier) * /* Parse value (constant or identifier) *
* Sets: value - the value (as a string) * * Sets: value - the value (as a string) *
* valtyp - value type */ * valtyp - value type */
void prsval(int alwreg) void prsval(int alwreg) {
{
DEBUG("Parsing value\n", 0); DEBUG("Parsing value\n", 0);
skpspc(); skpspc();
if (iscpre()) if (iscpre())
@ -35,8 +34,7 @@ void prsval(int alwreg)
/* Parse array index * /* Parse array index *
* Sets: value - array index or * * Sets: value - array index or *
* "" if no index defined */ * "" if no index defined */
void prsidx() void prsidx(void) {
{
expect('['); expect('[');
prsval(TRUE); prsval(TRUE);
DEBUG("Parsed array index '%s'\n", value); DEBUG("Parsed array index '%s'\n", value);
@ -44,8 +42,7 @@ void prsidx()
} }
/* Check for, Parse, and Process Index */ /* Check for, Parse, and Process Index */
void chkidx() 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) { if (valtyp == ARRAY) {
prsidx(); prsidx();
@ -67,8 +64,7 @@ void chkidx()
/* Parse Term in Expression * /* Parse Term in Expression *
* Sets: term - the term (as a string) */ * Sets: term - the term (as a string) */
void prstrm() void prstrm(void) {
{
DEBUG("Parsing term\n", 0); DEBUG("Parsing term\n", 0);
prsval(FALSE); prsval(FALSE);
if (valtyp == FUNCTION) { if (valtyp == FUNCTION) {
@ -81,8 +77,7 @@ void prstrm()
} }
/* Process Address Reference */ /* Process Address Reference */
void prcadr(int adract, char* symbol) void prcadr(int adract, char* symbol) {
{
DEBUG("Processing address '%s'\n", word); DEBUG("Processing address '%s'\n", word);
strcpy(word,"#>"); strcpy(word,"#>");
strcat(word,symbol); strcat(word,symbol);
@ -103,8 +98,7 @@ void prcadr(int adract, char* symbol)
} }
/* Parse and Compile Address of Operator */ /* Parse and Compile Address of Operator */
void prsadr(int adract) void prsadr(int adract) {
{
DEBUG("Parsing address\n", 0); DEBUG("Parsing address\n", 0);
if (isnpre()) if (isnpre())
prsnum(0xFFFF); prsnum(0xFFFF);
@ -114,8 +108,7 @@ void prsadr(int adract)
} }
/* Parse and Create Anonymous String */ /* Parse and Create Anonymous String */
void prsstr(int adract) void prsstr(int adract) {
{
DEBUG("Parsing anonymous string\n", 0); DEBUG("Parsing anonymous string\n", 0);
newlbl(vrname); //Generate Variable Name newlbl(vrname); //Generate Variable Name
value[0] = 0; //Use Variable Size 0 value[0] = 0; //Use Variable Size 0
@ -127,8 +120,7 @@ void prsstr(int adract)
} }
/* Check for and Process Address or String */ /* Check for and Process Address or String */
int chkadr(int adract) int chkadr(int adract) {
{
DEBUG("Checking for Address or String\n", 0); DEBUG("Checking for Address or String\n", 0);
int result = TRUE; int result = TRUE;
if (look('&')) if (look('&'))
@ -142,8 +134,7 @@ int chkadr(int adract)
} }
/* Parse function call */ /* Parse function call */
void prsfnc(char trmntr) void prsfnc(char trmntr) {
{
DEBUG("Processing Function Call '%s'...\n", term); DEBUG("Processing Function Call '%s'...\n", term);
if (fnscnt >= MAXFNS) if (fnscnt >= MAXFNS)
ERROR("Maximum Function Call Depth Exceeded", 0, EXIT_FAILURE); ERROR("Maximum Function Call Depth Exceeded", 0, EXIT_FAILURE);
@ -175,8 +166,7 @@ void prsfnc(char trmntr)
/* Parse first term of expession * /* Parse first term of expession *
* First term can include function calls */ * First term can include function calls */
void prsftm() void prsftm(void) {
{
prsval(TRUE); prsval(TRUE);
DEBUG("Processing first term '%s'...\n", value); DEBUG("Processing first term '%s'...\n", value);
strcpy(term, value); strcpy(term, value);
@ -198,8 +188,7 @@ void prsftm()
/* Process Arithmetic or Bitwise Operator * /* Process Arithmetic or Bitwise Operator *
* and the term that follows it */ * and the term that follows it */
void prcopr() void prcopr(void) {
{
DEBUG("Processing operator '%c'\n", oper); DEBUG("Processing operator '%c'\n", oper);
switch(oper) switch(oper)
{ {
@ -229,8 +218,7 @@ void prcopr()
} }
/* Parse and compile expression */ /* Parse and compile expression */
void prsxpr(char trmntr) void prsxpr(char trmntr) {
{
DEBUG("Parsing expression\n", 0); DEBUG("Parsing expression\n", 0);
skpspc(); skpspc();
if (match('-')) { if (match('-')) {

View File

@ -13,8 +13,7 @@
/* Error - Print textual description of system error * /* Error - Print textual description of system error *
* and exit with system error code */ * and exit with system error code */
void extsys(char *s) void extsys(char *s) {
{
perror(s); perror(s);
exterr(errno); exterr(errno);
} }
@ -22,8 +21,7 @@ void extsys(char *s)
/* Open Source File * /* Open Source File *
* Uses: srcnam - Source File Name * * Uses: srcnam - Source File Name *
* Sets: srcfil - Source File Handle */ * Sets: srcfil - Source File Handle */
void opnsrc() 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 if (strrchr(srcnam, '.') == NULL) //if no extension
strcat(srcnam, ".c02"); // add ".c02" strcat(srcnam, ".c02"); // add ".c02"
@ -33,16 +31,14 @@ void opnsrc()
} }
/* Close Source File */ /* Close Source File */
void clssrc() void clssrc(void) {
{
fclose(srcfil); fclose(srcfil);
} }
/* Open Output File * /* Open Output File *
* Uses: outnam - Output File Name * * Uses: outnam - Output File Name *
* Sets: outfil - Output File Handle */ * Sets: outfil - Output File Handle */
void opnout() 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 if (strlen(outnam) == 0) //if Output File not specified
{ {
@ -59,8 +55,7 @@ void opnout()
} }
/* Close Output File */ /* Close Output File */
void clsout() void clsout(void) {
{
fprintf(outfil, "\n"); fprintf(outfil, "\n");
fclose(outfil); fclose(outfil);
} }
@ -68,8 +63,7 @@ void clsout()
/* Open Log File * /* Open Log File *
* Uses: srcnam - Source File Name * * Uses: srcnam - Source File Name *
* Sets: logfil - Log File Handle */ * Sets: logfil - Log File Handle */
void opnlog() void opnlog(void) {
{
strcpy(lognam, srcnam); //set Log File Name to Source File Name strcpy(lognam, srcnam); //set Log File Name to Source File Name
char *dot = strrchr(lognam, '.'); //find file extension char *dot = strrchr(lognam, '.'); //find file extension
if (dot != NULL) *dot = 0; //and remove it if (dot != NULL) *dot = 0; //and remove it
@ -81,14 +75,14 @@ void opnlog()
/* Close Log File * /* Close Log File *
* Uses: logfil - Log File Handle */ * Uses: logfil - Log File Handle */
void clslog() { void clslog(void) {
fclose(logfil); fclose(logfil);
} }
/* Open Include file * /* Open Include file *
* Uses: incnam - Include File Name * * Uses: incnam - Include File Name *
* Sets: incfil - Include File Handle */ * Sets: incfil - Include File Handle */
void opninc() void opninc(void)
{ {
DEBUG("Opening include file '%s'\n", incnam); DEBUG("Opening include file '%s'\n", incnam);
incfil = fopen(incnam, "r"); incfil = fopen(incnam, "r");

View File

@ -20,8 +20,7 @@
/* Read next include file name from Source File * /* Read next include file name from Source File *
* Sets: incnam - the include file name */ * Sets: incnam - the include file name */
void pincnm() void pincnm(void) {
{
char dlmtr; char dlmtr;
int inclen = 0; int inclen = 0;
skpspc(); skpspc();
@ -43,7 +42,7 @@ void pincnm()
} }
/* Process assembly language include file */ /* Process assembly language include file */
void incasm() { void incasm(void) {
opninc(); opninc();
setcmt("======== Assembler File "); setcmt("======== Assembler File ");
addcmt(incnam); addcmt(incnam);
@ -59,8 +58,7 @@ void incasm() {
} }
/* Process define directive */ /* Process define directive */
void pdefin() void pdefin(void) {
{
getwrd(); //get defined identifier getwrd(); //get defined identifier
DEBUG("Defining '%s'\n", word); DEBUG("Defining '%s'\n", word);
strncpy(defnam[defcnt], word, VARLEN); strncpy(defnam[defcnt], word, VARLEN);
@ -73,8 +71,7 @@ void pdefin()
} }
/* Process enum directive */ /* Process enum directive */
void penumd() void penumd(void) {
{
int enmval = 0; int enmval = 0;
do { do {
getwrd(); //get defined identifier getwrd(); //get defined identifier
@ -90,8 +87,7 @@ void penumd()
} }
/* Parse ASCII Subdirective */ /* Parse ASCII Subdirective */
void pascii() void pascii(void) {
{
getwrd(); //Get Pragma Subdirective getwrd(); //Get Pragma Subdirective
if (wordis("INVERT")) if (wordis("INVERT"))
invasc = TRUE; invasc = TRUE;
@ -104,23 +100,20 @@ void pascii()
} }
/* Parse Origin Subdirective */ /* Parse Origin Subdirective */
void porign() void porign(void) {
{
prsnum(0xFFFF); //Get Origin Address prsnum(0xFFFF); //Get Origin Address
asmlin(ORGOP, value); //Emit Origin Instruction asmlin(ORGOP, value); //Emit Origin Instruction
DEBUG("Set origin to %s\n", value); DEBUG("Set origin to %s\n", value);
} }
/* Parse Zeropage Subdirective */ /* Parse Zeropage Subdirective */
void prszpg() void prszpg(void) {
{
zpaddr = prsnum(0xFF); //Set Zero Page Address to Constant 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 */ /* Process Vartable Subdirective */
void pvrtbl() void pvrtbl(void) {
{
if (vrwrtn) { if (vrwrtn) {
ERROR("Variable table already written", 0, EXIT_FAILURE); ERROR("Variable table already written", 0, EXIT_FAILURE);
} }
@ -128,8 +121,7 @@ void pvrtbl()
} }
/* Parse Pragma Directive */ /* Parse Pragma Directive */
void pprgma() void pprgma(void) {
{
getwrd(); //Get Pragma Subdirective getwrd(); //Get Pragma Subdirective
DEBUG("Parsing pragma directive '%s'\n", word); DEBUG("Parsing pragma directive '%s'\n", word);
if (wordis("ASCII")) if (wordis("ASCII"))
@ -145,8 +137,7 @@ void pprgma()
} }
/* Process Include File Directive */ /* Process Include File Directive */
void pincdr() void pincdr(void) {
{
skpchr(); //skip '#' skpchr(); //skip '#'
getwrd(); //read directive into word getwrd(); //read directive into word
DEBUG("Processing include file directive '%s'\n", word); DEBUG("Processing include file directive '%s'\n", word);
@ -161,7 +152,7 @@ void pincdr()
} }
/* Parse Header Word */ /* Parse Header Word */
void phdwrd() { void phdwrd(void) {
getwrd(); getwrd();
if (!ptype(MTNONE)) { if (!ptype(MTNONE)) {
fprintf(stderr, "Unexpected word '%s' in header\n", word); fprintf(stderr, "Unexpected word '%s' in header\n", word);
@ -170,14 +161,14 @@ void phdwrd() {
} }
/* Save Source File Information */ /* Save Source File Information */
void savsrc() { void savsrc(void) {
savchr = nxtchr; savchr = nxtchr;
savcol = curcol; savcol = curcol;
savlin = curlin; savlin = curlin;
} }
/* Set Include File Information */ /* Set Include File Information */
void setinc() { void setinc(void) {
curcol = 0; curcol = 0;
curlin = 0; curlin = 0;
inpfil = incfil; inpfil = incfil;
@ -193,13 +184,13 @@ void setinm(char* filext) {
} }
/* Set Input to Source File */ /* Set Input to Source File */
void setsrc() { void setsrc(void) {
inpfil = srcfil; inpfil = srcfil;
strcpy(inpnam, srcnam); strcpy(inpnam, srcnam);
} }
/* Restore Source File Pointer*/ /* Restore Source File Pointer*/
void rstsrc() { void rstsrc(void) {
nxtchr = savchr; nxtchr = savchr;
nxtupc = toupper(nxtchr); nxtupc = toupper(nxtchr);
curcol = savcol; curcol = savcol;
@ -209,7 +200,7 @@ void rstsrc() {
} }
/* Process header include file */ /* Process header include file */
void inchdr() { void inchdr(void) {
savsrc(); //Save Source File Information savsrc(); //Save Source File Information
opninc(); //Open Include File opninc(); //Open Include File
setinc(); //Set Include File Information setinc(); //Set Include File Information
@ -236,8 +227,7 @@ void inchdr() {
} }
/* Process Header File specified on Command Line */ /* Process Header File specified on Command Line */
void phdrfl() void phdrfl(void) {
{
if (hdrnam[0] == 0) return; if (hdrnam[0] == 0) return;
DEBUG("Processing Header '%s'\n", hdrnam); DEBUG("Processing Header '%s'\n", hdrnam);
setinm(".h02"); setinm(".h02");
@ -247,8 +237,7 @@ void phdrfl()
} }
/* Process include file */ /* Process include file */
void pincfl() void pincfl(void) {
{
pincnm(); //Parse Include File Name 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 char *dot = strrchr(incnam, '.'); //find extension
@ -272,8 +261,7 @@ void pincfl()
} }
/* Print Definition Table to Log File */ /* Print Definition Table to Log File */
void logdef() void logdef(void) {
{
int i; int i;
fprintf(logfil, "\n%-31s %5s\n", "Definition", "Value"); fprintf(logfil, "\n%-31s %5s\n", "Definition", "Value");
for (i=0; i<defcnt; i++) for (i=0; i<defcnt; i++)

View File

@ -21,8 +21,7 @@ const char lblflg[] = {LFNONE, LFNONE, LFBGN, LFEND, LFBGN, LFEND, LFEND, LFNONE
* Sets: tmplbl - Label name * * Sets: tmplbl - Label name *
* Returns: Index into label table * * Returns: Index into label table *
* (-1 if not found) */ * (-1 if not found) */
int lstlbl(int lbflag) int lstlbl(int lbflag) {
{
int i; 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--) { for (i = lblcnt - 1; i>-1; i--) {
@ -36,16 +35,14 @@ int lstlbl(int lbflag)
} }
/* Set Block Flag for Last Label */ /* Set Block Flag for Last Label */
void setblk(int blkflg) void setblk(int blkflg) {
{
lblblk[lblcnt-1] = blkflg; lblblk[lblcnt-1] = blkflg;
} }
/* Set label for next line of * /* Set label for next line of *
* Assembly Language Code * * Assembly Language Code *
* to word */ * to word */
void setlbl(char *lblset) void setlbl(char *lblset) {
{
DEBUG("Setting Label '%s'\n", lblset); DEBUG("Setting Label '%s'\n", lblset);
if (strlen(lblasm) > 0) { if (strlen(lblasm) > 0) {
DEBUG("Emitting Label '%s'\n'", lblasm); DEBUG("Emitting Label '%s'\n'", lblasm);
@ -57,8 +54,7 @@ void setlbl(char *lblset)
} }
/* parse label in code */ /* parse label in code */
void prslbl() void prslbl(void) {
{
DEBUG("Parsing Label '%s''\n", word); DEBUG("Parsing Label '%s''\n", word);
CCMNT(nxtchr); CCMNT(nxtchr);
skpchr(); //skip ':' skpchr(); //skip ':'
@ -66,8 +62,7 @@ void prslbl()
} }
/* generate new label */ /* generate new label */
void newlbl(char* lbname) void newlbl(char* lbname) {
{
sprintf(lbname, LABFMT, lblnxt++); sprintf(lbname, LABFMT, lblnxt++);
DEBUG("Generated new label '%s'\n", lbname); DEBUG("Generated new label '%s'\n", lbname);
} }
@ -75,8 +70,7 @@ void newlbl(char* lbname)
/* Check Label Contents * /* Check Label Contents *
* If lbname is blank, generate new * * If lbname is blank, generate new *
* label and copy into lbname */ * label and copy into lbname */
void chklbl(char* lbname) void chklbl(char* lbname) {
{
if (lbname[0]) return; if (lbname[0]) return;
newlbl(lbname); newlbl(lbname);
} }
@ -84,8 +78,7 @@ void chklbl(char* lbname)
/* Require Label * /* Require Label *
* if label is already set, returns that label * * if label is already set, returns that label *
* else generates new label and sets it */ * else generates new label and sets it */
void reqlbl(char* lbname) void reqlbl(char* lbname) {
{
if (lblasm[0]) if (lblasm[0])
strcpy(lbname, lblasm); strcpy(lbname, lblasm);
else { else {
@ -95,8 +88,7 @@ void reqlbl(char* lbname)
} }
/* Pop Label from Stack and Emit on Next Line */ /* Pop Label from Stack and Emit on Next Line */
int poplbl() int poplbl(void) {
{
int lbtype = lbltyp[--lblcnt]; int lbtype = lbltyp[--lblcnt];
DEBUG("Popped label type %d\n", lbtype); DEBUG("Popped label type %d\n", lbtype);
if (lbtype == LTLOOP) if (lbtype == LTLOOP)
@ -119,8 +111,7 @@ int poplbl()
} }
/* Get Top Label and Return Type */ /* Get Top Label and Return Type */
int toplbl(char *rtlbl) int toplbl(char *rtlbl) {
{
if (lblcnt) { if (lblcnt) {
strcpy(rtlbl, lblnam[lblcnt-1]); strcpy(rtlbl, lblnam[lblcnt-1]);
DEBUG("Found top label %s\n", rtlbl); DEBUG("Found top label %s\n", rtlbl);
@ -133,8 +124,7 @@ int toplbl(char *rtlbl)
/* Push Label onto Stack * /* Push Label onto Stack *
* Args: lbltyp - Label type * * Args: lbltyp - Label type *
* Uses: curlbl - Label to push */ * Uses: curlbl - Label to push */
void pshlbl(int lbtype, char* lbname) void pshlbl(int lbtype, char* lbname) {
{
DEBUG("Pushing label type %d\n", lbtype); DEBUG("Pushing label type %d\n", lbtype);
strcpy(lblnam[lblcnt], lbname); strcpy(lblnam[lblcnt], lbname);
lbltyp[lblcnt] = lbtype; lbltyp[lblcnt] = lbtype;

View File

@ -16,23 +16,23 @@
/* Various tests against nxtchr */ /* Various tests against nxtchr */
int match(char c) {return TF(nxtchr == c);} int match(char c) {return TF(nxtchr == c);}
int inbtwn(char mn, char mx) {return TF(nxtchr >= mn && nxtchr <= mx);} int inbtwn(char mn, char mx) {return TF(nxtchr >= mn && nxtchr <= mx);}
int isalph() {return isalpha(nxtchr);} int isalph(void) {return isalpha(nxtchr);}
int isanum() {return isalnum(nxtchr);} int isanum(void) {return isalnum(nxtchr);}
int isapos() {return match('\'');} int isapos(void) {return match('\'');}
int isbin() {return inbtwn('0', '1');} int isbin(void) {return inbtwn('0', '1');}
int isbpre() {return TF(isnpre() || isapos());} int isbpre(void) {return TF(isnpre() || isapos());}
int iscpre() {return TF(isbpre() || ishash());} int iscpre(void) {return TF(isbpre() || ishash());}
int isdec() {return inbtwn('0', '9');} int isdec(void) {return inbtwn('0', '9');}
int ishash() {return match('#');} int ishash(void) {return match('#');}
int ishexd() {return TF(isdec() || inbtwn('A', 'Z'));} int ishexd(void) {return TF(isdec() || inbtwn('A', 'Z'));}
int isnl() {return TF(match('\n') || match('\r'));} int isnl(void) {return TF(match('\n') || match('\r'));}
int isnpre() {return TF(isdec() || match('$') || match('%'));} int isnpre(void) {return TF(isdec() || match('$') || match('%'));}
int isoper() {return TF(strchr("+-&|^", nxtchr));} int isoper(void) {return TF(strchr("+-&|^", nxtchr));}
int ispopr() {return TF(strchr("+-<>", nxtchr));} int ispopr(void) {return TF(strchr("+-<>", nxtchr));}
int isprnt() {return isprint(nxtchr);} int isprnt(void) {return isprint(nxtchr);}
int isspc() {return isspace(nxtchr);} int isspc(void) {return isspace(nxtchr);}
int isvpre() {return TF(isalph() || iscpre());} int isvpre(void) {return TF(isalph() || iscpre());}
int isxpre() {return TF(isvpre() || match('-'));} int isxpre(void) {return TF(isvpre() || match('-'));}
/* Process ASCII Character */ /* Process ASCII Character */
char prcchr(char c) { char prcchr(char c) {
@ -43,17 +43,14 @@ char prcchr(char c) {
} }
/* if Word is s then return TRUE else return FALSE*/ /* if Word is s then return TRUE else return FALSE*/
int wordis(char *s) int wordis(char *s) {
{
return strcmp(word, s) == 0; return strcmp(word, s) == 0;
} }
/* Get Next Character from Current Input File * /* Get Next Character from Current Input File *
* Uses: inpfil - Input File Handle * * Uses: inpfil - Input File Handle *
* Sets: nxtchr - Next Character in Source File */ * Sets: nxtchr - Next Character in Source File */
char getnxt() char getnxt(void) {
{
int i;
int wascr = match('\r'); int wascr = match('\r');
char c = nxtchr; char c = nxtchr;
//if (nxtwrd[nxtptr]) //If nxtwrd is set //if (nxtwrd[nxtptr]) //If nxtwrd is set
@ -68,8 +65,7 @@ char getnxt()
} }
/* Advance Input File to next printable character */ /* Advance Input File to next printable character */
void skpspc() void skpspc(void) {
{
//DEBUG("Skipping Spaces\n", 0); //DEBUG("Skipping Spaces\n", 0);
if (isspc()) CCMNT(' '); //Add only the first space to comments if (isspc()) CCMNT(' '); //Add only the first space to comments
while (isspc()) while (isspc())
@ -80,8 +76,7 @@ void skpspc()
* and advance past it if it is * * and advance past it if it is *
* Returns TRUE is character is found, * * Returns TRUE is character is found, *
* otherwise FALSE */ * otherwise FALSE */
int look(char c) int look(char c) {
{
int found; int found;
skpspc(); skpspc();
found = match(c); found = match(c);
@ -93,8 +88,7 @@ int look(char c)
} }
/* if next printable character is c then skip, else generate error */ /* if next printable character is c then skip, else generate error */
void expect(char c) void expect(char c) {
{
if (c == 0) return; if (c == 0) return;
if (look(c)) return; if (look(c)) return;
else { else {
@ -104,14 +98,17 @@ void expect(char c)
} }
/* Advance Input File to next printable character */ /* Advance Input File to next printable character */
void skpchr() {char skip = getnxt();} void skpchr(void) {
char skip = getnxt();
DEBUG("Skipped character '%c'\n", skip);
}
/* Advance Input File to end of line */ /* Advance Input File to end of line */
void skpeol() {while (!isnl()) getnxt();} void skpeol(void) {while (!isnl()) getnxt();}
/* Advance Source File to end of comment * /* Advance Source File to end of comment *
* Recognizes both C and C++ style comments */ * Recognizes both C and C++ style comments */
void skpcmt() void skpcmt(void)
{ {
DEBUG("Skipping Comment\n", 0); DEBUG("Skipping Comment\n", 0);
skpchr(); //skip initial / skpchr(); //skip initial /
@ -135,8 +132,7 @@ void skpcmt()
/* Reads next Word in current Input File, where * /* Reads next Word in current Input File, where *
* a Word is a sequence of AlphaNumeric characters * * a Word is a sequence of AlphaNumeric characters *
* Sets: word - the Word read from the source file */ * Sets: word - the Word read from the source file */
void getwrd() void getwrd(void) {
{
int wrdlen = 0; int wrdlen = 0;
skpspc(); skpspc();
if (!isalph()) expctd("Alphabetic Character"); if (!isalph()) expctd("Alphabetic Character");
@ -149,8 +145,7 @@ void getwrd()
} }
/* Escape Character */ /* Escape Character */
char escape(char c) char escape(char c) {
{
DEBUG("Escaping character '%c'\n", c); DEBUG("Escaping character '%c'\n", c);
switch (c) { switch (c) {
case 'r': return 0x0d; case 'r': return 0x0d;
@ -159,8 +154,8 @@ char escape(char c)
} }
/* Get String */ /* Get String */
void getstr() { void getstr(void) {
char strdel, tmpchr; char strdel;
int wrdlen = 0, escnxt = FALSE; int wrdlen = 0, escnxt = FALSE;
DEBUG("Parsing string\n", 0); DEBUG("Parsing string\n", 0);
strdel = getnxt(); //Get String Delimiter strdel = getnxt(); //Get String Delimiter
@ -189,8 +184,7 @@ void getstr() {
* prefixed with '%' * * prefixed with '%' *
* Sets: word - binary number including leading '%' * * Sets: word - binary number including leading '%' *
* Returns: integer value of number */ * Returns: integer value of number */
int prsbin() int prsbin(void) {
{
int wrdlen = 0; int wrdlen = 0;
int digit; int digit;
int number = 0; int number = 0;
@ -212,8 +206,7 @@ int prsbin()
* a Decimal is a series of digits (0-9) * * a Decimal is a series of digits (0-9) *
* Sets: word - number without leading 0's * * Sets: word - number without leading 0's *
* Returns: integer value of number */ * Returns: integer value of number */
int prsdec() int prsdec(void) {
{
int wrdlen = 0; int wrdlen = 0;
int digit; int digit;
int number = 0; int number = 0;
@ -233,8 +226,7 @@ int prsdec()
/* Reads Hexadecimal number from input file * /* Reads Hexadecimal number from input file *
* Sets: word - Hex number including leading '$' * * Sets: word - Hex number including leading '$' *
* Returns: integer value of number */ * Returns: integer value of number */
int prshex() int prshex(void) {
{
int wrdlen = 0; int wrdlen = 0;
int digit; int digit;
int number = 0; int number = 0;
@ -261,8 +253,7 @@ int prshex()
* Sets: word - Character constant including * * Sets: word - Character constant including *
* single quotes * * single quotes *
* Returns: ASCII value of constant */ * Returns: ASCII value of constant */
int prschr() int prschr(void) {
{
int wrdlen = 0; int wrdlen = 0;
char c; char c;
DEBUG("Parsing character constant\n", 0); DEBUG("Parsing character constant\n", 0);
@ -284,8 +275,7 @@ int prschr()
* Sets: value - parsed number (as string) * * Sets: value - parsed number (as string) *
* word - parses text of value * * word - parses text of value *
* Returns: parsed number */ * Returns: parsed number */
int prsnum(int maxval) int prsnum(int maxval) {
{
int number; int number;
skpspc(); skpspc();
if (!isbpre()) expctd("constant value"); if (!isbpre()) expctd("constant value");
@ -316,14 +306,10 @@ int prsnum(int maxval)
} }
/* Parse Nuneric Byte Value */ /* Parse Nuneric Byte Value */
int prsbyt() int prsbyt(void) {return prsnum(0xFF);}
{
return prsnum(0xFF);
}
/* Find Defined Constant */ /* Find Defined Constant */
void fnddef(char *name) 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++) { for (defidx=0; defidx<defcnt; defidx++) {
if (strcmp(defnam[defidx], name) == 0) if (strcmp(defnam[defidx], name) == 0)
@ -333,8 +319,7 @@ void fnddef(char *name)
} }
/* Parse Definition */ /* Parse Definition */
int prsdef() int prsdef(void) {
{
expect('#'); expect('#');
getwrd(); //Get Constant Name getwrd(); //Get Constant Name
fnddef(word); fnddef(word);
@ -354,8 +339,7 @@ int prsdef()
* Note: Value is converted to hexadecimal * * Note: Value is converted to hexadecimal *
* because DASM uses the format 'c for * * because DASM uses the format 'c for *
* character arguments instead of 'c' */ * character arguments instead of 'c' */
void prscon() void prscon(void) {
{
skpspc(); skpspc();
if (ishash()) if (ishash())
cnstnt = prsdef(); cnstnt = prsdef();
@ -369,17 +353,15 @@ void prscon()
} }
/* Get Value Type */ /* Get Value Type */
int gettyp() int gettyp(void) {
{
if (match('(')) return FUNCTION; if (match('(')) return FUNCTION;
else if (match('[')) return ARRAY; else if (match('[')) return ARRAY;
else return VARIABLE; else return VARIABLE;
} }
/* Parse arithmetic or bitwise operator */ /* Parse arithmetic or bitwise operator */
void prsopr() void prsopr(void) {
{ if (!isoper())
if (!isoper)
expctd("Arithmetic or bitwise operator"); expctd("Arithmetic or bitwise operator");
oper = getnxt(); oper = getnxt();
DEBUG("Parsed operator '%c'\n", oper); DEBUG("Parsed operator '%c'\n", oper);
@ -389,22 +371,19 @@ void prsopr()
/* Generate Post-Operation Error */ /* Generate Post-Operation Error */
void poperr(char* name) void poperr(char* name) {
{
fprintf(stderr, "Illegal post-operation %c%c on register %s\n", oper, oper, name); fprintf(stderr, "Illegal post-operation %c%c on register %s\n", oper, oper, name);
exterr(EXIT_FAILURE); exterr(EXIT_FAILURE);
} }
/* Process Post Operator */ /* Process Post Operator */
void prcpst(char* name, char *index) void prcpst(char* name, char *index) {
{
DEBUG("Processing post operation '%c'\n", oper); DEBUG("Processing post operation '%c'\n", oper);
if (strlen(index)) { if (strlen(index)) {
asmlin("LDX", index); asmlin("LDX", index);
strcat(name,",X"); strcat(name,",X");
} }
switch(oper) switch(oper) {
{
case '+': case '+':
if (strcmp(name, "X")==0) if (strcmp(name, "X")==0)
asmlin("INX", ""); asmlin("INX", "");

View File

@ -18,8 +18,7 @@
#include "stmnt.h" #include "stmnt.h"
/* Begin Program Block */ /* Begin Program Block */
void bgnblk(char blkchr) void bgnblk(char blkchr) {
{
DEBUG("Begining program block\n", 0); DEBUG("Begining program block\n", 0);
if (blkchr) { if (blkchr) {
expect(blkchr); expect(blkchr);
@ -33,8 +32,7 @@ void bgnblk(char blkchr)
/* End Program Block * /* End Program Block *
* Args: blkflg: End of Multiline Block */ * Args: blkflg: End of Multiline Block */
void endblk(int blkflg) void endblk(int blkflg) {
{
int lbtype; int lbtype;
DEBUG("Ending program block with flag %d\n", blkflg); DEBUG("Ending program block with flag %d\n", blkflg);
expect('}'); //Block End Character expect('}'); //Block End Character
@ -75,8 +73,7 @@ void prcidx(int idxtyp, char *name, char *index)
} }
/* Process Assignment */ /* Process Assignment */
void prcasn(char trmntr) void prcasn(char trmntr) {
{
expect('='); expect('=');
if (look('(')) if (look('('))
prssif(trmntr); //Parse Shortcut If prssif(trmntr); //Parse Shortcut If
@ -108,8 +105,7 @@ void prcasn(char trmntr)
} }
/* Parse and Return Array Index and Type */ /* Parse and Return Array Index and Type */
int getidx(char* idx) int getidx(char* idx) {
{
prsidx(); //Parse Array Index prsidx(); //Parse Array Index
if (valtyp == CONSTANT) if (valtyp == CONSTANT)
strncpy(idx, word, VARLEN); strncpy(idx, word, VARLEN);
@ -120,8 +116,7 @@ int getidx(char* idx)
} }
/* Process Assignment Variable(s) */ /* Process Assignment Variable(s) */
void prcvar(char trmntr) void prcvar(char trmntr) {
{
chksym(TRUE, word); chksym(TRUE, word);
strcpy(asnvar, word); //save variable to assign to strcpy(asnvar, word); //save variable to assign to
asntyp = valtyp; //Set Assigned Varable Type asntyp = valtyp; //Set Assigned Varable Type
@ -171,8 +166,7 @@ void prcvar(char trmntr)
} }
/* Parse 'asm' String Parameter */ /* Parse 'asm' String Parameter */
void pasmst(char trmntr) void pasmst(char trmntr) {
{
skpspc(); //Skip Spaces skpspc(); //Skip Spaces
if (!match('"')) if (!match('"'))
expctd("string"); expctd("string");
@ -182,8 +176,7 @@ void pasmst(char trmntr)
} }
/* Parse and Compile 'asm' statement */ /* Parse and Compile 'asm' statement */
void pasm() void pasm(void) {
{
char opcode[LINELEN]; char opcode[LINELEN];
expect('('); expect('(');
pasmst(','); pasmst(',');
@ -196,8 +189,7 @@ void pasm()
} }
/* Parse and Compile an Assignment */ /* Parse and Compile an Assignment */
void prsasn(char trmntr) void prsasn(char trmntr) {
{
getwrd(); //Get Variable to be Assigned getwrd(); //Get Variable to be Assigned
prcvar(trmntr); prcvar(trmntr);
} }
@ -214,8 +206,7 @@ void pbrcnt(int lbflag)
} }
/* parse and compile 'do' statement */ /* parse and compile 'do' statement */
void pdo() void pdo(void) {
{
DEBUG("Parsing DO statement '%c'\n", nxtchr); DEBUG("Parsing DO statement '%c'\n", nxtchr);
newlbl(endlbl); //Create End Label newlbl(endlbl); //Create End Label
pshlbl(LTDWHL, endlbl); //and Push onto Stack pshlbl(LTDWHL, endlbl); //and Push onto Stack
@ -227,7 +218,7 @@ void pdo()
} }
/* parse and compile 'while' after 'do' statement */ /* parse and compile 'while' after 'do' statement */
void pdowhl() { void pdowhl(void) {
DEBUG("Parsing WHILE after DO '%c'\n", nxtchr); DEBUG("Parsing WHILE after DO '%c'\n", nxtchr);
getwrd(); //Check for While getwrd(); //Check for While
if (!wordis("WHILE")) if (!wordis("WHILE"))
@ -245,7 +236,7 @@ void pdowhl() {
/* parse and compile for statement */ /* parse and compile for statement */
void pfor() { void pfor(void) {
DEBUG("Parsing FOR statement '%c'\n", nxtchr); DEBUG("Parsing FOR statement '%c'\n", nxtchr);
expect('('); expect('(');
prsasn(';'); //Process Initial Assignment prsasn(';'); //Process Initial Assignment
@ -266,7 +257,7 @@ void pfor() {
} }
/* parse and compile if statement */ /* parse and compile if statement */
void pif() { void pif(void) {
DEBUG("Parsing IF statement\n", 0); DEBUG("Parsing IF statement\n", 0);
expect('('); expect('(');
newlbl(cndlbl); //Create New Label newlbl(cndlbl); //Create New Label
@ -276,7 +267,7 @@ void pif() {
} }
/* parse and compile else statement */ /* parse and compile else statement */
void pelse() { void pelse(void) {
DEBUG("Parsing ELSE statement\n", 0); DEBUG("Parsing ELSE statement\n", 0);
strcpy(lbltmp, lblasm); //Save Line Label strcpy(lbltmp, lblasm); //Save Line Label
lblasm[0] = 0; //and Clear It lblasm[0] = 0; //and Clear It
@ -288,7 +279,7 @@ void pelse() {
} }
/* parse and compile if statement */ /* parse and compile if statement */
void pgoto() { void pgoto(void) {
DEBUG("Parsing GOTO statement\n", 0); DEBUG("Parsing GOTO statement\n", 0);
getwrd(); getwrd();
expect(';'); expect(';');
@ -296,8 +287,7 @@ void pgoto() {
} }
/* parse and compile inline statement */ /* parse and compile inline statement */
void pinlne() void pinlne(void) {
{
DEBUG("Parsing INLINE statement\n", 0); DEBUG("Parsing INLINE statement\n", 0);
do { do {
DEBUG("Parsing inline parameter\n", 0); DEBUG("Parsing inline parameter\n", 0);
@ -331,8 +321,7 @@ void pinlne()
} }
/* parse and compile pop statement */ /* parse and compile pop statement */
void ppop() void ppop(void) {
{
DEBUG("Parsing POP statement\n", 0); DEBUG("Parsing POP statement\n", 0);
do { do {
asmlin("PLA", ""); //Pop Value off Stack asmlin("PLA", ""); //Pop Value off Stack
@ -347,8 +336,7 @@ void ppop()
} }
/* parse and compile push statement */ /* parse and compile push statement */
void ppush() void ppush(void) {
{
DEBUG("Parsing PUSH statement\n", 0); DEBUG("Parsing PUSH statement\n", 0);
do { do {
if (!chkadr(1)) { if (!chkadr(1)) {
@ -360,7 +348,7 @@ void ppush()
} }
/* parse and compile return statement */ /* parse and compile return statement */
void pretrn() { void pretrn(void) {
DEBUG("Parsing RETURN statement\n", 0); DEBUG("Parsing RETURN statement\n", 0);
if (!look(';')) if (!look(';'))
prsxpr(';'); prsxpr(';');
@ -369,7 +357,7 @@ void pretrn() {
} }
/* parse and compile select statement */ /* parse and compile select statement */
void pslct() { void pslct(void) {
DEBUG("Parsing SELECT statement\n", 0); DEBUG("Parsing SELECT statement\n", 0);
expect('('); expect('(');
prsxpr(')'); //Parse Expression prsxpr(')'); //Parse Expression
@ -381,7 +369,7 @@ void pslct() {
} }
/* process end of case block */ /* process end of case block */
void ecase() { void ecase(void) {
DEBUG("Processing end of CASE block\n", 0); DEBUG("Processing end of CASE block\n", 0);
if (poplbl(cndlbl) != LTCASE) if (poplbl(cndlbl) != LTCASE)
ERROR("%s not at end of CASE block\n", word, EXIT_FAILURE); ERROR("%s not at end of CASE block\n", word, EXIT_FAILURE);
@ -392,9 +380,9 @@ void ecase() {
} }
/* parse and compile select statement */ /* parse and compile select statement */
void pcase() { void pcase(void) {
if (!fcase) if (!fcase)
ecase("CASE"); //Process end of case block ecase(); //Process end of case block
skplbl[0] = 0; //Clear Skip Label skplbl[0] = 0; //Clear Skip Label
newlbl(cndlbl); //Create Conditional Label newlbl(cndlbl); //Create Conditional Label
pshlbl(LTCASE, cndlbl); //and Push onto Stack pshlbl(LTCASE, cndlbl); //and Push onto Stack
@ -418,13 +406,13 @@ void pcase() {
} }
/* parse and compile default statement */ /* parse and compile default statement */
void pdflt() { void pdflt(void) {
expect(':'); expect(':');
ecase(); //Process end of case block ecase(); //Process end of case block
} }
/* parse and compile while statement */ /* parse and compile while statement */
void pwhile() { void pwhile(void) {
DEBUG("Parsing WHILE statement '%c'\n", nxtchr); DEBUG("Parsing WHILE statement '%c'\n", nxtchr);
expect('('); expect('(');
newlbl(endlbl); //Create End Label newlbl(endlbl); //Create End Label
@ -443,21 +431,19 @@ void pwhile() {
} }
/* generate unimplemented statement error */ /* generate unimplemented statement error */
void punimp() { void punimp(void) {
ERROR("Unimplemented statement '%s' encountered\n", word, EXIT_FAILURE); ERROR("Unimplemented statement '%s' encountered\n", word, EXIT_FAILURE);
} }
/* Parse Function Call as Statement */ /* Parse Function Call as Statement */
void prsfns() void prsfns(void) {
{
strcpy(term, word); //Copy Function Name strcpy(term, word); //Copy Function Name
prsfnc(';'); //Parse Function Call prsfnc(';'); //Parse Function Call
return; return;
} }
/* parse and compile identifier (variable or function call) */ /* parse and compile identifier (variable or function call) */
void prssym() void prssym(void) {
{
DEBUG("Parsing Identifier %s\n", word); DEBUG("Parsing Identifier %s\n", word);
valtyp = gettyp(); valtyp = gettyp();
if (valtyp == FUNCTION) if (valtyp == FUNCTION)
@ -467,8 +453,7 @@ void prssym()
} }
/* parse and compile program statement */ /* parse and compile program statement */
void pstmnt() void pstmnt(void) {
{
DEBUG("Parsing statement '%s'\n", word); DEBUG("Parsing statement '%s'\n", word);
if (wordis("DO")) { if (wordis("DO")) {
pdo(); pdo();

View File

@ -19,8 +19,7 @@
* Sets: varidx = index into varnam array * * Sets: varidx = index into varnam array *
* varcnt if not found * * varcnt if not found *
* Returns: TRUE if found, otherwise FALSE */ * Returns: TRUE if found, otherwise FALSE */
int fndvar(char *name) int fndvar(char *name) {
{
DEBUG("Looking up variable '%s'\n", word); DEBUG("Looking up variable '%s'\n", word);
for (varidx=0; varidx<varcnt; varidx++) { for (varidx=0; varidx<varcnt; varidx++) {
if (strcmp(varnam[varidx], name) == 0) if (strcmp(varnam[varidx], name) == 0)
@ -33,8 +32,7 @@ int fndvar(char *name)
* Generates error if variable is undefined * * Generates error if variable is undefined *
* Args: alwreg - allow register name * * Args: alwreg - allow register name *
* name - variable name */ * name - variable name */
void chksym(int alwreg, char *name) void chksym(int alwreg, char *name) {
{
if (strlen(name) == 1 && strchr("AXY", name[0])) { if (strlen(name) == 1 && strchr("AXY", name[0])) {
if (alwreg && valtyp != ARRAY) { if (alwreg && valtyp != ARRAY) {
valtyp = REGISTER; valtyp = REGISTER;
@ -50,8 +48,7 @@ void chksym(int alwreg, char *name)
* Args: alwreg - Allow Register Names * * Args: alwreg - Allow Register Names *
* Sets: value - Identifier Name * * Sets: value - Identifier Name *
* valtyp - Identifier Type */ * valtyp - Identifier Type */
void prsvar(int alwreg) void prsvar(int alwreg) {
{
getwrd(); getwrd();
valtyp = gettyp(); valtyp = gettyp();
if (valtyp != FUNCTION) chksym(alwreg, word); if (valtyp != FUNCTION) chksym(alwreg, word);
@ -62,8 +59,7 @@ void prsvar(int alwreg)
/* Require and Parse Variable Name * /* Require and Parse Variable Name *
* Parameters: alwary - Allow Array Reference * * Parameters: alwary - Allow Array Reference *
* Sets: vrname - operand for LDA/STA/LDY/STY */ * Sets: vrname - operand for LDA/STA/LDY/STY */
void reqvar(int alwary) void reqvar(int alwary) {
{
prsvar(FALSE); prsvar(FALSE);
if (!alwary) if (!alwary)
if (valtyp != VARIABLE) if (valtyp != VARIABLE)
@ -71,8 +67,7 @@ void reqvar(int alwary)
} }
/* Parse Data Array */ /* Parse Data Array */
void prsdta() void prsdta(void) {
{
dtype = DTARRY; dtype = DTARRY;
expect('{'); expect('{');
dlen = 0; dlen = 0;
@ -86,8 +81,7 @@ void prsdta()
} }
/* Parse Data String */ /* Parse Data String */
void prsdts() void prsdts(void) {
{
dtype = DTSTR; dtype = DTSTR;
getstr(); getstr();
strcpy(value, word); strcpy(value, word);
@ -98,8 +92,7 @@ void prsdts()
* Uses: value - Data to store * * Uses: value - Data to store *
* Sets: datvar[] - Variable Data * * Sets: datvar[] - Variable Data *
* datlen[] - Data Length */ * datlen[] - Data Length */
void setdat() void setdat(void) {
{
int i; int i;
if (dtype == DTBYTE) { if (dtype == DTBYTE) {
DEBUG("Setting variable data to '%d'\n", cnstnt); DEBUG("Setting variable data to '%d'\n", cnstnt);
@ -123,8 +116,7 @@ void setdat()
} }
/* Parse and store variable data */ /* Parse and store variable data */
void prsdat() void prsdat(void) {
{
DEBUG("Checking for variable data\n", 0); DEBUG("Checking for variable data\n", 0);
if (!look('=')) { if (!look('=')) {
datlen[varcnt] = 0; datlen[varcnt] = 0;
@ -147,8 +139,7 @@ void prsdat()
/* Add Variable to Variable table * /* Add Variable to Variable table *
* Uses: word - variable name * * Uses: word - variable name *
* value - variable size */ * value - variable size */
void setvar(int m, int t) void setvar(int m, int t) {
{
DEBUG("Added variable '%s' ", word); DEBUG("Added variable '%s' ", word);
strncpy(varnam[varcnt], vrname, VARLEN); strncpy(varnam[varcnt], vrname, VARLEN);
varmod[varcnt] = m; varmod[varcnt] = m;
@ -159,8 +150,7 @@ void setvar(int m, int t)
/* Parse and Compile Variable Declaration * /* Parse and Compile Variable Declaration *
* Uses: word - variable name */ * Uses: word - variable name */
void addvar(int m, int t) void addvar(int m, int t) {
{
strcpy(vrname, word); //Save Variable Name strcpy(vrname, word); //Save Variable Name
if (fndvar(vrname)) if (fndvar(vrname))
ERROR("Duplicate declaration of variable '%s\n", word,EXIT_FAILURE); ERROR("Duplicate declaration of variable '%s\n", word,EXIT_FAILURE);
@ -193,8 +183,7 @@ void addvar(int m, int t)
/* Write Variable Table */ /* Write Variable Table */
void vartbl() void vartbl(void) {
{
int i, j; 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"); fprintf(logfil, "\n%-31s %s %s %s\n", "Variable", "Type", "Size", "Data");