From fd6a96afb5d3630a1ed6e87a402b22326141fa9e Mon Sep 17 00:00:00 2001 From: Curtis F Kaylor Date: Thu, 8 Mar 2018 08:23:05 -0500 Subject: [PATCH] Added struct declarations --- src/common.h | 10 ++++-- src/dclrtn.c | 11 ++++++- src/parse.h | 10 +++--- src/vars.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++----- src/vars.h | 58 +++++++++++++++++++-------------- 5 files changed, 139 insertions(+), 40 deletions(-) diff --git a/src/common.h b/src/common.h index a51ca78..ca8afe9 100644 --- a/src/common.h +++ b/src/common.h @@ -4,9 +4,13 @@ #define FNAMLEN 255 //Maximum File Name Length #define LINELEN 255 //Maximum Input/Output Line Length -#define CONLEN 6 //Maximum Definition Text Length -#define MAXCON 255 //Maximum Number of Definitions -#define VARLEN 6 //Maximum Variable Length +#define CONLEN 6 //Maximum Constant Name Length +#define MAXCON 255 //Maximum Number of Constants +#define STCLEN 6 //Maximum Struct Name Length +#define MAXSTC 32 //Maximum Number of Stuctures +#define STMLEN 6 //Maximum Struct Member Name Length +#define MAXSTM 255 //Maximum Number of Stucture Members +#define VARLEN 6 //Maximum Variable Name Length #define MAXVAR 255 //Maximum Number of Variables #define MAXFNS 16 //Maximum Functions in Stack #define DATASPC 2048 //Space to Allocate for Variable Data diff --git a/src/dclrtn.c b/src/dclrtn.c index 95d41f3..27ac86a 100644 --- a/src/dclrtn.c +++ b/src/dclrtn.c @@ -92,6 +92,14 @@ void penum(int m) { DEBUG("Enum Declaration Completed\n", 0) } +/* Parse Enum Declaration*/ +void pstrct(int m) { + DEBUG("Processing Struct Declarations\n", 0) + getwrd(); //Parse Structure Name + if (look('{')) defstc(); //Parse Struct Definition + else addstc(); //Parse and Compile Struct Declaration + SCMNT(""); //Clear Assembler Comment +} /* Parse Variable/Function Declaration*/ void pdecl(int m, int t) { @@ -113,7 +121,8 @@ void pdecl(int m, int t) { /* Check for and Parse Type Keyword */ int ptype(int m) { int result = TRUE; - if (wordis("CONST")) pconst(m); //Parse 'const' declaration + if (wordis("STRUCT")) pstrct(m); //Parse 'const' declaration + else if (wordis("CONST")) pconst(m); //Parse 'const' declaration else if (wordis("ENUM")) penum(m); //Parse 'enum' declaration else if (wordis("CHAR")) pdecl(m, VTCHAR); //Parse 'char' declaration else if (wordis("VOID")) pdecl(m, VTVOID); //Parse 'void' declaration diff --git a/src/parse.h b/src/parse.h index 7e088e2..8afee69 100644 --- a/src/parse.h +++ b/src/parse.h @@ -4,7 +4,7 @@ #define TF(x) (x) ? TRUE : FALSE; -enum stypes {LITERAL, VARIABLE, REGISTER, ARRAY, FUNCTION}; //Symbol Types +enum stypes {LITERAL, VARIABLE, REGISTER, ARRAY, STRUCT, FUNCTION}; //Symbol Types enum etypes {ETDEF, ETMAC}; //Definition Types char nxtwrd[LINELEN]; //Next Word (from DEFINE lookup) @@ -14,10 +14,10 @@ int valtyp; //Value Type char oper; //Arithmetic or Bitwise Operator int litval; //Value of Parsed Literal -char connam[MAXCON+1][CONLEN+1]; //Definition Name Table -int conval[MAXCON+1]; //Definition Value Table -int concnt; //Number of Definitions Defined -int conidx; //Index into Definition Tables +char connam[MAXCON+1][CONLEN+1]; //Constant Name Table +int conval[MAXCON+1]; //Constant Value Table +int concnt; //Number of Constants Defined +int conidx; //Index into Constant Tables int invasc; //Invert ASCII Flag int mskasc; //Set High Bit Flag diff --git a/src/vars.c b/src/vars.c index 2e426af..2ff5d06 100644 --- a/src/vars.c +++ b/src/vars.c @@ -20,7 +20,7 @@ * varcnt if not found * * Returns: TRUE if found, otherwise FALSE */ int fndvar(char *name) { - DEBUG("Looking up variable '%s'\n", word) + DEBUG("Looking up variable '%s'\n", name) for (varidx=0; varidx 256) ERROR("Structure Size %d Exceeds Limit of 256 bytes.\n", stclen, EXIT_FAILURE); + stcsiz[stccnt] = stclen; + DEBUG("Set struct size to %d\n", stclen); + stccnt++; + DEBUG("Struct Declaration Completed\n", 0) +} diff --git a/src/vars.h b/src/vars.h index cc49691..f60f6ee 100644 --- a/src/vars.h +++ b/src/vars.h @@ -3,20 +3,30 @@ *************************************/ /* Variable Table */ -char varnam[MAXVAR+1][VARLEN+1]; //Variable Name Table -char varmod[MAXVAR+1]; //Variable Modifier -char vartyp[MAXVAR+1]; //Variable Type -char varsiz[MAXVAR+1][4]; //Variable Array -int varcnt; //Number of Variables in Table -int varidx; //Index into Variable Tables -char vrname[MAXVAR+1]; //Variable Name -int vrwrtn; //Variables Written Flag +char varnam[MAXVAR+1][VARLEN+1]; //Variable Name Table +char varmod[MAXVAR+1]; //Variable Modifier +char vartyp[MAXVAR+1]; //Variable Type +char varsiz[MAXVAR+1][4]; //Variable Array Size +char varstc[MAXVAR+1]; //Variable Struct Type +int varcnt; //Number of Variables in Table +int varidx; //Index into Variable Tables +char vrname[MAXVAR+1]; //Variable Name +int vrwrtn; //Variables Written Flag -/* -int varidx; //Index into Variable Table -int vrtype; //Variable Type -*/ -enum vtypes {VTVOID, VTCHAR}; //Variable Types +char stcnam[MAXSTC+1][STCLEN+1]; //Structure Name Table +int stcsiz[MAXSTC+1]; //Structure Size Table +int stccnt; //Number of Structs Defined +int stcidx; //Index into Struct Tables +int stclen; //Size of Current Struct + +char stmnam[MAXSTM+1][STCLEN+1]; //Structure Member Name Table +int stmstc[MAXSTM+1]; //Structure Member Parent Struct +char stmtyp[MAXVAR+1]; //Structure Member Variable Type +int stmsiz[MAXVAR+1]; //Structure Member Array Size +int stmcnt; //Number of Struct Members Defined +int stmidx; //Index into Struct Member Tables + +enum vtypes {VTVOID, VTCHAR, VTSTRUCT}; //Variable Types char datvar[DATASPC+1]; //Variable Data Storage char datlen[MAXVAR+1]; //Variable Data Length @@ -39,14 +49,16 @@ char prmtrx[VARLEN+1]; //Function Parameter X char prmtry[VARLEN+1]; //Function Parameter Y int prmcnt; //Number of Parameters -void addvar(int m, int t); //Parse and Compile Variable Declaration +void addvar(int m, int t); //Parse and Compile Variable Declaration +void addstc(); //Parse and Compile Structure Declaration +void defstc(); //Parse Structure Definition void chksym(int alwreg, char *name); //Error if Variable not defined -void prsdts(); //Parse Data String -void setdat(); //Set Variable Data -void setvar(int m, int t); //Set Variable Name and Size -void prsdts(); //Parse Data String -void prsvar(int alwreg); //Parse Variable -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 -void vartbl(); //Create Variable Table +void prsdts(); //Parse Data String +void setdat(); //Set Variable Data +void setvar(int m, int t); //Set Variable Name and Size +void prsdts(); //Parse Data String +void prsvar(int alwreg); //Parse Variable +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 +void vartbl(); //Create Variable Table