struct decl {
char *name;
int nlocals;
struct type *type;
struct expr *value;
struct stmt *code;
struct symbol *symbol;
struct decl *next;
};
struct stmt {
int kind;
struct decl *decl;
struct expr *expr;
struct stmt *body;
struct stmt *ebody;
struct stmt *next;
};
#define STMT_KIND_DECL 0
#define STMT_KIND_EXPR 1
#define STMT_KIND_IF_ELSE 2
#define STMT_KIND_WHILE 3
#define STMT_KIND_RETURN 4
#define STMT_KIND_BLOCK 5
|
struct expr {
int kind;
struct expr *left;
struct expr *right;
const char *name;
int constant;
struct symbol *symbol;
int reg;
};
#define EXPR_KIND_LT 0
#define EXPR_KIND_LE 1
#define EXPR_KIND_EQ 2
#define EXPR_KIND_NE 3
#define EXPR_KIND_GT 4
#define EXPR_KIND_GE 5
#define EXPR_KIND_NOT 6
#define EXPR_KIND_ADD 7
#define EXPR_KIND_SUB 8
#define EXPR_KIND_MUL 9
#define EXPR_KIND_DIV 10
#define EXPR_KIND_NEG 11
#define EXPR_KIND_MOD 12
#define EXPR_KIND_ASSIGN 13
#define EXPR_KIND_CALL 14
#define EXPR_KIND_ARG 15
#define EXPR_KIND_NAME 16
#define EXPR_KIND_INT 17
#define EXPR_KIND_CHAR 18
#define EXPR_KIND_BOOLEAN 19
|
struct symbol {
int kind;
int which;
struct type *type;
char *name;
};
#define SYMBOL_KIND_NAME 0
#define SYMBOL_KIND_LOCAL 1
#define SYMBOL_KIND_PARAM 2
#define SYMBOL_KIND_GLOBAL 3
struct type {
int kind;
struct param_list *params;
struct type *rtype;
};
#define TYPE_KIND_CHARACTER 1
#define TYPE_KIND_INTEGER 2
#define TYPE_KIND_STRING 3
#define TYPE_KIND_BOOLEAN 4
#define TYPE_KIND_VOID 5
#define TYPE_KIND_FUNCTION 6
struct param_list {
char *name;
struct type *type;
struct param_list *next;
};
|