Break and continue keywords are working

This commit is contained in:
2022-08-20 20:08:22 +01:00
parent daceaa5492
commit 18c5fb6add
7 changed files with 194 additions and 35 deletions

View File

@@ -985,6 +985,20 @@ static void forStmt(Parser* parser, Node** nodeHandle) {
emitNodePath(nodeHandle, NODE_PATH_FOR, preClause, postClause, condition, thenPath, NULL);
}
static void breakStmt(Parser* parser, Node** nodeHandle) {
freeNode(*nodeHandle);
emitNodePath(nodeHandle, NODE_PATH_BREAK, NULL, NULL, NULL, NULL, NULL);
consume(parser, TOKEN_SEMICOLON, "Expected ';' at end of break statement");
}
static void continueStmt(Parser* parser, Node** nodeHandle) {
freeNode(*nodeHandle);
emitNodePath(nodeHandle, NODE_PATH_CONTINUE, NULL, NULL, NULL, NULL, NULL);
consume(parser, TOKEN_SEMICOLON, "Expected ';' at end of continue statement");
}
//precedence functions
static void expressionStmt(Parser* parser, Node** nodeHandle) {
//BUGFIX: check for empty statements
@@ -1043,6 +1057,18 @@ static void statement(Parser* parser, Node** nodeHandle) {
return;
}
//break
if (match(parser, TOKEN_BREAK)) {
breakStmt(parser, nodeHandle);
return;
}
//continue
if (match(parser, TOKEN_CONTINUE)) {
continueStmt(parser, nodeHandle);
return;
}
//default
expressionStmt(parser, nodeHandle);
}