mirror of
https://github.com/RevCurtisP/C02.git
synced 2025-04-22 00:37:19 +00:00
Fixed C compiler warnings
This commit is contained in:
parent
f713118fe6
commit
1156f3b47b
@ -14,8 +14,7 @@
|
||||
#include "asm.h"
|
||||
|
||||
/* Process comment */
|
||||
void prccmt()
|
||||
{
|
||||
void prccmt(void) {
|
||||
if (strlen(cmtasm)) {
|
||||
strcpy(asmcmt, ";");
|
||||
strcat(asmcmt, cmtasm);
|
||||
@ -26,8 +25,7 @@ void prccmt()
|
||||
}
|
||||
|
||||
/* 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);
|
||||
prccmt();
|
||||
fprintf(outfil, ASMFMT, lblasm, opcode, oprnd, asmcmt);
|
||||
@ -36,8 +34,7 @@ void asmlin(char *opcode, char *oprnd)
|
||||
}
|
||||
|
||||
/* output a single comment line */
|
||||
void cmtlin()
|
||||
{
|
||||
void cmtlin(void) {
|
||||
DEBUG("Writing Comment Line: %s\n", cmtasm);
|
||||
fprintf(outfil, "; %s\n", cmtasm);
|
||||
setcmt("");
|
||||
|
33
src/c02.c
33
src/c02.c
@ -26,8 +26,7 @@
|
||||
#include "include.h" //Include File Parsing
|
||||
|
||||
/* Initilize Compiler Variables */
|
||||
void init()
|
||||
{
|
||||
void init(void) {
|
||||
DEBUG("Initializing Compiler Variables\n",0);
|
||||
defcnt = 0;
|
||||
varcnt = 0;
|
||||
@ -50,8 +49,7 @@ void init()
|
||||
}
|
||||
|
||||
/* Reads and parses the next Word in Source File */
|
||||
void pword()
|
||||
{
|
||||
void pword(void) {
|
||||
lsrtrn = FALSE; //Clear RETURN flag
|
||||
getwrd();
|
||||
DEBUG("Parsing Word '%s'\n", word);
|
||||
@ -66,8 +64,7 @@ void pword()
|
||||
}
|
||||
|
||||
/* Process a directive */
|
||||
void pdrctv()
|
||||
{
|
||||
void pdrctv(void) {
|
||||
skpchr(); //skip '#'
|
||||
CCMNT('#');
|
||||
getwrd(); //read directive into word
|
||||
@ -87,8 +84,7 @@ void pdrctv()
|
||||
ERROR("Illegal directive %s encountered\n", word, EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void prolog()
|
||||
{
|
||||
void prolog(void) {
|
||||
DEBUG("Writing Assembly Prolog\n", 0);
|
||||
asmlin(CPUOP,CPUARG);
|
||||
setcmt("Program ");
|
||||
@ -96,21 +92,18 @@ void prolog()
|
||||
cmtlin();
|
||||
}
|
||||
|
||||
void epilog()
|
||||
{
|
||||
void epilog(void) {
|
||||
if (!vrwrtn) vartbl(); //Write Variable Table
|
||||
}
|
||||
|
||||
/* Compile Source Code*/
|
||||
void compile()
|
||||
{
|
||||
void compile(void) {
|
||||
DEBUG("Starting Compilation\n", 0);
|
||||
prolog();
|
||||
phdrfl(); //Process Header File specified on Command Line
|
||||
skpchr();
|
||||
DEBUG("Parsing Code\n", 0);
|
||||
while (TRUE)
|
||||
{
|
||||
while (TRUE) {
|
||||
skpspc();
|
||||
//DEBUG("Checking next character '%c'\n", nxtchr);
|
||||
if (match(EOF))
|
||||
@ -130,15 +123,13 @@ void compile()
|
||||
}
|
||||
|
||||
/* Display "Usage" text and exit*/
|
||||
void usage()
|
||||
{
|
||||
void usage(void) {
|
||||
printf("Usage: c02 sourcefile.c02\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* 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 opt; //Option
|
||||
char optarg[32]; //Option Argument
|
||||
@ -166,8 +157,7 @@ int popt(int arg, int argc, char *argv[])
|
||||
/* Parse Command Line Arguments *
|
||||
* Sets: srcnam - Source File Name (from first arg) *
|
||||
* outnam - Output File Name (from optional second arg) */
|
||||
void pargs(int argc, char *argv[])
|
||||
{
|
||||
void pargs(int argc, char *argv[]) {
|
||||
int arg;
|
||||
srcnam[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
|
||||
gencmt = TRUE; //Generate Assembly Language Comments
|
||||
|
||||
|
18
src/common.c
18
src/common.c
@ -11,8 +11,7 @@
|
||||
#include "common.h"
|
||||
|
||||
/* 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);
|
||||
exit(errnum);
|
||||
}
|
||||
@ -20,33 +19,28 @@ void exterr(int errnum)
|
||||
/* Error - print "Expected" error message *
|
||||
and exit with general failure code *
|
||||
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);
|
||||
exterr(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Print current position in file */
|
||||
void prtpos()
|
||||
{
|
||||
void prtpos(void) {
|
||||
printf("(%s: %d,%d) ", inpnam, curlin, curcol);
|
||||
}
|
||||
|
||||
/* Set comment to string */
|
||||
void setcmt(char *s)
|
||||
{
|
||||
void setcmt(char *s) {
|
||||
strcpy(cmtasm, s);
|
||||
}
|
||||
|
||||
/* Append string to comment */
|
||||
void addcmt(char *s)
|
||||
{
|
||||
void addcmt(char *s) {
|
||||
strcat(cmtasm, s);
|
||||
}
|
||||
|
||||
/* Append character to comment */
|
||||
void chrcmt(char c)
|
||||
{
|
||||
void chrcmt(char c) {
|
||||
if (cmtasm[0] == 0 && c == ' ') return;
|
||||
int i = strlen(cmtasm);
|
||||
cmtasm[i++] = c;
|
||||
|
@ -32,7 +32,7 @@
|
||||
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 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)
|
||||
|
||||
|
31
src/cond.c
31
src/cond.c
@ -20,12 +20,10 @@ int cmpenc; //Encoded Comparator Character
|
||||
/* Encode Comparison Operator Character *
|
||||
* Args: Comparison Operator Character *
|
||||
* Returns: Comparison Operator Bit Mask */
|
||||
int enccmp(char c)
|
||||
{
|
||||
int enccmp(char c) {
|
||||
int e;
|
||||
DEBUG("Encoding Comparison Character '%c'\n", c);
|
||||
switch(c)
|
||||
{
|
||||
DEBUG("Encoding Comparison Character '%c'", c);
|
||||
switch(c) {
|
||||
case '=': e = 1; break;
|
||||
case '<': e = 2; break;
|
||||
case '>': e = 4; break;
|
||||
@ -35,7 +33,7 @@ int enccmp(char c)
|
||||
CCMNT(c);
|
||||
skpchr();
|
||||
}
|
||||
DEBUG("Encoded as %d\n", e);
|
||||
DETAIL(", encoded as %d\n", e);
|
||||
return e;
|
||||
}
|
||||
|
||||
@ -43,9 +41,8 @@ int enccmp(char c)
|
||||
* Args: comparator - Encoded Comparison Operator *
|
||||
* Uses: term - Term Being Compared Against *
|
||||
* label - Branch Target if Comparison is FALSE */
|
||||
void prccmp()
|
||||
{
|
||||
DEBUG("Processing comparison operator %d\n", cmprtr);
|
||||
void prccmp(void) {
|
||||
DEBUG("Processing comparitor %d\n", cmprtr);
|
||||
switch(cmprtr) {
|
||||
case 0: // Raw Expression (Skip)
|
||||
asmlin("BEQ", cndlbl);
|
||||
@ -80,14 +77,12 @@ void prccmp()
|
||||
asmlin("BNE", cndlbl);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unsupported comparison operator index %d\n", cmprtr);
|
||||
exterr(EXIT_FAILURE);
|
||||
ERROR("Unsupported comparison operator index %d\n", cmprtr, EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse Comparison */
|
||||
int prscmp(int revrse)
|
||||
{
|
||||
void prscmp(int revrse) {
|
||||
skpspc();
|
||||
cmpenc = enccmp(nxtchr); //Encode Comparison Character
|
||||
cmprtr = cmpenc; //Set Encoded Comparator
|
||||
@ -99,14 +94,13 @@ int prscmp(int revrse)
|
||||
skpspc();
|
||||
if (cmprtr)
|
||||
prstrm();
|
||||
cmprtr = cmprtr ^ revrse & 7;
|
||||
cmprtr = (cmprtr ^ revrse) & 7;
|
||||
prccmp();
|
||||
DEBUG("Parsed comparator %d\n", cmprtr);
|
||||
}
|
||||
|
||||
/* Parse Flag Operator */
|
||||
void prsflg(int revrse)
|
||||
{
|
||||
void prsflg(int revrse) {
|
||||
DEBUG("Parsing Flag Operator '%c'\n", nxtchr);
|
||||
if (match('+'))
|
||||
cmprtr = 0;
|
||||
@ -115,7 +109,7 @@ void prsflg(int revrse)
|
||||
else
|
||||
expctd("Flag operator");
|
||||
skpchr();
|
||||
cmprtr = cmprtr ^ revrse & 1;
|
||||
cmprtr = (cmprtr ^ revrse) & 1;
|
||||
if (cmprtr)
|
||||
asmlin("BPL", cndlbl);
|
||||
else
|
||||
@ -124,8 +118,7 @@ void prsflg(int revrse)
|
||||
|
||||
/* Parse and Compile Conditional Expression *
|
||||
* Condition = <expression> <comparator> <term> */
|
||||
void prscnd(char trmntr, int revrse)
|
||||
{
|
||||
void prscnd(char trmntr, int revrse) {
|
||||
DEBUG("Parsing condition with revrse=%d\n", revrse);
|
||||
if (look('!')) {
|
||||
revrse = (revrse) ? FALSE: TRUE;
|
||||
|
12
src/dclrtn.c
12
src/dclrtn.c
@ -18,8 +18,7 @@
|
||||
#include "dclrtn.h"
|
||||
|
||||
/* Add Function Definition */
|
||||
void addfnc()
|
||||
{
|
||||
void addfnc(void) {
|
||||
expect('(');
|
||||
strcpy(fncnam, word); //Save Function Name
|
||||
prmcnt = 0; //Set Number of Parameters
|
||||
@ -55,8 +54,7 @@ void addfnc()
|
||||
}
|
||||
|
||||
/* (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);
|
||||
while(TRUE) {
|
||||
getwrd();
|
||||
@ -77,8 +75,7 @@ void pdecl(int m, int t)
|
||||
}
|
||||
|
||||
/* Check for and Parse Type Keyword */
|
||||
int ptype(int m)
|
||||
{
|
||||
int ptype(int m) {
|
||||
int result = TRUE;
|
||||
if (wordis("VOID"))
|
||||
pdecl(m, VTVOID); //Parse 'void' declaration
|
||||
@ -91,8 +88,7 @@ int ptype(int m)
|
||||
}
|
||||
|
||||
/* Check for and Parse Modifier */
|
||||
int pmodfr()
|
||||
{
|
||||
int pmodfr(void) {
|
||||
DEBUG("Parsing modifier '%s'\n", word);
|
||||
int result = TRUE;
|
||||
if (wordis("ALIGNED")) {
|
||||
|
36
src/expr.c
36
src/expr.c
@ -17,8 +17,7 @@
|
||||
/* Parse value (constant or identifier) *
|
||||
* Sets: value - the value (as a string) *
|
||||
* valtyp - value type */
|
||||
void prsval(int alwreg)
|
||||
{
|
||||
void prsval(int alwreg) {
|
||||
DEBUG("Parsing value\n", 0);
|
||||
skpspc();
|
||||
if (iscpre())
|
||||
@ -35,8 +34,7 @@ void prsval(int alwreg)
|
||||
/* Parse array index *
|
||||
* Sets: value - array index or *
|
||||
* "" if no index defined */
|
||||
void prsidx()
|
||||
{
|
||||
void prsidx(void) {
|
||||
expect('[');
|
||||
prsval(TRUE);
|
||||
DEBUG("Parsed array index '%s'\n", value);
|
||||
@ -44,8 +42,7 @@ void prsidx()
|
||||
}
|
||||
|
||||
/* Check for, Parse, and Process Index */
|
||||
void chkidx()
|
||||
{
|
||||
void chkidx(void) {
|
||||
//DEBUG("Checking for Array Index with valtyp=%d\n", valtyp);
|
||||
if (valtyp == ARRAY) {
|
||||
prsidx();
|
||||
@ -67,8 +64,7 @@ void chkidx()
|
||||
|
||||
/* Parse Term in Expression *
|
||||
* Sets: term - the term (as a string) */
|
||||
void prstrm()
|
||||
{
|
||||
void prstrm(void) {
|
||||
DEBUG("Parsing term\n", 0);
|
||||
prsval(FALSE);
|
||||
if (valtyp == FUNCTION) {
|
||||
@ -81,8 +77,7 @@ void prstrm()
|
||||
}
|
||||
|
||||
/* Process Address Reference */
|
||||
void prcadr(int adract, char* symbol)
|
||||
{
|
||||
void prcadr(int adract, char* symbol) {
|
||||
DEBUG("Processing address '%s'\n", word);
|
||||
strcpy(word,"#>");
|
||||
strcat(word,symbol);
|
||||
@ -103,8 +98,7 @@ void prcadr(int adract, char* symbol)
|
||||
}
|
||||
|
||||
/* Parse and Compile Address of Operator */
|
||||
void prsadr(int adract)
|
||||
{
|
||||
void prsadr(int adract) {
|
||||
DEBUG("Parsing address\n", 0);
|
||||
if (isnpre())
|
||||
prsnum(0xFFFF);
|
||||
@ -114,8 +108,7 @@ void prsadr(int adract)
|
||||
}
|
||||
|
||||
/* Parse and Create Anonymous String */
|
||||
void prsstr(int adract)
|
||||
{
|
||||
void prsstr(int adract) {
|
||||
DEBUG("Parsing anonymous string\n", 0);
|
||||
newlbl(vrname); //Generate Variable Name
|
||||
value[0] = 0; //Use Variable Size 0
|
||||
@ -127,8 +120,7 @@ void prsstr(int adract)
|
||||
}
|
||||
|
||||
/* Check for and Process Address or String */
|
||||
int chkadr(int adract)
|
||||
{
|
||||
int chkadr(int adract) {
|
||||
DEBUG("Checking for Address or String\n", 0);
|
||||
int result = TRUE;
|
||||
if (look('&'))
|
||||
@ -142,8 +134,7 @@ int chkadr(int adract)
|
||||
}
|
||||
|
||||
/* Parse function call */
|
||||
void prsfnc(char trmntr)
|
||||
{
|
||||
void prsfnc(char trmntr) {
|
||||
DEBUG("Processing Function Call '%s'...\n", term);
|
||||
if (fnscnt >= MAXFNS)
|
||||
ERROR("Maximum Function Call Depth Exceeded", 0, EXIT_FAILURE);
|
||||
@ -175,8 +166,7 @@ void prsfnc(char trmntr)
|
||||
|
||||
/* Parse first term of expession *
|
||||
* First term can include function calls */
|
||||
void prsftm()
|
||||
{
|
||||
void prsftm(void) {
|
||||
prsval(TRUE);
|
||||
DEBUG("Processing first term '%s'...\n", value);
|
||||
strcpy(term, value);
|
||||
@ -198,8 +188,7 @@ void prsftm()
|
||||
|
||||
/* Process Arithmetic or Bitwise Operator *
|
||||
* and the term that follows it */
|
||||
void prcopr()
|
||||
{
|
||||
void prcopr(void) {
|
||||
DEBUG("Processing operator '%c'\n", oper);
|
||||
switch(oper)
|
||||
{
|
||||
@ -229,8 +218,7 @@ void prcopr()
|
||||
}
|
||||
|
||||
/* Parse and compile expression */
|
||||
void prsxpr(char trmntr)
|
||||
{
|
||||
void prsxpr(char trmntr) {
|
||||
DEBUG("Parsing expression\n", 0);
|
||||
skpspc();
|
||||
if (match('-')) {
|
||||
|
22
src/files.c
22
src/files.c
@ -13,8 +13,7 @@
|
||||
|
||||
/* Error - Print textual description of system error *
|
||||
* and exit with system error code */
|
||||
void extsys(char *s)
|
||||
{
|
||||
void extsys(char *s) {
|
||||
perror(s);
|
||||
exterr(errno);
|
||||
}
|
||||
@ -22,8 +21,7 @@ void extsys(char *s)
|
||||
/* Open Source File *
|
||||
* Uses: srcnam - Source File Name *
|
||||
* Sets: srcfil - Source File Handle */
|
||||
void opnsrc()
|
||||
{
|
||||
void opnsrc(void) {
|
||||
DEBUG("Processing Source File Name '%s'\n", srcnam);
|
||||
if (strrchr(srcnam, '.') == NULL) //if no extension
|
||||
strcat(srcnam, ".c02"); // add ".c02"
|
||||
@ -33,16 +31,14 @@ void opnsrc()
|
||||
}
|
||||
|
||||
/* Close Source File */
|
||||
void clssrc()
|
||||
{
|
||||
void clssrc(void) {
|
||||
fclose(srcfil);
|
||||
}
|
||||
|
||||
/* Open Output File *
|
||||
* Uses: outnam - Output File Name *
|
||||
* Sets: outfil - Output File Handle */
|
||||
void opnout()
|
||||
{
|
||||
void opnout(void) {
|
||||
DEBUG("Processing Output File Name '%s'\n", outnam);
|
||||
if (strlen(outnam) == 0) //if Output File not specified
|
||||
{
|
||||
@ -59,8 +55,7 @@ void opnout()
|
||||
}
|
||||
|
||||
/* Close Output File */
|
||||
void clsout()
|
||||
{
|
||||
void clsout(void) {
|
||||
fprintf(outfil, "\n");
|
||||
fclose(outfil);
|
||||
}
|
||||
@ -68,8 +63,7 @@ void clsout()
|
||||
/* Open Log File *
|
||||
* Uses: srcnam - Source File Name *
|
||||
* Sets: logfil - Log File Handle */
|
||||
void opnlog()
|
||||
{
|
||||
void opnlog(void) {
|
||||
strcpy(lognam, srcnam); //set Log File Name to Source File Name
|
||||
char *dot = strrchr(lognam, '.'); //find file extension
|
||||
if (dot != NULL) *dot = 0; //and remove it
|
||||
@ -81,14 +75,14 @@ void opnlog()
|
||||
|
||||
/* Close Log File *
|
||||
* Uses: logfil - Log File Handle */
|
||||
void clslog() {
|
||||
void clslog(void) {
|
||||
fclose(logfil);
|
||||
}
|
||||
|
||||
/* Open Include file *
|
||||
* Uses: incnam - Include File Name *
|
||||
* Sets: incfil - Include File Handle */
|
||||
void opninc()
|
||||
void opninc(void)
|
||||
{
|
||||
DEBUG("Opening include file '%s'\n", incnam);
|
||||
incfil = fopen(incnam, "r");
|
||||
|
@ -20,8 +20,7 @@
|
||||
|
||||
/* Read next include file name from Source File *
|
||||
* Sets: incnam - the include file name */
|
||||
void pincnm()
|
||||
{
|
||||
void pincnm(void) {
|
||||
char dlmtr;
|
||||
int inclen = 0;
|
||||
skpspc();
|
||||
@ -43,7 +42,7 @@ void pincnm()
|
||||
}
|
||||
|
||||
/* Process assembly language include file */
|
||||
void incasm() {
|
||||
void incasm(void) {
|
||||
opninc();
|
||||
setcmt("======== Assembler File ");
|
||||
addcmt(incnam);
|
||||
@ -59,8 +58,7 @@ void incasm() {
|
||||
}
|
||||
|
||||
/* Process define directive */
|
||||
void pdefin()
|
||||
{
|
||||
void pdefin(void) {
|
||||
getwrd(); //get defined identifier
|
||||
DEBUG("Defining '%s'\n", word);
|
||||
strncpy(defnam[defcnt], word, VARLEN);
|
||||
@ -73,8 +71,7 @@ void pdefin()
|
||||
}
|
||||
|
||||
/* Process enum directive */
|
||||
void penumd()
|
||||
{
|
||||
void penumd(void) {
|
||||
int enmval = 0;
|
||||
do {
|
||||
getwrd(); //get defined identifier
|
||||
@ -90,8 +87,7 @@ void penumd()
|
||||
}
|
||||
|
||||
/* Parse ASCII Subdirective */
|
||||
void pascii()
|
||||
{
|
||||
void pascii(void) {
|
||||
getwrd(); //Get Pragma Subdirective
|
||||
if (wordis("INVERT"))
|
||||
invasc = TRUE;
|
||||
@ -104,23 +100,20 @@ void pascii()
|
||||
}
|
||||
|
||||
/* Parse Origin Subdirective */
|
||||
void porign()
|
||||
{
|
||||
void porign(void) {
|
||||
prsnum(0xFFFF); //Get Origin Address
|
||||
asmlin(ORGOP, value); //Emit Origin Instruction
|
||||
DEBUG("Set origin to %s\n", value);
|
||||
}
|
||||
|
||||
/* Parse Zeropage Subdirective */
|
||||
void prszpg()
|
||||
{
|
||||
void prszpg(void) {
|
||||
zpaddr = prsnum(0xFF); //Set Zero Page Address to Constant
|
||||
DEBUG("Set zero page address to %d\n", zpaddr);
|
||||
}
|
||||
|
||||
/* Process Vartable Subdirective */
|
||||
void pvrtbl()
|
||||
{
|
||||
void pvrtbl(void) {
|
||||
if (vrwrtn) {
|
||||
ERROR("Variable table already written", 0, EXIT_FAILURE);
|
||||
}
|
||||
@ -128,8 +121,7 @@ void pvrtbl()
|
||||
}
|
||||
|
||||
/* Parse Pragma Directive */
|
||||
void pprgma()
|
||||
{
|
||||
void pprgma(void) {
|
||||
getwrd(); //Get Pragma Subdirective
|
||||
DEBUG("Parsing pragma directive '%s'\n", word);
|
||||
if (wordis("ASCII"))
|
||||
@ -145,8 +137,7 @@ void pprgma()
|
||||
}
|
||||
|
||||
/* Process Include File Directive */
|
||||
void pincdr()
|
||||
{
|
||||
void pincdr(void) {
|
||||
skpchr(); //skip '#'
|
||||
getwrd(); //read directive into word
|
||||
DEBUG("Processing include file directive '%s'\n", word);
|
||||
@ -161,7 +152,7 @@ void pincdr()
|
||||
}
|
||||
|
||||
/* Parse Header Word */
|
||||
void phdwrd() {
|
||||
void phdwrd(void) {
|
||||
getwrd();
|
||||
if (!ptype(MTNONE)) {
|
||||
fprintf(stderr, "Unexpected word '%s' in header\n", word);
|
||||
@ -170,14 +161,14 @@ void phdwrd() {
|
||||
}
|
||||
|
||||
/* Save Source File Information */
|
||||
void savsrc() {
|
||||
void savsrc(void) {
|
||||
savchr = nxtchr;
|
||||
savcol = curcol;
|
||||
savlin = curlin;
|
||||
}
|
||||
|
||||
/* Set Include File Information */
|
||||
void setinc() {
|
||||
void setinc(void) {
|
||||
curcol = 0;
|
||||
curlin = 0;
|
||||
inpfil = incfil;
|
||||
@ -193,13 +184,13 @@ void setinm(char* filext) {
|
||||
}
|
||||
|
||||
/* Set Input to Source File */
|
||||
void setsrc() {
|
||||
void setsrc(void) {
|
||||
inpfil = srcfil;
|
||||
strcpy(inpnam, srcnam);
|
||||
}
|
||||
|
||||
/* Restore Source File Pointer*/
|
||||
void rstsrc() {
|
||||
void rstsrc(void) {
|
||||
nxtchr = savchr;
|
||||
nxtupc = toupper(nxtchr);
|
||||
curcol = savcol;
|
||||
@ -209,7 +200,7 @@ void rstsrc() {
|
||||
}
|
||||
|
||||
/* Process header include file */
|
||||
void inchdr() {
|
||||
void inchdr(void) {
|
||||
savsrc(); //Save Source File Information
|
||||
opninc(); //Open Include File
|
||||
setinc(); //Set Include File Information
|
||||
@ -236,8 +227,7 @@ void inchdr() {
|
||||
}
|
||||
|
||||
/* Process Header File specified on Command Line */
|
||||
void phdrfl()
|
||||
{
|
||||
void phdrfl(void) {
|
||||
if (hdrnam[0] == 0) return;
|
||||
DEBUG("Processing Header '%s'\n", hdrnam);
|
||||
setinm(".h02");
|
||||
@ -247,8 +237,7 @@ void phdrfl()
|
||||
}
|
||||
|
||||
/* Process include file */
|
||||
void pincfl()
|
||||
{
|
||||
void pincfl(void) {
|
||||
pincnm(); //Parse Include File Name
|
||||
DEBUG("Processing include file '%s'\n", incnam);
|
||||
char *dot = strrchr(incnam, '.'); //find extension
|
||||
@ -272,8 +261,7 @@ void pincfl()
|
||||
}
|
||||
|
||||
/* Print Definition Table to Log File */
|
||||
void logdef()
|
||||
{
|
||||
void logdef(void) {
|
||||
int i;
|
||||
fprintf(logfil, "\n%-31s %5s\n", "Definition", "Value");
|
||||
for (i=0; i<defcnt; i++)
|
||||
|
30
src/label.c
30
src/label.c
@ -21,8 +21,7 @@ const char lblflg[] = {LFNONE, LFNONE, LFBGN, LFEND, LFBGN, LFEND, LFEND, LFNONE
|
||||
* Sets: tmplbl - Label name *
|
||||
* Returns: Index into label table *
|
||||
* (-1 if not found) */
|
||||
int lstlbl(int lbflag)
|
||||
{
|
||||
int lstlbl(int lbflag) {
|
||||
int i;
|
||||
DEBUG("Searching for label flag %d\n", lbflag);
|
||||
for (i = lblcnt - 1; i>-1; i--) {
|
||||
@ -36,16 +35,14 @@ int lstlbl(int lbflag)
|
||||
}
|
||||
|
||||
/* Set Block Flag for Last Label */
|
||||
void setblk(int blkflg)
|
||||
{
|
||||
void setblk(int blkflg) {
|
||||
lblblk[lblcnt-1] = blkflg;
|
||||
}
|
||||
|
||||
/* Set label for next line of *
|
||||
* Assembly Language Code *
|
||||
* to word */
|
||||
void setlbl(char *lblset)
|
||||
{
|
||||
void setlbl(char *lblset) {
|
||||
DEBUG("Setting Label '%s'\n", lblset);
|
||||
if (strlen(lblasm) > 0) {
|
||||
DEBUG("Emitting Label '%s'\n'", lblasm);
|
||||
@ -57,8 +54,7 @@ void setlbl(char *lblset)
|
||||
}
|
||||
|
||||
/* parse label in code */
|
||||
void prslbl()
|
||||
{
|
||||
void prslbl(void) {
|
||||
DEBUG("Parsing Label '%s''\n", word);
|
||||
CCMNT(nxtchr);
|
||||
skpchr(); //skip ':'
|
||||
@ -66,8 +62,7 @@ void prslbl()
|
||||
}
|
||||
|
||||
/* generate new label */
|
||||
void newlbl(char* lbname)
|
||||
{
|
||||
void newlbl(char* lbname) {
|
||||
sprintf(lbname, LABFMT, lblnxt++);
|
||||
DEBUG("Generated new label '%s'\n", lbname);
|
||||
}
|
||||
@ -75,8 +70,7 @@ void newlbl(char* lbname)
|
||||
/* Check Label Contents *
|
||||
* If lbname is blank, generate new *
|
||||
* label and copy into lbname */
|
||||
void chklbl(char* lbname)
|
||||
{
|
||||
void chklbl(char* lbname) {
|
||||
if (lbname[0]) return;
|
||||
newlbl(lbname);
|
||||
}
|
||||
@ -84,8 +78,7 @@ void chklbl(char* lbname)
|
||||
/* Require Label *
|
||||
* if label is already set, returns that label *
|
||||
* else generates new label and sets it */
|
||||
void reqlbl(char* lbname)
|
||||
{
|
||||
void reqlbl(char* lbname) {
|
||||
if (lblasm[0])
|
||||
strcpy(lbname, lblasm);
|
||||
else {
|
||||
@ -95,8 +88,7 @@ void reqlbl(char* lbname)
|
||||
}
|
||||
|
||||
/* Pop Label from Stack and Emit on Next Line */
|
||||
int poplbl()
|
||||
{
|
||||
int poplbl(void) {
|
||||
int lbtype = lbltyp[--lblcnt];
|
||||
DEBUG("Popped label type %d\n", lbtype);
|
||||
if (lbtype == LTLOOP)
|
||||
@ -119,8 +111,7 @@ int poplbl()
|
||||
}
|
||||
|
||||
/* Get Top Label and Return Type */
|
||||
int toplbl(char *rtlbl)
|
||||
{
|
||||
int toplbl(char *rtlbl) {
|
||||
if (lblcnt) {
|
||||
strcpy(rtlbl, lblnam[lblcnt-1]);
|
||||
DEBUG("Found top label %s\n", rtlbl);
|
||||
@ -133,8 +124,7 @@ int toplbl(char *rtlbl)
|
||||
/* Push Label onto Stack *
|
||||
* Args: lbltyp - Label type *
|
||||
* Uses: curlbl - Label to push */
|
||||
void pshlbl(int lbtype, char* lbname)
|
||||
{
|
||||
void pshlbl(int lbtype, char* lbname) {
|
||||
DEBUG("Pushing label type %d\n", lbtype);
|
||||
strcpy(lblnam[lblcnt], lbname);
|
||||
lbltyp[lblcnt] = lbtype;
|
||||
|
115
src/parse.c
115
src/parse.c
@ -16,23 +16,23 @@
|
||||
/* Various tests against nxtchr */
|
||||
int match(char c) {return TF(nxtchr == c);}
|
||||
int inbtwn(char mn, char mx) {return TF(nxtchr >= mn && nxtchr <= mx);}
|
||||
int isalph() {return isalpha(nxtchr);}
|
||||
int isanum() {return isalnum(nxtchr);}
|
||||
int isapos() {return match('\'');}
|
||||
int isbin() {return inbtwn('0', '1');}
|
||||
int isbpre() {return TF(isnpre() || isapos());}
|
||||
int iscpre() {return TF(isbpre() || ishash());}
|
||||
int isdec() {return inbtwn('0', '9');}
|
||||
int ishash() {return match('#');}
|
||||
int ishexd() {return TF(isdec() || inbtwn('A', 'Z'));}
|
||||
int isnl() {return TF(match('\n') || match('\r'));}
|
||||
int isnpre() {return TF(isdec() || match('$') || match('%'));}
|
||||
int isoper() {return TF(strchr("+-&|^", nxtchr));}
|
||||
int ispopr() {return TF(strchr("+-<>", nxtchr));}
|
||||
int isprnt() {return isprint(nxtchr);}
|
||||
int isspc() {return isspace(nxtchr);}
|
||||
int isvpre() {return TF(isalph() || iscpre());}
|
||||
int isxpre() {return TF(isvpre() || match('-'));}
|
||||
int isalph(void) {return isalpha(nxtchr);}
|
||||
int isanum(void) {return isalnum(nxtchr);}
|
||||
int isapos(void) {return match('\'');}
|
||||
int isbin(void) {return inbtwn('0', '1');}
|
||||
int isbpre(void) {return TF(isnpre() || isapos());}
|
||||
int iscpre(void) {return TF(isbpre() || ishash());}
|
||||
int isdec(void) {return inbtwn('0', '9');}
|
||||
int ishash(void) {return match('#');}
|
||||
int ishexd(void) {return TF(isdec() || inbtwn('A', 'Z'));}
|
||||
int isnl(void) {return TF(match('\n') || match('\r'));}
|
||||
int isnpre(void) {return TF(isdec() || match('$') || match('%'));}
|
||||
int isoper(void) {return TF(strchr("+-&|^", nxtchr));}
|
||||
int ispopr(void) {return TF(strchr("+-<>", nxtchr));}
|
||||
int isprnt(void) {return isprint(nxtchr);}
|
||||
int isspc(void) {return isspace(nxtchr);}
|
||||
int isvpre(void) {return TF(isalph() || iscpre());}
|
||||
int isxpre(void) {return TF(isvpre() || match('-'));}
|
||||
|
||||
/* Process ASCII Character */
|
||||
char prcchr(char c) {
|
||||
@ -43,17 +43,14 @@ char prcchr(char c) {
|
||||
}
|
||||
|
||||
/* if Word is s then return TRUE else return FALSE*/
|
||||
int wordis(char *s)
|
||||
{
|
||||
int wordis(char *s) {
|
||||
return strcmp(word, s) == 0;
|
||||
}
|
||||
|
||||
/* Get Next Character from Current Input File *
|
||||
* Uses: inpfil - Input File Handle *
|
||||
* Sets: nxtchr - Next Character in Source File */
|
||||
char getnxt()
|
||||
{
|
||||
int i;
|
||||
char getnxt(void) {
|
||||
int wascr = match('\r');
|
||||
char c = nxtchr;
|
||||
//if (nxtwrd[nxtptr]) //If nxtwrd is set
|
||||
@ -68,8 +65,7 @@ char getnxt()
|
||||
}
|
||||
|
||||
/* Advance Input File to next printable character */
|
||||
void skpspc()
|
||||
{
|
||||
void skpspc(void) {
|
||||
//DEBUG("Skipping Spaces\n", 0);
|
||||
if (isspc()) CCMNT(' '); //Add only the first space to comments
|
||||
while (isspc())
|
||||
@ -80,8 +76,7 @@ void skpspc()
|
||||
* and advance past it if it is *
|
||||
* Returns TRUE is character is found, *
|
||||
* otherwise FALSE */
|
||||
int look(char c)
|
||||
{
|
||||
int look(char c) {
|
||||
int found;
|
||||
skpspc();
|
||||
found = match(c);
|
||||
@ -93,8 +88,7 @@ int look(char c)
|
||||
}
|
||||
|
||||
/* if next printable character is c then skip, else generate error */
|
||||
void expect(char c)
|
||||
{
|
||||
void expect(char c) {
|
||||
if (c == 0) return;
|
||||
if (look(c)) return;
|
||||
else {
|
||||
@ -104,14 +98,17 @@ void expect(char c)
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
void skpeol() {while (!isnl()) getnxt();}
|
||||
void skpeol(void) {while (!isnl()) getnxt();}
|
||||
|
||||
/* Advance Source File to end of comment *
|
||||
* Recognizes both C and C++ style comments */
|
||||
void skpcmt()
|
||||
void skpcmt(void)
|
||||
{
|
||||
DEBUG("Skipping Comment\n", 0);
|
||||
skpchr(); //skip initial /
|
||||
@ -135,8 +132,7 @@ void skpcmt()
|
||||
/* Reads next Word in current Input File, where *
|
||||
* a Word is a sequence of AlphaNumeric characters *
|
||||
* Sets: word - the Word read from the source file */
|
||||
void getwrd()
|
||||
{
|
||||
void getwrd(void) {
|
||||
int wrdlen = 0;
|
||||
skpspc();
|
||||
if (!isalph()) expctd("Alphabetic Character");
|
||||
@ -149,8 +145,7 @@ void getwrd()
|
||||
}
|
||||
|
||||
/* Escape Character */
|
||||
char escape(char c)
|
||||
{
|
||||
char escape(char c) {
|
||||
DEBUG("Escaping character '%c'\n", c);
|
||||
switch (c) {
|
||||
case 'r': return 0x0d;
|
||||
@ -159,8 +154,8 @@ char escape(char c)
|
||||
}
|
||||
|
||||
/* Get String */
|
||||
void getstr() {
|
||||
char strdel, tmpchr;
|
||||
void getstr(void) {
|
||||
char strdel;
|
||||
int wrdlen = 0, escnxt = FALSE;
|
||||
DEBUG("Parsing string\n", 0);
|
||||
strdel = getnxt(); //Get String Delimiter
|
||||
@ -189,8 +184,7 @@ void getstr() {
|
||||
* prefixed with '%' *
|
||||
* Sets: word - binary number including leading '%' *
|
||||
* Returns: integer value of number */
|
||||
int prsbin()
|
||||
{
|
||||
int prsbin(void) {
|
||||
int wrdlen = 0;
|
||||
int digit;
|
||||
int number = 0;
|
||||
@ -212,8 +206,7 @@ int prsbin()
|
||||
* a Decimal is a series of digits (0-9) *
|
||||
* Sets: word - number without leading 0's *
|
||||
* Returns: integer value of number */
|
||||
int prsdec()
|
||||
{
|
||||
int prsdec(void) {
|
||||
int wrdlen = 0;
|
||||
int digit;
|
||||
int number = 0;
|
||||
@ -233,8 +226,7 @@ int prsdec()
|
||||
/* Reads Hexadecimal number from input file *
|
||||
* Sets: word - Hex number including leading '$' *
|
||||
* Returns: integer value of number */
|
||||
int prshex()
|
||||
{
|
||||
int prshex(void) {
|
||||
int wrdlen = 0;
|
||||
int digit;
|
||||
int number = 0;
|
||||
@ -261,8 +253,7 @@ int prshex()
|
||||
* Sets: word - Character constant including *
|
||||
* single quotes *
|
||||
* Returns: ASCII value of constant */
|
||||
int prschr()
|
||||
{
|
||||
int prschr(void) {
|
||||
int wrdlen = 0;
|
||||
char c;
|
||||
DEBUG("Parsing character constant\n", 0);
|
||||
@ -284,8 +275,7 @@ int prschr()
|
||||
* Sets: value - parsed number (as string) *
|
||||
* word - parses text of value *
|
||||
* Returns: parsed number */
|
||||
int prsnum(int maxval)
|
||||
{
|
||||
int prsnum(int maxval) {
|
||||
int number;
|
||||
skpspc();
|
||||
if (!isbpre()) expctd("constant value");
|
||||
@ -316,14 +306,10 @@ int prsnum(int maxval)
|
||||
}
|
||||
|
||||
/* Parse Nuneric Byte Value */
|
||||
int prsbyt()
|
||||
{
|
||||
return prsnum(0xFF);
|
||||
}
|
||||
int prsbyt(void) {return prsnum(0xFF);}
|
||||
|
||||
/* Find Defined Constant */
|
||||
void fnddef(char *name)
|
||||
{
|
||||
void fnddef(char *name) {
|
||||
DEBUG("Looking up defined constant '%s'\n", word);
|
||||
for (defidx=0; defidx<defcnt; defidx++) {
|
||||
if (strcmp(defnam[defidx], name) == 0)
|
||||
@ -333,8 +319,7 @@ void fnddef(char *name)
|
||||
}
|
||||
|
||||
/* Parse Definition */
|
||||
int prsdef()
|
||||
{
|
||||
int prsdef(void) {
|
||||
expect('#');
|
||||
getwrd(); //Get Constant Name
|
||||
fnddef(word);
|
||||
@ -354,8 +339,7 @@ int prsdef()
|
||||
* Note: Value is converted to hexadecimal *
|
||||
* because DASM uses the format 'c for *
|
||||
* character arguments instead of 'c' */
|
||||
void prscon()
|
||||
{
|
||||
void prscon(void) {
|
||||
skpspc();
|
||||
if (ishash())
|
||||
cnstnt = prsdef();
|
||||
@ -369,17 +353,15 @@ void prscon()
|
||||
}
|
||||
|
||||
/* Get Value Type */
|
||||
int gettyp()
|
||||
{
|
||||
int gettyp(void) {
|
||||
if (match('(')) return FUNCTION;
|
||||
else if (match('[')) return ARRAY;
|
||||
else return VARIABLE;
|
||||
}
|
||||
|
||||
/* Parse arithmetic or bitwise operator */
|
||||
void prsopr()
|
||||
{
|
||||
if (!isoper)
|
||||
void prsopr(void) {
|
||||
if (!isoper())
|
||||
expctd("Arithmetic or bitwise operator");
|
||||
oper = getnxt();
|
||||
DEBUG("Parsed operator '%c'\n", oper);
|
||||
@ -389,22 +371,19 @@ void prsopr()
|
||||
|
||||
|
||||
/* 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);
|
||||
exterr(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Process Post Operator */
|
||||
void prcpst(char* name, char *index)
|
||||
{
|
||||
void prcpst(char* name, char *index) {
|
||||
DEBUG("Processing post operation '%c'\n", oper);
|
||||
if (strlen(index)) {
|
||||
asmlin("LDX", index);
|
||||
strcat(name,",X");
|
||||
}
|
||||
switch(oper)
|
||||
{
|
||||
switch(oper) {
|
||||
case '+':
|
||||
if (strcmp(name, "X")==0)
|
||||
asmlin("INX", "");
|
||||
|
71
src/stmnt.c
71
src/stmnt.c
@ -18,8 +18,7 @@
|
||||
#include "stmnt.h"
|
||||
|
||||
/* Begin Program Block */
|
||||
void bgnblk(char blkchr)
|
||||
{
|
||||
void bgnblk(char blkchr) {
|
||||
DEBUG("Begining program block\n", 0);
|
||||
if (blkchr) {
|
||||
expect(blkchr);
|
||||
@ -33,8 +32,7 @@ void bgnblk(char blkchr)
|
||||
|
||||
/* End Program Block *
|
||||
* Args: blkflg: End of Multiline Block */
|
||||
void endblk(int blkflg)
|
||||
{
|
||||
void endblk(int blkflg) {
|
||||
int lbtype;
|
||||
DEBUG("Ending program block with flag %d\n", blkflg);
|
||||
expect('}'); //Block End Character
|
||||
@ -75,8 +73,7 @@ void prcidx(int idxtyp, char *name, char *index)
|
||||
}
|
||||
|
||||
/* Process Assignment */
|
||||
void prcasn(char trmntr)
|
||||
{
|
||||
void prcasn(char trmntr) {
|
||||
expect('=');
|
||||
if (look('('))
|
||||
prssif(trmntr); //Parse Shortcut If
|
||||
@ -108,8 +105,7 @@ void prcasn(char trmntr)
|
||||
}
|
||||
|
||||
/* Parse and Return Array Index and Type */
|
||||
int getidx(char* idx)
|
||||
{
|
||||
int getidx(char* idx) {
|
||||
prsidx(); //Parse Array Index
|
||||
if (valtyp == CONSTANT)
|
||||
strncpy(idx, word, VARLEN);
|
||||
@ -120,8 +116,7 @@ int getidx(char* idx)
|
||||
}
|
||||
|
||||
/* Process Assignment Variable(s) */
|
||||
void prcvar(char trmntr)
|
||||
{
|
||||
void prcvar(char trmntr) {
|
||||
chksym(TRUE, word);
|
||||
strcpy(asnvar, word); //save variable to assign to
|
||||
asntyp = valtyp; //Set Assigned Varable Type
|
||||
@ -171,8 +166,7 @@ void prcvar(char trmntr)
|
||||
}
|
||||
|
||||
/* Parse 'asm' String Parameter */
|
||||
void pasmst(char trmntr)
|
||||
{
|
||||
void pasmst(char trmntr) {
|
||||
skpspc(); //Skip Spaces
|
||||
if (!match('"'))
|
||||
expctd("string");
|
||||
@ -182,8 +176,7 @@ void pasmst(char trmntr)
|
||||
}
|
||||
|
||||
/* Parse and Compile 'asm' statement */
|
||||
void pasm()
|
||||
{
|
||||
void pasm(void) {
|
||||
char opcode[LINELEN];
|
||||
expect('(');
|
||||
pasmst(',');
|
||||
@ -196,8 +189,7 @@ void pasm()
|
||||
}
|
||||
|
||||
/* Parse and Compile an Assignment */
|
||||
void prsasn(char trmntr)
|
||||
{
|
||||
void prsasn(char trmntr) {
|
||||
getwrd(); //Get Variable to be Assigned
|
||||
prcvar(trmntr);
|
||||
}
|
||||
@ -214,8 +206,7 @@ void pbrcnt(int lbflag)
|
||||
}
|
||||
|
||||
/* parse and compile 'do' statement */
|
||||
void pdo()
|
||||
{
|
||||
void pdo(void) {
|
||||
DEBUG("Parsing DO statement '%c'\n", nxtchr);
|
||||
newlbl(endlbl); //Create End Label
|
||||
pshlbl(LTDWHL, endlbl); //and Push onto Stack
|
||||
@ -227,7 +218,7 @@ void pdo()
|
||||
}
|
||||
|
||||
/* parse and compile 'while' after 'do' statement */
|
||||
void pdowhl() {
|
||||
void pdowhl(void) {
|
||||
DEBUG("Parsing WHILE after DO '%c'\n", nxtchr);
|
||||
getwrd(); //Check for While
|
||||
if (!wordis("WHILE"))
|
||||
@ -245,7 +236,7 @@ void pdowhl() {
|
||||
|
||||
|
||||
/* parse and compile for statement */
|
||||
void pfor() {
|
||||
void pfor(void) {
|
||||
DEBUG("Parsing FOR statement '%c'\n", nxtchr);
|
||||
expect('(');
|
||||
prsasn(';'); //Process Initial Assignment
|
||||
@ -266,7 +257,7 @@ void pfor() {
|
||||
}
|
||||
|
||||
/* parse and compile if statement */
|
||||
void pif() {
|
||||
void pif(void) {
|
||||
DEBUG("Parsing IF statement\n", 0);
|
||||
expect('(');
|
||||
newlbl(cndlbl); //Create New Label
|
||||
@ -276,7 +267,7 @@ void pif() {
|
||||
}
|
||||
|
||||
/* parse and compile else statement */
|
||||
void pelse() {
|
||||
void pelse(void) {
|
||||
DEBUG("Parsing ELSE statement\n", 0);
|
||||
strcpy(lbltmp, lblasm); //Save Line Label
|
||||
lblasm[0] = 0; //and Clear It
|
||||
@ -288,7 +279,7 @@ void pelse() {
|
||||
}
|
||||
|
||||
/* parse and compile if statement */
|
||||
void pgoto() {
|
||||
void pgoto(void) {
|
||||
DEBUG("Parsing GOTO statement\n", 0);
|
||||
getwrd();
|
||||
expect(';');
|
||||
@ -296,8 +287,7 @@ void pgoto() {
|
||||
}
|
||||
|
||||
/* parse and compile inline statement */
|
||||
void pinlne()
|
||||
{
|
||||
void pinlne(void) {
|
||||
DEBUG("Parsing INLINE statement\n", 0);
|
||||
do {
|
||||
DEBUG("Parsing inline parameter\n", 0);
|
||||
@ -331,8 +321,7 @@ void pinlne()
|
||||
}
|
||||
|
||||
/* parse and compile pop statement */
|
||||
void ppop()
|
||||
{
|
||||
void ppop(void) {
|
||||
DEBUG("Parsing POP statement\n", 0);
|
||||
do {
|
||||
asmlin("PLA", ""); //Pop Value off Stack
|
||||
@ -347,8 +336,7 @@ void ppop()
|
||||
}
|
||||
|
||||
/* parse and compile push statement */
|
||||
void ppush()
|
||||
{
|
||||
void ppush(void) {
|
||||
DEBUG("Parsing PUSH statement\n", 0);
|
||||
do {
|
||||
if (!chkadr(1)) {
|
||||
@ -360,7 +348,7 @@ void ppush()
|
||||
}
|
||||
|
||||
/* parse and compile return statement */
|
||||
void pretrn() {
|
||||
void pretrn(void) {
|
||||
DEBUG("Parsing RETURN statement\n", 0);
|
||||
if (!look(';'))
|
||||
prsxpr(';');
|
||||
@ -369,7 +357,7 @@ void pretrn() {
|
||||
}
|
||||
|
||||
/* parse and compile select statement */
|
||||
void pslct() {
|
||||
void pslct(void) {
|
||||
DEBUG("Parsing SELECT statement\n", 0);
|
||||
expect('(');
|
||||
prsxpr(')'); //Parse Expression
|
||||
@ -381,7 +369,7 @@ void pslct() {
|
||||
}
|
||||
|
||||
/* process end of case block */
|
||||
void ecase() {
|
||||
void ecase(void) {
|
||||
DEBUG("Processing end of CASE block\n", 0);
|
||||
if (poplbl(cndlbl) != LTCASE)
|
||||
ERROR("%s not at end of CASE block\n", word, EXIT_FAILURE);
|
||||
@ -392,9 +380,9 @@ void ecase() {
|
||||
}
|
||||
|
||||
/* parse and compile select statement */
|
||||
void pcase() {
|
||||
void pcase(void) {
|
||||
if (!fcase)
|
||||
ecase("CASE"); //Process end of case block
|
||||
ecase(); //Process end of case block
|
||||
skplbl[0] = 0; //Clear Skip Label
|
||||
newlbl(cndlbl); //Create Conditional Label
|
||||
pshlbl(LTCASE, cndlbl); //and Push onto Stack
|
||||
@ -418,13 +406,13 @@ void pcase() {
|
||||
}
|
||||
|
||||
/* parse and compile default statement */
|
||||
void pdflt() {
|
||||
void pdflt(void) {
|
||||
expect(':');
|
||||
ecase(); //Process end of case block
|
||||
}
|
||||
|
||||
/* parse and compile while statement */
|
||||
void pwhile() {
|
||||
void pwhile(void) {
|
||||
DEBUG("Parsing WHILE statement '%c'\n", nxtchr);
|
||||
expect('(');
|
||||
newlbl(endlbl); //Create End Label
|
||||
@ -443,21 +431,19 @@ void pwhile() {
|
||||
}
|
||||
|
||||
/* generate unimplemented statement error */
|
||||
void punimp() {
|
||||
void punimp(void) {
|
||||
ERROR("Unimplemented statement '%s' encountered\n", word, EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Parse Function Call as Statement */
|
||||
void prsfns()
|
||||
{
|
||||
void prsfns(void) {
|
||||
strcpy(term, word); //Copy Function Name
|
||||
prsfnc(';'); //Parse Function Call
|
||||
return;
|
||||
}
|
||||
|
||||
/* parse and compile identifier (variable or function call) */
|
||||
void prssym()
|
||||
{
|
||||
void prssym(void) {
|
||||
DEBUG("Parsing Identifier %s\n", word);
|
||||
valtyp = gettyp();
|
||||
if (valtyp == FUNCTION)
|
||||
@ -467,8 +453,7 @@ void prssym()
|
||||
}
|
||||
|
||||
/* parse and compile program statement */
|
||||
void pstmnt()
|
||||
{
|
||||
void pstmnt(void) {
|
||||
DEBUG("Parsing statement '%s'\n", word);
|
||||
if (wordis("DO")) {
|
||||
pdo();
|
||||
|
33
src/vars.c
33
src/vars.c
@ -19,8 +19,7 @@
|
||||
* Sets: varidx = index into varnam array *
|
||||
* varcnt if not found *
|
||||
* Returns: TRUE if found, otherwise FALSE */
|
||||
int fndvar(char *name)
|
||||
{
|
||||
int fndvar(char *name) {
|
||||
DEBUG("Looking up variable '%s'\n", word);
|
||||
for (varidx=0; varidx<varcnt; varidx++) {
|
||||
if (strcmp(varnam[varidx], name) == 0)
|
||||
@ -33,8 +32,7 @@ int fndvar(char *name)
|
||||
* Generates error if variable is undefined *
|
||||
* Args: alwreg - allow register 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 (alwreg && valtyp != ARRAY) {
|
||||
valtyp = REGISTER;
|
||||
@ -50,8 +48,7 @@ void chksym(int alwreg, char *name)
|
||||
* Args: alwreg - Allow Register Names *
|
||||
* Sets: value - Identifier Name *
|
||||
* valtyp - Identifier Type */
|
||||
void prsvar(int alwreg)
|
||||
{
|
||||
void prsvar(int alwreg) {
|
||||
getwrd();
|
||||
valtyp = gettyp();
|
||||
if (valtyp != FUNCTION) chksym(alwreg, word);
|
||||
@ -62,8 +59,7 @@ void prsvar(int alwreg)
|
||||
/* Require and Parse Variable Name *
|
||||
* Parameters: alwary - Allow Array Reference *
|
||||
* Sets: vrname - operand for LDA/STA/LDY/STY */
|
||||
void reqvar(int alwary)
|
||||
{
|
||||
void reqvar(int alwary) {
|
||||
prsvar(FALSE);
|
||||
if (!alwary)
|
||||
if (valtyp != VARIABLE)
|
||||
@ -71,8 +67,7 @@ void reqvar(int alwary)
|
||||
}
|
||||
|
||||
/* Parse Data Array */
|
||||
void prsdta()
|
||||
{
|
||||
void prsdta(void) {
|
||||
dtype = DTARRY;
|
||||
expect('{');
|
||||
dlen = 0;
|
||||
@ -86,8 +81,7 @@ void prsdta()
|
||||
}
|
||||
|
||||
/* Parse Data String */
|
||||
void prsdts()
|
||||
{
|
||||
void prsdts(void) {
|
||||
dtype = DTSTR;
|
||||
getstr();
|
||||
strcpy(value, word);
|
||||
@ -98,8 +92,7 @@ void prsdts()
|
||||
* Uses: value - Data to store *
|
||||
* Sets: datvar[] - Variable Data *
|
||||
* datlen[] - Data Length */
|
||||
void setdat()
|
||||
{
|
||||
void setdat(void) {
|
||||
int i;
|
||||
if (dtype == DTBYTE) {
|
||||
DEBUG("Setting variable data to '%d'\n", cnstnt);
|
||||
@ -123,8 +116,7 @@ void setdat()
|
||||
}
|
||||
|
||||
/* Parse and store variable data */
|
||||
void prsdat()
|
||||
{
|
||||
void prsdat(void) {
|
||||
DEBUG("Checking for variable data\n", 0);
|
||||
if (!look('=')) {
|
||||
datlen[varcnt] = 0;
|
||||
@ -147,8 +139,7 @@ void prsdat()
|
||||
/* Add Variable to Variable table *
|
||||
* Uses: word - variable name *
|
||||
* value - variable size */
|
||||
void setvar(int m, int t)
|
||||
{
|
||||
void setvar(int m, int t) {
|
||||
DEBUG("Added variable '%s' ", word);
|
||||
strncpy(varnam[varcnt], vrname, VARLEN);
|
||||
varmod[varcnt] = m;
|
||||
@ -159,8 +150,7 @@ void setvar(int m, int t)
|
||||
|
||||
/* Parse and Compile Variable Declaration *
|
||||
* Uses: word - variable name */
|
||||
void addvar(int m, int t)
|
||||
{
|
||||
void addvar(int m, int t) {
|
||||
strcpy(vrname, word); //Save Variable Name
|
||||
if (fndvar(vrname))
|
||||
ERROR("Duplicate declaration of variable '%s\n", word,EXIT_FAILURE);
|
||||
@ -193,8 +183,7 @@ void addvar(int m, int t)
|
||||
|
||||
|
||||
/* Write Variable Table */
|
||||
void vartbl()
|
||||
{
|
||||
void vartbl(void) {
|
||||
int i, j;
|
||||
DEBUG("Writing Variable Table", 0);
|
||||
fprintf(logfil, "\n%-31s %s %s %s\n", "Variable", "Type", "Size", "Data");
|
||||
|
Loading…
x
Reference in New Issue
Block a user