MyHLは、haribote HL-8cを改造したバージョンです。
左シフト演算子を追加
@@ -151,6 +151,7 @@ enum { Divi, Mod, And, + ShiftLeft, ShiftRight, Assign, Ex, @@ -221,6 +222,7 @@ String defaultTokens[] = { "/", "%", "&", + "<<", ">>", "=", "!", @@ -291,6 +293,7 @@ typedef enum { Infix_Mod = 4, Infix_Plus = 5, Infix_Minus = 5, + Infix_ShiftLeft = 6, Infix_ShiftRight = 6, Infix_LesEq = 7, Infix_GtrEq = 7, @@ -319,6 +322,7 @@ Precedence precedenceTable[][2] = { [Divi] = {Infix_Divi, NoPrecedence}, [Mod] = {Infix_Mod, NoPrecedence}, [And] = {Infix_And, NoPrecedence}, + [ShiftLeft] = {Infix_ShiftLeft, NoPrecedence}, [ShiftRight] = {Infix_ShiftRight, NoPrecedence}, [Assign] = {Infix_Assign, NoPrecedence}, [Ex] = {NoPrecedence, Prefix_Ex}, @@ -416,6 +420,7 @@ typedef enum { OpDiv, OpMod, OpBand, + OpShl, OpShr, OpAdd1, OpSub1, @@ -977,6 +982,7 @@ void exec() case OpMod: *icp[1] = *icp[2] % *icp[3]; icp += 5; continue; case OpAdd: *icp[1] = *icp[2] + *icp[3]; icp += 5; continue; case OpSub: *icp[1] = *icp[2] - *icp[3]; icp += 5; continue; + case OpShl: *icp[1] = *icp[2] << *icp[3]; icp += 5; continue; case OpShr: *icp[1] = *icp[2] >> *icp[3]; icp += 5; continue; case OpClt: *icp[1] = *icp[2] < *icp[3]; icp += 5; continue; case OpCle: *icp[1] = *icp[2] <= *icp[3]; icp += 5; continue;
中置演算子を追加
同じ要領で、次の中置演算子を追加しました。
演算子 | トークンコード | 文字列 |
---|---|---|
ビットXOR演算子 | Xor | "^" |
ビットXOR演算子 | Or | "|" |
論理AND演算子 | AndAnd | "&&" |
論理OR演算子 | OrOr | "||" |
中置演算子は、決まった場所に決まった内容を書くだけで追加できます。
ビットXOR演算子を追加する際は、lexer()を一部変更して"^"に対応する必要があります。
@@ -113,8 +113,8 @@ int lexer(String str, int *tc) while (isAlphabet(str[pos + len]) || isNumber(str[pos + len])) ++len; } - else if (strchr("=+-*/!%&~|<>?:.#", str[pos]) != NULL) { - while (strchr("=+-*/!%&~|<>?:.#", str[pos + len]) != NULL && str[pos + len] != 0) + else if (strchr("=+-*/!%&~^|<>?:.#", str[pos]) != NULL) { + while (strchr("=+-*/!%&~^|<>?:.#", str[pos + len]) != NULL && str[pos + len] != 0) ++len; } else if (str[pos] == '"') { // 文字列