📄 statement.h
字号:
#ifndef STATEMENT_H#define STATEMENT_Htypedef struct statement Statement;#include "bool.h"#include "expression.h"#include "list.h"#include "scope.h"#include "token.h"typedef enum{ assignment_stat = 40, compound_stat, delete_stat, expr_stat, for_stat, if_stat, repeat_stat, return_stat, while_stat}Stat_subtype;/* Statements are stored in 'Statement'-type structures. The subtype field * indicates the type of the statement (listed in Stat_subtype) * Depending on this type, the union un may contain fields specific * to that type of statement. For instance, an assignment statement * has two expressions pointing to the lvalue and rvalue, and a loop * statement has a condition expression to evaluate and another statement * to execute. These fields should be accessed using the ASSIGNMENT_STAT, * COMPOUND_STAT, etc defines! */struct statement{ Stat_subtype subtype; union { struct { Expression *lvalue; Expression *rvalue; } assignment_stat; struct { List *declarations; List *statements; Scope *scope; Bool must_delete_scope; } compound_stat; struct { Expression *expression; } delete_stat, expr_stat; struct for_stat { Expression *loop_variable; Expression *begin_value; Expression *end_value; Expression *increment_value; Statement *body; } for_stat; struct if_stat { Expression *condition; Statement *then_body; Statement *else_body; /* 0 if no else-part */ } if_stat; struct loop_stat { Statement *body; Expression *condition; } loop_stat; struct return_stat { Expression *return_value; /* 0 if no return value */ Token *token; } return_stat; } un;};#define ASSIGNMENT_STAT(s) ((s)->un.assignment_stat)#define COMPOUND_STAT(s) ((s)->un.compound_stat)#define DELETE_STAT(s) ((s)->un.delete_stat)#define EXPR_STAT(s) ((s)->un.expr_stat)#define FOR_STAT(s) ((s)->un.for_stat)#define IF_STAT(s) ((s)->un.if_stat)#define LOOP_STAT(s) ((s)->un.loop_stat)#define RETURN_STAT(s) ((s)->un.return_stat)Statement *new_assignment_statement(Expression *lvalue, Expression *rvalue);Statement *new_compound_statement(List *declarations, List *statements, Scope *scope);Statement *new_delete_statement(Expression *expression);Statement *new_expression_statement(Expression *expression);Statement *new_for_statement(Expression *loop_variable, Expression *begin_value, Expression *end_value, Expression *increment_value, Statement *body);Statement *new_if_statement(Expression *condition, Statement *then_body, Statement *else_body);Statement *new_repeat_statement(Statement *body, Expression *condition);Statement *new_return_statement(Expression *return_value, Token *);Statement *new_while_statement(Expression *condition, Statement *body);void delete_statement(Statement *);void type_check_statement(Statement *, Declaration *subprog);void generate_statement(Statement *);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -