diff --git a/port/linux/test/parse-test.cpp b/port/linux/test/parse-test.cpp index 5e1fe73fe..34f8d7965 100644 --- a/port/linux/test/parse-test.cpp +++ b/port/linux/test/parse-test.cpp @@ -1064,4 +1064,39 @@ TEST(parser, pop_by_str) { EXPECT_STREQ((char*)"3(>=)2", token1); EXPECT_STREQ((char*)"29", token2); args_deinit(buffs); -} \ No newline at end of file +} + +TEST(parser, mm) { + pikaMemInfo.heapUsedMax = 0; + Args* buffs = New_strBuff(); + char* lines = (char*)"a = a ** -1\n"; + printf("%s", lines); + char* pikaAsm = Parser_multiLineToAsm(buffs, (char*)lines); + printf("%s", pikaAsm); + EXPECT_STREQ(pikaAsm,(char *) + "B0\n" + "1 REF a\n" + "1 NUM -1\n" + "0 OPT **\n" + "0 OUT a\n" + ); + args_deinit(buffs); + EXPECT_EQ(pikaMemNow(), 0); +} + +TEST(parser, self_inc) { + pikaMemInfo.heapUsedMax = 0; + Args* buffs = New_strBuff(); + char* lines = (char*)"a += -1\n"; + printf("%s", lines); + char* pikaAsm = Parser_multiLineToAsm(buffs, (char*)lines); + printf("%s", pikaAsm); + EXPECT_STREQ(pikaAsm,(char *) + "B0\n" + "1 REF a\n" + "1 NUM -1\n" + "0 OPT +=\n" + ); + args_deinit(buffs); + EXPECT_EQ(pikaMemNow(), 0); +} diff --git a/src/PikaParser.c b/src/PikaParser.c index 4a9c68aaa..b7387ce25 100644 --- a/src/PikaParser.c +++ b/src/PikaParser.c @@ -188,7 +188,9 @@ uint8_t Parser_checkIsDirect(char* str) { /* include '0' */ uint32_t size = strGetSize(str) + 1; for (int i = 1; i + 1 < size; i++) { - if ((str[i - 1] != '=') && (str[i] == '=') && (str[i + 1] != '=')) { + if ((str[i - 1] != '=') && (str[i - 1] != '+') && (str[i - 1] != '-') && + (str[i - 1] != '*') && (str[i - 1] != '/') && (str[i + 1] != '=') && + (str[i] == '=')) { return 1; } } @@ -510,8 +512,8 @@ char* Lexer_getOperator(Args* outBuffs, char* stmt) { "<=", ">", ">=", "!=", "==", "%=", "/=", "//=", "-=", "+=", "*=", "**="}; for (int i = 0; i < sizeof(operators) / 4; i++) { - if (Lexer_isContain(tokens, operators[i])) { - operator= strsCopy(buffs, operators[i]); + if (Lexer_isContain(tokens, (char*)operators[i])) { + operator= strsCopy(buffs, (char*)operators[i]); } } /* out put */