- 论坛徽章:
- 0
|
上次附件有问题,已经重新更新了一下。
下面是初步确定使用的符号表的一些结构定义,代码目前还没有完成。
- typedef enum {StmtT, ExprT} NodeType;
- typedef enum {VariableT, ParameterT, ConstantT, AssignT, FunctionT, CallT, LabelT, IfT, ElseT, ForT, WhileT, DoWhileT, GotoT, ContinueT, BreakT, ReturnT} StmtType;
- typedef enum {OperT, ConstT, IdT,ValueT} ExprType;
- typedef enum {ByteT, CharT, ShortT, IntT, LongT, FloatT, DoubleT, BoolT, StringT, StructT, ClassT, VoidT} DataType;
- typedef enum
- {
- OP_ASSIGN,
- OP_EQ,
- OP_NE,
- OP_LT,
- OP_GT,
- OP_LE,
- OP_GE,
- OP_AND,
- OP_OR,
- OP_ADD,
- OP_SUB,
- OP_MUL,
- OP_DIV,
- OP_MOD,
- OP_ADD_ASSIGN,
- OP_SUB_ASSIGN,
- OP_MUL_ASSIGN,
- OP_DIV_ASSIGN,
- OP_MOD_ASSIGN,
- OP_AND_ASSIGN,
- OP_XOR_ASSIGN,
- OP_OR_ASSIGN
-
- } OpType;
- struct Symbol
- {
- char* name;
- int lineno;
- NodeType nodetype;
- union
- {
- StmtType stmt;
- ExprType expr;
- } symtype;
-
- ValueType valuetype;
- union
- {
- OpType opval;
- char byteval;
- short charval;
- short shortval;
- int intval;
- int64 longval;
- float floatval;
- double doubleval;
- int boolval;
- char * stringval;
- void * structval;
- } value;
-
-
- int size;
- int bitsize;
- int boundary;
- int bitbdary;
- DataType type;
- DataType basetype;
- DataType machtype;
- int nelts : 0;
- };
- typedef struct Symrec Symrec ;
- struct Symrec
- {
- Symbol node;
- Symrec* child[MAX_CHILD];
- Symrec* next;
- };
- struct Symtable
- {
- Symtable * tables;
- Symrec * symrec;
- };
复制代码 |
|