mirror of
https://github.com/RevCurtisP/C02.git
synced 2025-02-19 19:31:04 +00:00
Added index-of operator for struct members
This commit is contained in:
parent
93b8f5859f
commit
44a763826b
17
doc/c02.txt
17
doc/c02.txt
@ -543,6 +543,23 @@ Note: The size-of operator is evaluated at compile time and generates two
|
||||
bytes of machine language code. It is the most efficient method of specifying
|
||||
a variable length.
|
||||
|
||||
INDEX-OF OPERATOR
|
||||
|
||||
The index-of operator ? generates a literal value equal to the offset in bytes
|
||||
of a specified stucture member. It is allowed anywhere a literal would be and
|
||||
should be used anytime the offset of the member of a struct is required.
|
||||
|
||||
When using the size-of operator, it is prefixed to the member specification.
|
||||
|
||||
Examples:
|
||||
|
||||
blkmem(?rec.data, &s); //Search block for segment where data contains s
|
||||
memcpy(?rec.data, &t); //Copy bytes of rec up to member data into t
|
||||
|
||||
Note: The idex-of operator is evaluated at compile time and generates two
|
||||
bytes of machine language code. It is the most efficient method of specifying
|
||||
a the offset of a struct member.
|
||||
|
||||
FUNCTION CALLS
|
||||
|
||||
A function call may be used as a stand-alone statement, or as the first
|
||||
|
@ -24,7 +24,7 @@ int isbpre(void) {return TF(isnpre() || isapos());}
|
||||
int isdec(void) {return inbtwn('0', '9');}
|
||||
int iscpre(void) {return match('#');}
|
||||
int ishexd(void) {return TF(isdec() || inbtwn('A', 'Z'));}
|
||||
int islpre(void) {return TF(isbpre() || iscpre() || isszop());}
|
||||
int islpre(void) {return TF(isbpre() || iscpre() || isszop() || isxfop());}
|
||||
int isnl(void) {return TF(match('\n') || match('\r'));}
|
||||
int isnpre(void) {return TF(isdec() || match('$') || match('%'));}
|
||||
int isoper(void) {return TF(strchr("+-&|^", nxtchr));}
|
||||
@ -33,6 +33,7 @@ int isprnt(void) {return isprint(nxtchr);}
|
||||
int isspc(void) {return isspace(nxtchr);}
|
||||
int isszop(void) {return match('@');}
|
||||
int isvpre(void) {return TF(isalph() || islpre());}
|
||||
int isxfop(void) {return match('?');}
|
||||
int isxpre(void) {return TF(isvpre() || match('-'));}
|
||||
|
||||
/* Process ASCII Character */
|
||||
@ -317,7 +318,8 @@ int prscon(void) {
|
||||
void prslit(void) {
|
||||
skpspc();
|
||||
if (iscpre()) litval = prscon(); //Parse Constant
|
||||
else if (isszop()) litval = psizof(); //Parese SizeOf Operator
|
||||
else if (isszop()) litval = psizof(); //Parse SizeOf Operator
|
||||
else if (isxfop()) litval = pidxof(); //Parse IndexOf Operator
|
||||
else litval = prsbyt(); //Parse Byte Value
|
||||
valtyp = LITERAL;
|
||||
strcpy(word, value); //Patch for DASM
|
||||
|
@ -40,6 +40,7 @@ int isprnt(); //Is Next Character Printable
|
||||
int isspc(); //Is Next Character a Space
|
||||
int isszop(); //Is Next Character the SizeOf Operator
|
||||
int isvpre(); //Is Next Character a Value Prefix
|
||||
int isxfop(); //Is Next Character the IndexOf Operator
|
||||
int isxpre(); //Is Next Character an Expression Prefix
|
||||
|
||||
void expect(char c); //Look for Character and Exit if not found
|
||||
@ -54,6 +55,7 @@ int prsnum(int maxval); //Parse Numeric
|
||||
void prsopr(); //Parse Arithmetic Operator
|
||||
int prspst(char trmntr, char* name, char* index); //Parse Post Operator
|
||||
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 skpspc(); //Advance to Next Printable Character
|
||||
|
22
src/vars.c
22
src/vars.c
@ -104,15 +104,31 @@ void reqvar(int alwary) {
|
||||
if (!alwary && valtyp != VARIABLE) expctd("Variable");
|
||||
}
|
||||
|
||||
/* Parse IndexOf Operator *
|
||||
* Sets: value - variable size (as string) *
|
||||
* Returns: variable size (as integer */
|
||||
int pidxof(void) {
|
||||
expect('?'); //Check for and Skip SizeOf Operator
|
||||
DEBUG("Parsing IndexOf operator", 0);
|
||||
mbridx = -1; //Set Member Index to None
|
||||
reqvar(FALSE); //Parse Variable Name to get Size Of
|
||||
if (mbridx > -1) {
|
||||
sprintf(value, "$%hhX", membrs[mbridx].offset);
|
||||
return membrs[mbridx].offset;
|
||||
}
|
||||
ERROR("IndexOf operator requires a struct member\n", 0, EXIT_FAILURE);
|
||||
return 0; //Suppress Warning
|
||||
}
|
||||
|
||||
/* Parse SizeOf Operator *
|
||||
* Sets: value - variable size (as string) *
|
||||
* Returns: variable size (as integer */
|
||||
int psizof(void) {
|
||||
expect('@'); //Check for and Skip SizeOf Operator
|
||||
DEBUG("Parsing sizeof operator", 0);
|
||||
DEBUG("Parsing SizeOf operator", 0);
|
||||
mbridx = -1; //Set Member Index to None
|
||||
reqvar(FALSE); //Parse Variable Name to get Size Of
|
||||
if (mbridx > 0) {
|
||||
if (mbridx > -1) {
|
||||
sprintf(value, "$%hhX", membrs[mbridx].size);
|
||||
return membrs[mbridx].size;
|
||||
}
|
||||
@ -183,7 +199,7 @@ void prsdat(void) {
|
||||
else if (match('"')) prsdts(); //Parse Data String
|
||||
else if (match('{')) prsdta(); //Parse Data Array
|
||||
else expctd("numeric or string literal");
|
||||
if (alcvar && dtype == DTBYTE) setdat(); //Store Data Value
|
||||
if (alcvar || dtype == DTBYTE) setdat(); //Store Data Value
|
||||
}
|
||||
|
||||
/* Add Variable to Variable table *
|
||||
|
@ -64,6 +64,7 @@ void prsdts(); //Parse Data String
|
||||
void prsvar(int alwreg); //Parse Variable
|
||||
void prsmbr(char* name); //Parse Struct Member
|
||||
int psizof(void); //Parse SizeOf Operator
|
||||
int pidxof(void); //Parse IndexOf Operator
|
||||
void reqvar(int alwary); //Require and Parse Variable Name
|
||||
void setdat(); //Store variable data
|
||||
void setvar(int m, int t); //Add Variable to Variable table
|
||||
|
@ -15,6 +15,15 @@ struct record {
|
||||
//Declare Structure Variable
|
||||
struct record rec;
|
||||
|
||||
//Display Structure Info
|
||||
printf(@rec,"@rec=%d\n");
|
||||
printf(?rec.name,"?rec.name=%d\t");
|
||||
printf(@rec.name,"@rec.name=%d\n");
|
||||
printf(?rec.index,"?rec.index=%d\t");
|
||||
printf(@rec.index,"@rec.index=%d\n");
|
||||
printf(?rec.data,"?rec.data=%d\t");
|
||||
printf(@rec.data,"@rec.data=%d\n");
|
||||
|
||||
//Set Structure Members
|
||||
strdst(&rec.name); strcpy(name);
|
||||
rec.index = index;
|
||||
@ -32,6 +41,6 @@ index = rec.index;
|
||||
for (i = 0; i<129; i++)
|
||||
d = rec.data[i];
|
||||
|
||||
//Treat Structure Like and Array
|
||||
//Treat Structure Like an Array
|
||||
for (i = 0; i<140; i++)
|
||||
d = rec[i];
|
||||
|
Loading…
x
Reference in New Issue
Block a user