Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. typedef enum { PLUS, MINUS, DIV, MULT }binop;
  2. typedef enum { EQUAL, DIF, LESS, GT, LE, GE }relop;
  3.  
  4. typedef struct _Instr Instr;
  5.  
  6. struct _Instr {
  7. enum { ATOM_VAR, ATOM_NUMBER, BINOP, GOTO, IF_CONDITION, LABEL }kind;
  8. union {
  9. char *var;
  10. int number;
  11. struct {
  12. struct _Expr *left;
  13. struct _Expr *right;
  14. binop oper;
  15. }op;
  16. char *label;
  17. union {
  18. relop bool_oper;
  19. struct _Expr *if_condition;
  20. char *if_label;
  21. char *else_label;
  22. }if_else;
  23. }attr;
  24. };
  25.  
  26. Instr *int_instr(int n);
  27. Instr *char_instr(char *v);
  28. Instr *mkBinop(binop o);
  29. Instr *binop_instr(binop op, Expr *l, Expr *r);
  30. Instr *goto_instr(char *g);
  31. Instr *if_instr(relop op, Expr *a, char *l1, char *l2);
  32. Instr *label_instr(char *l);
  33. char *newVar();
  34. char *newLabel();
  35.  
  36. typedef struct _InstrList InstrList;
  37.  
  38. struct _InstrList {
  39. Instr *instr;
  40. InstrList *next;
  41. };
  42.  
  43. InstrList *mkIList(Instr *i, InstrList *n);
  44. Instr *getFirst(InstrList *l);
  45. InstrList *nextInstrs(InstrList *n);
  46. InstrList *append(InstrList *l1, InstrList *l2);
  47. InstrList *compileExp(Expr *e, char *r);
  48. InstrList *compileBool(ExprBool *e, char *labelTrue, char *labelFalse);
  49. InstrList *compileCmd(Cmd *c);
  50.  
  51. void printInstr(Instr *i);
  52. void printListInstrs(InstrList *l);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement