📄 struct.h
字号:
#ifndef COMPILER_STRUCT#define COMPILER_STRUCT#define TREE_X 1000#define TREE_Y 1000#define INT_SIZE 4#define CHAR_SIZE 4#define FLOAT_SIZE 4#define DOUBLE_SIZE 8#define STRUCT_SIZE 4 // the size of the start address of a structure#define VOID_SIZE 0typedef struct symtype{ char name[255]; // structure name char scope[256]; // scope of the structure char memberName[256][256]; // member names int member[256]; // the type for each member int sizeOfMember[256]; // size of each member, how many of each int numMembers; struct symtype *next;} symtype;typedef struct symrec{ char *name; int nameType; // variable 0, function 1 int type; // char 0, int 1, float 2, void 3, double 4, struct 5 int isArray; // 0 not an array, 1 yes it's an array variable int numArray; int numArgs; // if node is func, store the number of args in the func defination int argsType[20]; // if node is a func. Type of args, index 0 is the 1st arg, 1 is the 2nd and so on int isFuncArg; // parameter of func or not. 0 local val, 1 parameters int order; // if variable, the order of the val. start 0, and add one for next val in the same function int argOrder; // the order of function arguments char value[20]; // if char, int or float, the value is saved here as string char *scope; struct symtype *structtype; struct symrec *next;} symrec;typedef struct symnode{ char *name; char value[30]; // if is char, int or float, real values saved here as string int strIndex; //if name is STRING, store the literal string index in literals[][] symrec *symTab; //if ID, point to the symTable int line,col; struct symnode *sibling; struct symnode *next;} symnode;symrec *symTable;symnode *symRoot;symtype *symStruct;symtype *curStrNode;//int numError;int currLine;int column;int idType; // type of id. char 0, int 1, float 2, void 3, double 4, struct 5int funcType ; // type of function. char 0 int 1, float 2, void 3, double 4, struct 5char idName[255]; // the name of latest ID tokenchar scope[255]; // the scope of variable or function int strCount; // num of literal stringsint numArgs; // num of arguments for a functionint arraySize;int numTypes; // number of user define typesint numMembers; // number of the members in a structureint symTableError;int typeErrs;char literals[255][255];int numGlobals();int numVals(const char *scope);int maxValOrder(const char * scope);int maxArgOrder(const char *name,const char *scope);symrec *getValNode( const char *scope, int isPara, int index);symrec *getFuncNode(const char *funcName);int sizeOfVals(const char * scope);int sizeOfID(symnode *id);int sizeOfStruct(symtype *node);int offsetAtID(const char *scope, int index);int offsetOfPara(const char *scope, int index);int sizeAtIndex(symnode *id, int index);int sizeAtMember(symtype *id, const char* member);int sizeOfID(symnode *id);int sizeOfStruct(symtype *node);int getMemberType(symtype *str, const char *member);int getMemberSize(symtype *str, const char *member);symnode *addSibling (symnode *, symnode * );symnode *addNext (symnode *, symnode *);symnode *newLeaf(char *);symnode *copyNode(symnode *src, symnode *dest);symnode *setStrIndex(symnode *node, int i);symrec *add2Table(const char *, int, const char*);symrec *getsym (const char *, const char *);symrec *putsym (const char *, int, int , const char *);symtype * getStruct(const char * struct_name, const char * scope);symtype *putStruct(const char * struct_name, const char * scope);symtype *newStruct(const char * struct_name, const char * scope);int sizeOfStruct(symtype *node);void printParseTree(symnode *);int printSymbolTable();int checkFunc(symnode *func, symnode *tree, int argOrder);void typeCheck(symnode *tree);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -