📄 syntax.h
字号:
#ifndef SYNTAX_H
#define SYNTAX_H
#include "dccdef.h"
#include "symbol.h"
/* expression tree descriptions */
enum en_exp {//must in order!!!!!!
exp_void, // used for parameter lists, and vacant statement
exp_brace, // used in initializer
exp_const, exp_vref, exp_rref, exp_aref, exp_label,
//reference of variable, register, array,
exp_call,
exp_ntomem, exp_ptomem, exp_array,
exp_typecast, exp_sizeofexp, exp_sizeoftype, exp_ptr, exp_val, \
exp_incr, exp_decr, exp_uminus, exp_uplus, exp_lnot, exp_rvs,
exp_mul, exp_div, exp_mod,
exp_umul, exp_udiv, exp_umod,
exp_add, exp_sub,
exp_lsh, exp_rsh,
exp_eq, exp_ueq,
exp_gtr, exp_geq, exp_les, exp_leq,
exp_ugtr, exp_ugeq, exp_ules, exp_uleq,
exp_and,
exp_xor,
exp_or,
exp_land,
exp_lor,
exp_trinary, //opd1 is exp_lor
exp_assign,
exp_addas, exp_subas, exp_mulas, exp_divas, exp_modas,
// exp_notas, exp_andas, exp_oras,
exp_andas, exp_oras, exp_xoras, exp_lshas, exp_rshas,
// exp_comma,
// Cancel Comma expression, consider it as expression squence
exp_itof, exp_ftoi
};
#define is_variable(exptype) ((exptype)==exp_vref||((exptype)>=exp_ntomem&&(exptype)<=exp_array))
/* statement node descriptions */
enum en_stmt {
stmt_exp = 1, stmt_while, stmt_for, stmt_do, stmt_if, stmt_switch,
stmt_case, stmt_default, stmt_goto, stmt_break, stmt_continue, //stmt_label, stmt_asm,
stmt_return, stmt_compound, stmt_decl};
typedef struct _expnode {
struct _expnode *next;
enum en_exp exptype;
struct _datatype* datatype;
union {
long i;
unsigned long u;
double f; //remember!!!
struct {
char *base; //link name, if null means EBP
long offset;
}addr;
struct _sym *label;// just for the label of goto, shit
struct _expnode *opd[2];
}val;
}ExpNode;
typedef struct _stmtnode {
struct _stmtnode *next; // next statement
enum en_stmt stmtype;
struct _expnode *exp;// condition or expression ,also used in initializing
struct _supertype *spec;
struct _sym *declist;// for stmt_decl
struct _stmtnode *s1, *s2; // internal statements, for "for", "if-else"
struct _stmtnode *ss; // main compound stmt "while" "switch" "for"
int labelno; // for goto
char *filename; //for the need to report bug
int lineno; //for the need to report bug
}StmtNode;
typedef union _constvalue{
long i; /* int val */
unsigned long u; /* unsigned val */
double f; /* float val */
char *s; /* string val */
}ConstValue;
/**********************************************************************/
//syntax.c
struct _stmtnode *newDeclStmt(
struct _supertype *spec,
struct _sym *declist,
char *filename,
int lineno
);
struct _stmtnode *newCalcStmt(
int stmtype,
struct _expnode *exp,
struct _stmtnode *ss,
struct _stmtnode *s1,
struct _stmtnode *s2,
char *filename,
int lineno
);
void preswitch(struct _stmtnode *stmt);
struct _expnode *newInitExp(
int exptype
);
struct _expnode *evaluate_void_exp();
struct _expnode *evaluate_brace_exp(
struct _expnode *exp
);
//do some opt, get rid of const
struct _expnode *evaluate_const_exp(
int bt,
void *value
);
struct _expnode *evaluate_id_exp(
char *name
);
struct _expnode *evaluate_label_exp(
char *name
);
struct _expnode *evaluate_call_exp(
struct _expnode *func,
struct _expnode *arglist
);
struct _expnode *evaluate_member_exp(
int exptype,
struct _expnode *var,
char *memname
);
struct _expnode *evaluate_array_exp(
struct _expnode *array,
struct _expnode *index
);
struct _expnode *evaluate_typecast_exp(
struct _datatype *target_type,
struct _expnode *origin
);
struct _expnode *evaluate_sizeof_exp(
struct _datatype *type,
struct _expnode *exp
);
//increase or dcrease
struct _expnode *evaluate_indecr_exp(
int exptype, //if it is minus , means the opd is on the left , a little trick
struct _expnode *exp
);
struct _expnode *evaluate_unary_exp(
int exptype,
struct _expnode *exp
);
struct _expnode *evaluate_binary_exp(
int exptype,
struct _expnode *left,
struct _expnode *right
);
struct _expnode *evaluate_cmp_exp(
int exptype,
struct _expnode *left,
struct _expnode *right
);
struct _expnode *evaluate_bit_exp(
int exptype,
struct _expnode *left,
struct _expnode *right
);
struct _expnode *evaluate_logic_exp(
int exptype,
struct _expnode *left,
struct _expnode *right
);
struct _expnode *evaluate_trinary_exp(
struct _expnode *judge,
struct _expnode *left,
struct _expnode *right
);
struct _expnode *evaluate_assign_exp(
int exptype,
struct _expnode *left,
struct _expnode *right
);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -