statement.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef VIRTUALMATH_STATEMENT_H
  2. #define VIRTUALMATH_STATEMENT_H
  3. #include "__macro.h"
  4. typedef struct Statement{
  5. enum StatementType{
  6. start = 1,
  7. base_value,
  8. base_list,
  9. base_var,
  10. operation,
  11. set_function,
  12. call_function,
  13. if_branch,
  14. while_branch,
  15. for_branch,
  16. try_branch,
  17. with_branch,
  18. break_cycle,
  19. continue_cycle,
  20. rego_if,
  21. restart,
  22. return_code,
  23. raise_code,
  24. } type;
  25. union StatementU{
  26. struct base_value{
  27. struct LinkValue *value;
  28. } base_value;
  29. struct base_var{
  30. char *name;
  31. struct Statement *times;
  32. } base_var;
  33. struct {
  34. enum{
  35. list_,
  36. tuple_,
  37. } type;
  38. struct Parameter *list;
  39. } base_list;
  40. struct operation{
  41. enum OperationType{
  42. ADD = 1,
  43. SUB,
  44. MUL,
  45. DIV,
  46. ASS,
  47. } OperationType;
  48. struct Statement *left;
  49. struct Statement *right;
  50. } operation;
  51. struct {
  52. struct Statement *name;
  53. struct Statement *function;
  54. struct Parameter *parameter;
  55. } set_function;
  56. struct {
  57. struct Statement *function;
  58. struct Parameter *parameter;
  59. } call_function;
  60. struct {
  61. struct StatementList *if_list; // if elif
  62. struct Statement *else_list; // else分支(无condition)
  63. struct Statement *finally;
  64. } if_branch;
  65. struct {
  66. enum {
  67. while_,
  68. do_while_,
  69. } type;
  70. struct Statement *first; // first do
  71. struct StatementList *while_list; // while循环体
  72. struct Statement *after; // after do
  73. struct Statement *else_list; // else分支(无condition)
  74. struct Statement *finally;
  75. } while_branch;
  76. struct {
  77. struct Statement *var; // first do
  78. struct Statement *iter; // after do
  79. struct StatementList *for_list; // for循环体
  80. struct Statement *else_list; // else分支(无condition)
  81. struct Statement *finally;
  82. } for_branch;
  83. struct {
  84. struct Statement *try; // first do
  85. struct StatementList *except_list; // for循环体
  86. struct Statement *else_list; // else分支(无condition)
  87. struct Statement *finally;
  88. } try_branch;
  89. struct {
  90. struct StatementList *with_list; // for循环体
  91. struct Statement *else_list; // else分支(无condition)
  92. struct Statement *finally;
  93. } with_branch;
  94. struct {
  95. struct Statement *times;
  96. } break_cycle;
  97. struct {
  98. struct Statement *times;
  99. } continue_cycle;
  100. struct {
  101. struct Statement *times;
  102. } rego_if;
  103. struct {
  104. struct Statement *times;
  105. } restart;
  106. struct {
  107. struct Statement *value;
  108. } return_code;
  109. struct {
  110. struct Statement *value;
  111. } raise_code;
  112. }u;
  113. struct Statement *next;
  114. } Statement;
  115. typedef struct StatementList{
  116. enum {
  117. if_b,
  118. do_b,
  119. while_b,
  120. except_b,
  121. } type;
  122. struct Statement *condition;
  123. struct Statement *var;
  124. struct Statement *code;
  125. struct StatementList *next;
  126. } StatementList;
  127. Statement *makeStatement();
  128. Statement *makeOperationStatement(int type);
  129. struct Token *setOperationFromToken(Statement **st_ad, struct Token *left, struct Token *right, int type, bool is_right);
  130. Statement *makeTupleStatement(struct Parameter *pt, int type);
  131. Statement *makeFunctionStatement(Statement *name, Statement *function, struct Parameter *pt);
  132. Statement *makeCallStatement(Statement *function, struct Parameter *pt);
  133. Statement *makeIfStatement();
  134. Statement *makeWhileStatement();
  135. Statement *makeTryStatement();
  136. Statement *makeBreakStatement(Statement *times);
  137. Statement *makeContinueStatement(Statement *times);
  138. Statement *makeRegoStatement(Statement *times);
  139. Statement *makeRestartStatement(Statement *times);
  140. Statement *makeReturnStatement(Statement *value);
  141. Statement *makeRaiseStatement(Statement *value);
  142. void connectStatement(Statement *base, Statement *new);
  143. void freeStatement(Statement *st);
  144. StatementList *connectStatementList(StatementList *base, StatementList *new);
  145. StatementList *makeStatementList(Statement *condition, Statement *var, Statement *code, int type);
  146. void freeStatementList(StatementList *base);
  147. #define makeConnectStatementList(base, condition, var, code, type) connectStatementList(base, makeStatementList(condition, var, code, type))
  148. #endif //VIRTUALMATH_STATEMENT_H