Skip to content

Commit

Permalink
fix: Fix continue; statement bug
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvank committed Dec 3, 2024
1 parent df36e97 commit d10cb24
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
37 changes: 22 additions & 15 deletions examples/inp_break.c
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
void printf(char *, ...);

int main() {
int main()
{
int i = 0;
while(1) {
if (i==0) {
while (1)
{
if (i == 0)
{
printf("i is 0\n");
continue;
break;
}
break;
continue;
}

for(int i = 0; i >=0; i = i + 1) {
if (i==0) {
for (int i = 0; i >= 0; i = i + 1)
{
if (i == 0)
{
printf("i is 0\n");
continue;
}
if (i==1) {
if (i == 1)
{
break;
}
}

for(int i = 0; i >=0; i = i + 1) {
for (int i = 0; i <= 10; i = i + 1)
{
// 15
printf("i is %d\n", i);
for (int j = 0; j < 10; j++) {
// 19
for (int j = 0; j < 10; j++)
{
// 19
printf("j is %d\n", j);
if (j == 5) {
if (j == 5)
{
break;
}
}
// 20
break;
}
// 16
// 16

return 0;
}
8 changes: 4 additions & 4 deletions lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ typed_token *eof_token();
#define TKN_OREQ 93
#define TKN_ANDEQ 94
#define TKN_BREAK 96
#define TKN_CONTINUE 96
#define TKN_SWITCH 97
#define TKN_CASE 98
#define TKN_DEFAULT 99
#define TKN_CONTINUE 97
#define TKN_SWITCH 98
#define TKN_CASE 99
#define TKN_DEFAULT 100

#define TKN_COMMENT 128
#define TKN_DIRECTIVE 129
Expand Down
6 changes: 3 additions & 3 deletions parser/break.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ parser_node *parse_break(typed_token **tkns_ptr)
void continue_debug(int depth, parser_node *node)
{
printtabs(depth);
printf("continue\n");
printf("Continue\n");
}

apply_result *continue_apply(parser_node *node, context *ctx)
Expand All @@ -59,8 +59,8 @@ parser_node *parse_continue(typed_token **tkns_ptr)
return NULL;
}
parser_node *continue_node = (parser_node *)malloc(sizeof(parser_node));
continue_node->debug = break_debug;
continue_node->apply = break_apply;
continue_node->debug = continue_debug;
continue_node->apply = continue_apply;
*tkns_ptr = tkn->next->next;
return continue_node;
}
Expand Down

0 comments on commit d10cb24

Please sign in to comment.