diff --git a/port/linux/test/mem_pool_config.c b/port/linux/test/mem_pool_config.c index 130736bb0..7c590cd92 100644 --- a/port/linux/test/mem_pool_config.c +++ b/port/linux/test/mem_pool_config.c @@ -1,6 +1,6 @@ #include "dataMemory.h" -#define use_const_pool 1 +#define use_const_pool 0 #define use_dynamic_pool 0 #define pika_aline 8 diff --git a/port/linux/test/parse-test.cpp b/port/linux/test/parse-test.cpp index 349d084a8..98bdd1a9d 100644 --- a/port/linux/test/parse-test.cpp +++ b/port/linux/test/parse-test.cpp @@ -862,9 +862,35 @@ TEST(lexser, operator_not) { /* run */ char* tokens = Lexer_getTokens(buffs, (char*)"not not not "); char* printTokens = Lexer_printTokens(buffs, tokens); - + /* assert */ - EXPECT_STREQ(printTokens, "notnotnot"); + EXPECT_STREQ(printTokens, "[opt]not[opt]not[opt]not"); + + /* deinit */ + args_deinit(buffs); + EXPECT_EQ(pikaMemNow(), 0); +} + +TEST(lexser, operator_all) { + /* init */ + pikaMemInfo.heapUsedMax = 0; + Args* buffs = New_strBuff(); + + /* run */ + char* tokens = Lexer_getTokens(buffs, (char*) + "not or and " + "+ += - -=" + "* ** *= **=" + "/ // /= //=" + "% %= = == !=" + "> >= >>" + "< <= <<" + ); + char* printTokens = Lexer_printTokens(buffs, tokens); + printf((char*)"%s\n", printTokens); + + /* assert */ + EXPECT_STREQ(printTokens, "[opt]not[opt]or[opt]and[opt]+[opt]+=[opt]-[opt]-=[opt]*[opt]**[opt]*=[opt]**=[opt]/[opt]//[opt]/=[opt]//=[opt]%[opt]%=[opt]=[opt]==[opt]!=[opt]>[opt]>=[opt]>>[opt]<[opt]<=[opt]<<"); /* deinit */ args_deinit(buffs); diff --git a/src/PikaParser.c b/src/PikaParser.c index 5f047288d..30298c424 100644 --- a/src/PikaParser.c +++ b/src/PikaParser.c @@ -181,7 +181,7 @@ char* Lexer_printTokens(Args* outBuffs, char* tokens) { for (int i = 0; i < tokenSize; i++) { char* token = strsPopToken(buffs, tokens, ' '); if (token[0] == TOKEN_operator) { - printOut = strsAppend(buffs, printOut, ""); + printOut = strsAppend(buffs, printOut, "[opt]"); printOut = strsAppend(buffs, printOut, token + 1); } } @@ -229,6 +229,150 @@ char* Lexer_getTokens(Args* outBuffs, char* stmt) { if (i + 3 < size) { c3 = stmt[i + 3]; } + // + + if ('+' == c0) { + /* += */ + if ('=' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "+="); + i = i + 1; + continue; + } + /* + */ + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "+"); + continue; + } + // - + if ('-' == c0) { + /* -= */ + if ('=' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "-="); + i = i + 1; + continue; + } + /* - */ + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "-"); + continue; + } + // * + if ('*' == c0) { + // **= + if (('*' == c1) && ('=' == c2)) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "**="); + i = i + 2; + continue; + } + // *= + if ('=' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "*="); + i = i + 1; + continue; + } + if ('*' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "**"); + i = i + 1; + continue; + } + // * + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "*"); + continue; + } + // = + if ('=' == c0) { + /* == */ + if ('=' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "=="); + i = i + 1; + continue; + } + /* = */ + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "="); + continue; + } + + // > + if ('>' == c0) { + // >= + if ('=' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, ">="); + i = i + 1; + continue; + } + // >> + if ('>' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, ">>"); + i = i + 1; + continue; + } + // > + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, ">"); + continue; + } + + // < + if ('<' == c0) { + // <= + if ('=' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "<="); + i = i + 1; + continue; + } + // << + if ('<' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "<<"); + i = i + 1; + continue; + } + // < + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "<"); + continue; + } + + + + // / + if ('/' == c0) { + // //= + if (('/' == c1) && ('=' == c2)) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "//="); + i = i + 2; + continue; + } + // /= + if ('=' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "/="); + i = i + 1; + continue; + } + if ('/' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "//"); + i = i + 1; + continue; + } + // / + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "/"); + continue; + } + // % + if ('%' == c0) { + /* %= */ + if ('=' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "%="); + i = i + 1; + continue; + } + /* % */ + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "%"); + continue; + } + // != + if ('!' == c0) { + /* != */ + if ('=' == c1) { + tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "!="); + i = i + 1; + continue; + } + } /* not */ if ('n' == c0) { if (('o' == c1) && ('t' == c2) && (' ' == c3)) { @@ -253,72 +397,6 @@ char* Lexer_getTokens(Args* outBuffs, char* stmt) { continue; } } - if ('+' == c0) { - /* += */ - if ('=' == c1) { - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "+="); - i = i + 2; - continue; - } - /* + */ - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "+"); - continue; - } - if ('-' == c0) { - /* -= */ - if ('=' == c1) { - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "-="); - i = i + 2; - continue; - } - /* - */ - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "-"); - continue; - } - if ('*' == c0) { - // **= - if (('*' == c1) && ('=' == c2)) { - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "**="); - i = i + 3; - continue; - } - // *= - if ('=' == c1) { - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "*="); - i = i + 2; - continue; - } - if ('*' == c1) { - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "**"); - i = i + 2; - continue; - } - // * - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "*"); - continue; - } - if ('/' == c0) { - // //= - if (('/' == c1) && ('=' == c2)) { - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "//="); - i = i + 3; - continue; - } - // /= - if ('=' == c1) { - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "/="); - i = i + 2; - continue; - } - if ('/' == c1) { - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "//"); - i = i + 2; - continue; - } - // / - tokens = Lexer_setToken(buffs, tokens, TOKEN_operator, "/"); - continue; - } } tokens = strsCopy(outBuffs, tokens); args_deinit(buffs);