o_o设计之路,解释器头文件
1 // 2 // oointerpreter.h 3 // o_o 4 // 5 // Created by cy0104 on 2017/5/18. 6 // Copyright © 2017年 cy0104. All rights reserved. 7 // 8 9 #define USE_GLBL 10 #ifndef oointerpreter_h 11 #define oointerpreter_h 12 13 #include <string.h> 14 #include "prefix.h" 15 #include "vector.h" 16 #include "o_opcodes.h" 17 18 /* symbol definition */ 19 #pragma region trans 20 21 /*WARN:following codes may not work on certain ide,in witch fix it manully.*/ 22 #define O_O_SYM const char* 23 #define O_O_BRE O_O_SYM 24 #define O_O_REG O_O_SYM 25 #define O_O_OPE O_O_SYM 26 #define O_O_STR O_O_SYM 27 28 #define __symdes(__ssym,__ctok,__ctyp)(#__ctok #__ctyp #__ssym) 29 #define symdes(a,b,c)(__symdes(a,b,c)) 30 #define test_of_symdes(__ssym,__ctok)(__ctok ## __ssym) 31 32 #define tokofdes(des)(des[0]) 33 #define typofdes(des)(des[1]) 34 #define symofdes(des)(des+2) 35 36 /*fetch left or right region-symbol*/ 37 #define l_reg(__index)(ooreg[__index*2]) 38 #define r_reg(__index)(ooreg[__index*2+1]) 39 40 /*execute order of symbols*/ 41 #define TOK_LBR \x41 42 #define TOK_STR \x42 43 #define TOK_SBR \x43 44 #define TOK_WBR \x44 45 #define TOK_MOV \x45 46 #define TOK_ADD \x46 47 #define TOK_MUL \x47 48 #define TOK_AND \x48 49 #define TOK_CMP \x49 50 #define TOK_REG \x4A 51 #define TOK_INC \x4B 52 53 /*ref & expr combine order*/ 54 /* 55 **R:Ref 56 **E:Expr 57 */ 58 #define R_EXP \x58 59 #define EXP_R \x59 60 #define R_R \x5A 61 #define EXP_EXP \x5B 62 #define R_ \x50 63 #define X_X \x41 64 #define _R \x48 65 #define _EXP \x49 66 #define HAS_LEXPR(__typ) (__typ&0x10) 67 #define HAS_REXPR(__typ) (__typ&0x08) 68 #define is_typ(c,t)(c==@#t) 69 70 O_O_BRE oolbr = "\n\r"; 71 72 //{ 73 // symdes(\x0a,TOK_LBR,X_X),/* \n */ 74 // symdes(\x0d,TOK_LBR,X_X),/* \r */ 75 // symdes(;,TOK_SBR,X_X), 76 // symdes(\x20,TOK_WBR,X_X),/* space */ 77 // symdes(\x09,TOK_WBR,X_X),/* tab */ 78 // NULL 79 //}; 80 O_O_BRE oowbr = " \t"; 81 O_O_REG ooreg = "()[]{}"; 82 //{ 83 // symdes(\x28,TOK_REG,X_X),/* ( */ 84 // symdes(\x29,TOK_REG,X_X),/* ) */ 85 // symdes([,TOK_REG,X_X), 86 // symdes(],TOK_REG,X_X), 87 // symdes({,TOK_REG,X_X), 88 // symdes(},TOK_REG,X_X), 89 // NULL 90 //}; 91 92 O_O_STR oostr = "\"\'"; 93 //{ 94 // symdes(\x39,TOK_STR,X_X), 95 // symdes(\x34,TOK_STR,X_X), 96 // NULL 97 //}; 98 BEGIN_DECL_GLBL(char, test) 99 "123123" 100 END_DECL_GLBL; 101 102 O_O_OPE ooope[] = { 103 symdes(<-,TOK_MOV,R_EXP), 104 symdes(->,TOK_MOV,EXP_R), 105 symdes(<->,TOK_MOV,R_R), 106 symdes(+=,TOK_MOV,R_EXP), 107 symdes(-=,TOK_MOV,R_EXP), 108 symdes(*=,TOK_MOV,R_EXP), 109 symdes(/=,TOK_MOV,R_EXP), 110 symdes(%=,TOK_MOV,R_EXP), 111 symdes(^=,TOK_MOV,R_EXP), 112 113 symdes(+,TOK_ADD,EXP_EXP), 114 symdes(-,TOK_ADD,EXP_EXP), 115 116 symdes(*,TOK_MUL,EXP_EXP), 117 symdes(/,TOK_MUL,EXP_EXP), 118 symdes(%,TOK_MUL,EXP_EXP), 119 120 symdes(||,TOK_AND,EXP_EXP), 121 symdes(&&,TOK_AND,EXP_EXP), 122 123 symdes(!,TOK_INC,_EXP), 124 symdes(++,TOK_INC,R_), 125 symdes(--,TOK_INC,R_), 126 127 symdes(<,TOK_CMP,EXP_EXP), 128 symdes(>,TOK_CMP,EXP_EXP), 129 symdes(=,TOK_CMP,EXP_EXP), 130 symdes(==,TOK_CMP,EXP_EXP), 131 symdes(<=,TOK_CMP,EXP_EXP), 132 symdes(>=,TOK_CMP,EXP_EXP), 133 symdes(!=,TOK_CMP,EXP_EXP), 134 135 NULL 136 }; 137 138 #pragma endregion 139 /* end of symbol definition */ 140 141 #define PREPROC_SYNTAX_CHECK(__codes,errCode,errMessage) 142 143 #define INTERP_SYNTAX_CHECK(__codes,errCode,errMessage) 144 145 #define SCAN_LINE(__codes,__tmpSym) \ 146 char* __tmpSym; \ 147 for(char* pChar = __codes;pChar!='\n'&&pChar!=0;pChar++){ \ 148 \ 149 } 150 #pragma region string usage 151 152 #define s_in_s(sBig,sSmall) strstr(sBig,sSmall) 153 #pragma end region 154 int __preload_config(const char* fp); 155 O_O_OPCODE* __interprete(const char* codes); 156 157 #endif /* oointerpreter_h */
目前还在修复bug中,c文件等到确认无误后再放出来……