1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2025-02-19 19:31:04 +00:00

Allow comments inside struct definitions

This commit is contained in:
Curtis F Kaylor 2019-05-05 18:10:26 -04:00
parent e87b4e9b44
commit 28960cbcfa
7 changed files with 36 additions and 24 deletions

View File

@ -109,7 +109,7 @@ void compile(void) {
if (match(EOF)) break; //Stop Parsing (End of File)
else if (match('}')) endblk(TRUE); //End Multi-Line Program Block
else if (match('#')) pdrctv(); //Parse Directive
else if (match('/')) skpcmt(); //Skip Comment
else if (match('/')) skpcmt(TRUE); //Skip Comment
else if (isalph()) pword(); //Parse Word
else ERROR("Unexpected character '%c'\n", nxtchr, EXIT_FAILURE)
}

View File

@ -233,7 +233,7 @@ void inchdr(int chksub) {
if (match('#'))
pincdr();
else if (match('/'))
skpcmt();
skpcmt(TRUE);
else if (isalph())
phdwrd();
else {

View File

@ -106,13 +106,13 @@ void skpeol(void) {while (!isnl()) getnxt();}
/* Advance Source File to end of comment *
* Recognizes both C and C++ style comments */
void skpcmt(void)
void skpcmt(int exslsh)
{
DEBUG("Skipping Comment\n", 0)
skpchr(); //skip initial /
if (exslsh) expect('/'); //skip initial /
if (match('/')) skpeol(); //if C style comment skip rest of line
else if (match('*')) //if C++ style comment
while (TRUE) // skip to */
else if (match('*')) //if C++ style comment
while (TRUE) // skip to */
{
skpchr();
if (!match('*')) continue;

View File

@ -58,6 +58,6 @@ int prspst(char trmntr, int isint, char* name, char* index); //Parse Post Oper
int psizof(void); //Parse SizeOf Operator
int pidxof(void); //Parse SizeOf Operator
void skpchr(); //Skip Next Character
void skpcmt(); //Skip to End of Comment
void skpcmt(int exslsh); //Skip to End of Comment
void skpspc(); //Advance to Next Printable Character
int wordis(char *s); //Does word match s

View File

@ -375,6 +375,7 @@ void defstc(void) {
strncpy(strct.name, word, STCLEN);
DEBUG("Set struct name to '%s'\n", word);
strct.size = 0; //Initialize Struct Length
while (look('/')) skpcmt(FALSE); //Skip Comments
do {
getwrd(); //Get Member Name
if (wordis("STRUCT")) {
@ -411,6 +412,7 @@ void defstc(void) {
membrs[mbrcnt++] = membr;
strct.size += membr.size;
expect(';');
while (look('/')) skpcmt(FALSE); //Skip Comments
} while (!look('}'));
expect(';');
if (strct.size > 256) ERROR("Structure Size %d Exceeds Limit of 256 bytes.\n", strct.size, EXIT_FAILURE);

View File

@ -2,6 +2,15 @@
* C02 Variable Management Routines *
*************************************/
/* Variable Record */
struct varrec {
char name[VARLEN+1]; //Variable Name Table (string)
char modifr; //Variable Modifier (MTxxx)
char type; //Variable Type (VTxxx)
char size[4]; //Variable Array Size (string)
char stcidx; //Variable Struct Index
};
/* Variable Table */
char varnam[MAXVAR+1][VARLEN+1]; //Variable Name Table (string)
char varmod[MAXVAR+1]; //Variable Modifier (MTxxx)
@ -11,6 +20,7 @@ char varstc[MAXVAR+1]; //Variable Struct Index
int varcnt; //Number of Variables in Table
int varidx; //Index into Variable Tables
char vrname[MAXVAR+1]; //Variable Name
int vrtype; //Variable Type
int vrwrtn; //Variables Written Flag
struct strctd { //Struct Definition

View File

@ -12,12 +12,13 @@
char d, i;
char aa,xx,yy;
int yx;
//Define Structure
struct record {
char name[8];
char index;
data[128];
struct record { /* Sample Record */
char name[8]; //Name
char index; //Index
data[128]; //Data
};
//Declare Structure Variable
@ -76,22 +77,22 @@ goto exit;
//Print Destination Record
void prtdst() {
puts("REC.NAME="); putln(&dstrec.name);
puts("REC.INDEX="); putdec(dstrec.index); newlin();
puts("REC.DATA={");
setdst(&dstrec.name); printf("REC.NAME=\"%s\"%n");
printf(dstrec.index, "REC.INDEX=%d%n");
puts("REC.DATA=[");
for (i = 0; i<@dstrec.data; i++) {
if (i) putc(',');
putdec(dstrec.data[i]);
}
putln("}");
newlin();
putln("]");
anykey();
}
//Print Frame
void prtfrm() {
puts("outer."); cpybox(&fram.outer); prtbox();
puts("inner."); cpybox(&fram.inner); prtbox();
newlin();
putln("OUTER."); cpybox(&fram.outer); prtbox();
putln("INNER."); cpybox(&fram.inner); prtbox();
anykey();
}
void cpybox() {
@ -101,15 +102,14 @@ void cpybox() {
//Print Box
void prtbox() {
puts("toplft."); prtpnt(&box.toplft);
puts("btmrgt."); prtpnt(&box.btmrgt);
newlin();
puts(" TOPLFT."); prtpnt(&box.toplft);
puts(" BTMRGT."); prtpnt(&box.btmrgt);
}
//Print Point
void prtpnt() {
savrxy(); setdst(&pnt);
resrxy(); memcpy(@pnt);
printf(pnt.xpos,"xpos=%d,");
printf(pnt.ypos,"ypos=%d ");
printf(pnt.xpos,"XPOS=%d,");
printf(pnt.ypos,"YPOS=%d%n");
}