mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
OPT for < and while is ok
This commit is contained in:
parent
53ba6273a9
commit
347dd331bb
@ -558,4 +558,36 @@ TEST(parser, add_a_pp) {
|
||||
"0 OUT a\n");
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(parser, while_a_pp) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
Args* buffs = New_strBuff();
|
||||
char* lines = (char*)
|
||||
"while a < 10:\n"
|
||||
" print(a)\n"
|
||||
" a = a + 1\n"
|
||||
"\n";
|
||||
printf("%s", lines);
|
||||
char* pikaAsm = pikaParseMultiLineToAsm(buffs, (char*)lines);
|
||||
printf("%s", pikaAsm);
|
||||
EXPECT_STREQ(pikaAsm,
|
||||
"B0\n"
|
||||
"1 REF a\n"
|
||||
"1 NUM 10\n"
|
||||
"0 OPT <\n"
|
||||
"0 JEZ 2\n"
|
||||
"B1\n"
|
||||
"1 REF a\n"
|
||||
"0 RUN print\n"
|
||||
"B1\n"
|
||||
"1 REF a\n"
|
||||
"1 NUM 1\n"
|
||||
"0 OPT +\n"
|
||||
"0 OUT a\n"
|
||||
"B0\n"
|
||||
"0 JMP -1\n"
|
||||
"B0\n");
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
@ -80,6 +80,9 @@ static enum StmtType matchStmtType(char* right) {
|
||||
if (strIsContain(rightWithoutSubStmt, '+') ||
|
||||
strIsContain(rightWithoutSubStmt, '-') ||
|
||||
strIsContain(rightWithoutSubStmt, '*') ||
|
||||
strIsContain(rightWithoutSubStmt, '<') ||
|
||||
strIsContain(rightWithoutSubStmt, '>') ||
|
||||
strIsContain(rightWithoutSubStmt, '=') ||
|
||||
strIsContain(rightWithoutSubStmt, '/')) {
|
||||
stmtType = OPERATOR;
|
||||
goto exit;
|
||||
@ -148,6 +151,15 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
|
||||
if (strIsContain(rightWithoutSubStmt, '/')) {
|
||||
operator[0] = '/';
|
||||
}
|
||||
if (strIsContain(rightWithoutSubStmt, '<')) {
|
||||
operator[0] = '<';
|
||||
}
|
||||
if (strIsContain(rightWithoutSubStmt, '>')) {
|
||||
operator[0] = '>';
|
||||
}
|
||||
if (strIsContain(rightWithoutSubStmt, '=')) {
|
||||
operator[0] = '==';
|
||||
}
|
||||
obj_setStr(ast, (char*)"operator", operator);
|
||||
char* rightBuff = strsCopy(buffs, right);
|
||||
char* subStmt1 = strsPopToken(buffs, rightBuff, operator[0]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user