Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef enum { PLUS, MINUS, DIV, MULT }binop;
- typedef enum { EQUAL, DIF, LESS, GT, LE, GE }relop;
- typedef struct _Instr Instr;
- struct _Instr {
- enum { ATOM_VAR, ATOM_NUMBER, BINOP, GOTO, IF_CONDITION, LABEL }kind;
- union {
- char *var;
- int number;
- struct {
- struct _Expr *left;
- struct _Expr *right;
- binop oper;
- }op;
- char *label;
- union {
- relop bool_oper;
- struct _Expr *if_condition;
- char *if_label;
- char *else_label;
- }if_else;
- }attr;
- };
- Instr *int_instr(int n);
- Instr *char_instr(char *v);
- Instr *mkBinop(binop o);
- Instr *binop_instr(binop op, Expr *l, Expr *r);
- Instr *goto_instr(char *g);
- Instr *if_instr(relop op, Expr *a, char *l1, char *l2);
- Instr *label_instr(char *l);
- char *newVar();
- char *newLabel();
- typedef struct _InstrList InstrList;
- struct _InstrList {
- Instr *instr;
- InstrList *next;
- };
- InstrList *mkIList(Instr *i, InstrList *n);
- Instr *getFirst(InstrList *l);
- InstrList *nextInstrs(InstrList *n);
- InstrList *append(InstrList *l1, InstrList *l2);
- InstrList *compileExp(Expr *e, char *r);
- InstrList *compileBool(ExprBool *e, char *labelTrue, char *labelFalse);
- InstrList *compileCmd(Cmd *c);
- void printInstr(Instr *i);
- void printListInstrs(InstrList *l);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement