mirror of
https://github.com/RevCurtisP/C02.git
synced 2025-02-16 14:30:33 +00:00
Added CPU Type and Numeric Literal String Escapes
This commit is contained in:
parent
0bd11dbaed
commit
2b5f96c7d0
@ -52,6 +52,7 @@ void init(void) {
|
|||||||
xsnvar[0] = 0; //Assigned X Variable Name
|
xsnvar[0] = 0; //Assigned X Variable Name
|
||||||
ysnvar[0] = 0; //Assigned Y Variable Name
|
ysnvar[0] = 0; //Assigned Y Variable Name
|
||||||
subcnt = 0; //Include Subdirectories
|
subcnt = 0; //Include Subdirectories
|
||||||
|
strcpy(cputyp, CPUARG); //Set CPU Type to Default Value
|
||||||
strcpy(incdir, "../include/");
|
strcpy(incdir, "../include/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ void pdrctv(void) {
|
|||||||
|
|
||||||
void prolog(void) {
|
void prolog(void) {
|
||||||
DEBUG("Writing Assembly Prolog\n", 0)
|
DEBUG("Writing Assembly Prolog\n", 0)
|
||||||
asmlin(CPUOP,CPUARG);
|
asmlin(CPUOP,cputyp);
|
||||||
setcmt("Program ");
|
setcmt("Program ");
|
||||||
addcmt(srcnam);
|
addcmt(srcnam);
|
||||||
cmtlin();
|
cmtlin();
|
||||||
@ -130,12 +131,16 @@ int popt(int arg, int argc, char *argv[]) {
|
|||||||
strncpy (argstr, argv[arg], 31);
|
strncpy (argstr, argv[arg], 31);
|
||||||
if (strlen(argstr) != 2) ERROR("malformed option %s\n", argstr, EXIT_FAILURE)
|
if (strlen(argstr) != 2) ERROR("malformed option %s\n", argstr, EXIT_FAILURE)
|
||||||
opt = toupper(argstr[1]);
|
opt = toupper(argstr[1]);
|
||||||
if (strchr("HS", opt)) {
|
if (strchr("CHS", opt)) {
|
||||||
if (++arg >= argc) ERROR("Option -%c requires an argument\n", opt, EXIT_FAILURE)
|
if (++arg >= argc) ERROR("Option -%c requires an argument\n", opt, EXIT_FAILURE)
|
||||||
strncpy(optarg, argv[arg], 31);
|
strncpy(optarg, argv[arg], 31);
|
||||||
}
|
}
|
||||||
DEBUG("Processing Command Line Option -%c\n", argstr[1])
|
DEBUG("Processing Command Line Option -%c\n", argstr[1])
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
case 'C':
|
||||||
|
strcpy(cputyp, optarg);
|
||||||
|
DEBUG("CPU Type set to '%s'\n", cputyp)
|
||||||
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
strcpy(hdrnam, optarg);
|
strcpy(hdrnam, optarg);
|
||||||
DEBUG("Header Name set to '%s'\n", hdrnam)
|
DEBUG("Header Name set to '%s'\n", hdrnam)
|
||||||
|
@ -65,7 +65,10 @@ int savchr; //Holds nxtchr when switching input files
|
|||||||
int wrdlen; //Length of Parsed Word
|
int wrdlen; //Length of Parsed Word
|
||||||
char word[LINELEN]; //Word parsed from source file
|
char word[LINELEN]; //Word parsed from source file
|
||||||
char uword[LINELEN]; //Word converted to uppercase
|
char uword[LINELEN]; //Word converted to uppercase
|
||||||
|
int pstlen; //Length of Parsed String
|
||||||
|
char pstrng[LINELEN]; //String parsed fron source file
|
||||||
char cmtasm[LINELEN]; //Assembly Language Comment Text
|
char cmtasm[LINELEN]; //Assembly Language Comment Text
|
||||||
|
char cputyp[LINELEN]; //CPU Type
|
||||||
|
|
||||||
char hdrnam[FNAMLEN]; //Header File Name
|
char hdrnam[FNAMLEN]; //Header File Name
|
||||||
char incdir[FNAMLEN]; //Include File Directory
|
char incdir[FNAMLEN]; //Include File Directory
|
||||||
|
23
src/parse.c
23
src/parse.c
@ -81,12 +81,15 @@ void skpspc(void) {
|
|||||||
* otherwise FALSE */
|
* otherwise FALSE */
|
||||||
int look(char c) {
|
int look(char c) {
|
||||||
int found;
|
int found;
|
||||||
|
DEBUG("Looking for '%c', ", c);
|
||||||
skpspc();
|
skpspc();
|
||||||
found = match(c);
|
found = match(c);
|
||||||
if (found) {
|
if (found) {
|
||||||
skpchr();
|
skpchr();
|
||||||
CCMNT(c);
|
CCMNT(c);
|
||||||
|
DETAIL("Found\n", 0);
|
||||||
}
|
}
|
||||||
|
else DETAIL("Not found\n", 0);
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +139,8 @@ void getwrd(void) {
|
|||||||
while (isanum()) word[wrdlen++] = toupper(getnxt());
|
while (isanum()) word[wrdlen++] = toupper(getnxt());
|
||||||
word[wrdlen] = 0;
|
word[wrdlen] = 0;
|
||||||
ACMNT(word);
|
ACMNT(word);
|
||||||
|
DEBUG("Read word '%s'", word)
|
||||||
|
DETAIL("Delimited by '%c'\n", nxtchr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Escape Character */
|
/* Escape Character */
|
||||||
@ -154,31 +159,41 @@ char escape(char c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Escape Numeric Literal */
|
||||||
|
char escnum(void) {
|
||||||
|
DEBUG("Escaping numeric literal\n", 0);
|
||||||
|
char c = prsnum(0xff);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get String *
|
/* Get String *
|
||||||
* Sets: word = parsed string
|
* Sets: word = parsed string
|
||||||
* wrdlen = length of string (including terminator) */
|
* wrdlen = length of string (including terminator) */
|
||||||
void getstr(void) {
|
void getstr(void) {
|
||||||
char strdel;
|
char strdel;
|
||||||
int escnxt = FALSE;
|
int escnxt = FALSE;
|
||||||
wrdlen = 0;
|
pstlen = 0;
|
||||||
DEBUG("Parsing string\n", 0)
|
DEBUG("Parsing string\n", 0)
|
||||||
strdel = getnxt(); //Get String Delimiter
|
strdel = getnxt(); //Get String Delimiter
|
||||||
CCMNT(strdel);
|
CCMNT(strdel);
|
||||||
while(!match(strdel) || escnxt) {
|
while(!match(strdel) || escnxt) {
|
||||||
|
if (isnl()) ERROR("String Not Terminated", 0, EXIT_FAILURE)
|
||||||
CCMNT(nxtchr);
|
CCMNT(nxtchr);
|
||||||
if (escnxt) {
|
if (escnxt) {
|
||||||
word[wrdlen++] = escape(getnxt());
|
if (isnpre()) pstrng[pstlen++] = escnum();
|
||||||
|
else pstrng[pstlen++] = escape(getnxt());
|
||||||
escnxt = FALSE;
|
escnxt = FALSE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (match('\\')) escnxt = TRUE;
|
if (match('\\')) escnxt = TRUE;
|
||||||
else word[wrdlen++] = prcchr(nxtchr);
|
else pstrng[pstlen++] = prcchr(nxtchr);
|
||||||
skpchr();
|
skpchr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
skpchr(); //Skip End Delimiter
|
skpchr(); //Skip End Delimiter
|
||||||
CCMNT(strdel);
|
CCMNT(strdel);
|
||||||
word[wrdlen] = 0;
|
pstrng[pstlen] = 0;
|
||||||
|
strcpy(word,pstrng); wrdlen=pstlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read Binary number from input file *
|
/* Read Binary number from input file *
|
||||||
|
Loading…
x
Reference in New Issue
Block a user