parse for continue is ok

This commit is contained in:
lyon 2021-12-29 21:10:04 +08:00
parent 45ee8621cc
commit fc2e4f2287
2 changed files with 20 additions and 0 deletions

View File

@ -1571,6 +1571,8 @@ TEST(parser, break_) {
" if i = 1:\n"
" break\n"
" break \n"
" continue\n"
" continue \n"
"\n";
printf("%s", lines);
char* pikaAsm = Parser_multiLineToAsm(buffs, (char*)lines);
@ -1601,6 +1603,10 @@ TEST(parser, break_) {
"0 BRK\n"
"B2\n"
"0 BRK\n"
"B2\n"
"0 CTN\n"
"B2\n"
"0 CTN\n"
"B0\n"
"0 JMP -1\n"
"B0\n"

View File

@ -803,6 +803,13 @@ AST* AST_parseLine(char* line, Stack* blockStack) {
goto block_matched;
}
}
if (0 == strncmp(lineStart, (char*)"continue", 8)) {
if ((lineStart[8] == ' ') || (lineStart[8] == 0)) {
obj_setStr(ast, "continue", "");
stmt = "";
goto block_matched;
}
}
if (strEqu(lineStart, (char*)"return")) {
obj_setStr(ast, "return", "");
stmt = "";
@ -1133,6 +1140,13 @@ char* AST_toPikaAsm(AST* ast, Args* buffs) {
is_block_matched = 1;
goto exit;
}
if (obj_isArgExist(ast, "continue")) {
/* parse stmt ast */
pikaAsm = AST_appandPikaAsm(ast, ast, runBuffs, pikaAsm);
pikaAsm = strsAppend(runBuffs, pikaAsm, "0 CTN\n");
is_block_matched = 1;
goto exit;
}
exit:
if (!is_block_matched) {
/* parse stmt ast */