📄 wsstree.h
字号:
/* The type is the opcode of the short-circuit logical byte-code operand. */ int type; struct WsExpressionRec *left; struct WsExpressionRec *right; } logical; struct { /* The type is the opcode of the binary byte-code operand. */ int type; struct WsExpressionRec *left; struct WsExpressionRec *right; } binary; struct { /* The type is the opcode of the unary byte-code operand. */ int type; struct WsExpressionRec *expr; } unary; struct { /* Is this an unary addition or substraction. */ WsBool addp; char *variable; } unary_var; struct { /* Is this a postfix addition or substraction. */ WsBool addp; char *variable; } postfix_var; struct { /* The type of the call: ' ', '#', '.' */ int type; /* The name of the external module or library. */ char *base; /* The name of the function to call. */ char *name; /* The arguments of the call. */ WsList *arguments; } call; struct { /* Separate sign bit, so that we can tell the difference * between -2147483648 and +2147483648. We have to deal * with both, because the former is parsed as "-" "2147483648". * Sign is 1 for positive numbers, -1 for negative numbers, * and can be either 1 or -1 for zero. */ int sign; WsUInt32 ival; } integer; char *symbol; WsUInt16 cindex; WsFloat fval; WsUtf8String string; } u;};typedef struct WsExpressionRec WsExpression;/* Linearize the expression `expr' into symbolic byte-code assembler. */void ws_expr_linearize(WsCompilerPtr compiler, WsExpression *expr);/* Constructors for different expression types. *//* Create a comma expression for `left' and `right'. */WsExpression *ws_expr_comma(WsCompilerPtr compiler, WsUInt32 line, WsExpression *left, WsExpression *right);/* Create an assignment expression. The argument `type' specifies the type of the expression. It is the assignment token value. */WsExpression *ws_expr_assign(WsCompilerPtr compiler, WsUInt32 line, char *identifier, int op, WsExpression *expr);/* Create a conditional expression with condition `e_cond' and expressions `e_then' and `e_else'. */WsExpression *ws_expr_conditional(WsCompilerPtr compiler, WsUInt32 line, WsExpression *e_cond, WsExpression *e_then, WsExpression *e_else);/* Create a logical expression of type `type'. The argument `type' is the opcode of the logical shoft-circuit byte-code operand. */WsExpression *ws_expr_logical(WsCompilerPtr compiler, WsUInt32 line, int type, WsExpression *left, WsExpression *right);/* Create a binary expression of type `type'. The argument `type' is the opcode of the binary byte-code operand. */WsExpression *ws_expr_binary(WsCompilerPtr compiler, WsUInt32 line, int type, WsExpression *left, WsExpression *right);/* Create an unary expression of type `type'. The argument `type' is the opcode of the unary byte-code operand. */WsExpression *ws_expr_unary(WsCompilerPtr compiler, WsUInt32 line, int type, WsExpression *expr);/* Create an unary variable modification expression. The argument `addp' specified whether the expression is an addition (++) or a substraction (--) expression. */WsExpression *ws_expr_unary_var(WsCompilerPtr compiler, WsUInt32 line, WsBool addp, char *variable);/* Create a postfix variable modification expression. The argument `addp' specified whether the expression is an addition (++) or a substraction (--) expression. */WsExpression *ws_expr_postfix_var(WsCompilerPtr compiler, WsUInt32 line, WsBool addp, char *variable);/* A generic call expression. The argument `type' must be one of ' ', '#', or '.' for local, extern, or library function call respectively. */WsExpression *ws_expr_call(WsCompilerPtr compiler, WsUInt32 linenum, int type, char *base, char *name, WsList *arguments);/* A symbol reference expression. */WsExpression *ws_expr_symbol(WsCompilerPtr compiler, WsUInt32 linenum, char *identifier);/* Constant `invalid'. */WsExpression *ws_expr_const_invalid(WsCompilerPtr compiler, WsUInt32 linenum);/* Constant `true'. */WsExpression *ws_expr_const_true(WsCompilerPtr compiler, WsUInt32 linenum);/* Constant `false'. */WsExpression *ws_expr_const_false(WsCompilerPtr compiler, WsUInt32 linenum);/* An unsigned 32 bit integer. */WsExpression *ws_expr_const_integer(WsCompilerPtr compiler, WsUInt32 linenum, WsUInt32 ival);/* A floating point number. */WsExpression *ws_expr_const_float(WsCompilerPtr compiler, WsUInt32 linenum, WsFloat fval);/* An UTF-8 encoded string. */WsExpression *ws_expr_const_string(WsCompilerPtr compiler, WsUInt32 linenum, WsUtf8String *string);/********************* Misc syntax tree structures **********************//* A variable declaration */struct WsVarDecRec{ char *name; WsExpression *expr;};typedef struct WsVarDecRec WsVarDec;/* Create a new variable declaration */WsVarDec *ws_variable_declaration(WsCompilerPtr compiler, char *name, WsExpression *expr);/* A function formal parameter */struct WsFormalParmRec{ WsUInt32 line; char *name;};typedef struct WsFormalParmRec WsFormalParm;/* Create a new formal parameter */WsFormalParm *ws_formal_parameter(WsCompilerPtr compiler, WsUInt32 line, char *name);/********************* Statements ***************************************//* Statement types. */typedef enum{ WS_STMT_BLOCK, WS_STMT_VARIABLE, WS_STMT_EMPTY, WS_STMT_EXPR, WS_STMT_IF, WS_STMT_FOR, WS_STMT_WHILE, WS_STMT_CONTINUE, WS_STMT_BREAK, WS_STMT_RETURN} WsStatementType;/* A statement. */struct WsStatementRec{ WsStatementType type; WsUInt32 first_line; WsUInt32 last_line; union { WsList *block; WsList *var; WsExpression *expr; struct { WsExpression *expr; struct WsStatementRec *s_then; struct WsStatementRec *s_else; } s_if ; struct { WsList *init; WsExpression *e1; WsExpression *e2; WsExpression *e3; struct WsStatementRec *stmt; } s_for ; struct { WsExpression *expr; struct WsStatementRec *stmt; } s_while ; } u;};typedef struct WsStatementRec WsStatement;/* Linearize the statement `stmt' into symbolic byte-code assembler. */void ws_stmt_linearize(WsCompilerPtr compiler, WsStatement *stmt);/* Constructors for statements. *//* Create a new block statement from the statements `block'. The arguments `first_line' and `last_line' specify the first and last line numbers of the block (the line numbers of the '{' and '}' tokens). */WsStatement *ws_stmt_block(WsCompilerPtr compiler, WsUInt32 first_line, WsUInt32 last_line, WsList *block);/* Create a new variable initialization statement. */WsStatement *ws_stmt_variable(WsCompilerPtr compiler, WsUInt32 line, WsList *variables);/* Create a new empty statement. */WsStatement *ws_stmt_empty(WsCompilerPtr compiler, WsUInt32 line);/* Create a new expression statement. */WsStatement *ws_stmt_expr(WsCompilerPtr compiler, WsUInt32 line, WsExpression *expr);/* Create a new if statement. */WsStatement *ws_stmt_if (WsCompilerPtr compiler, WsUInt32 line, WsExpression *expr, WsStatement *s_then, WsStatement *s_else);/* Create a new for statement. Only one of the arguments `init' and `e1' can be defined. The init must be given for statements which has a VariableDeclarationList in the initialization block. For the C-like statements, the argument `e1' must be given for the initialization expression. */WsStatement *ws_stmt_for (WsCompilerPtr compiler, WsUInt32 line, WsList *init, WsExpression *e1, WsExpression *e2, WsExpression *e3, WsStatement *stmt);/* Create a new while statement. */WsStatement *ws_stmt_while (WsCompilerPtr compiler, WsUInt32 line, WsExpression *expr, WsStatement *stmt);/* Create a new continue statement. */WsStatement *ws_stmt_continue(WsCompilerPtr compiler, WsUInt32 line);/* Create a new break statement. */WsStatement *ws_stmt_break(WsCompilerPtr compiler, WsUInt32 line);/* Create a new return statement. The argument `expr' is the expression to return. If it is NULL, the return statement returns an empty string. */WsStatement *ws_stmt_return(WsCompilerPtr compiler, WsUInt32 line, WsExpression *expr);#endif /* not WSSTREE_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -