@@ -231,6 +231,7 @@ static const char sub_param_fi[] = {'f', 'i'};
231231%token T_DO " do"
232232%token T_WHILE " while"
233233%token T_TIMES " times"
234+ %token T_LOOP " loop"
234235%token T_SWITCH " switch"
235236%token T_CASE " case"
236237%token T_DEFAULT " default"
@@ -657,6 +658,7 @@ Block:
657658 | IfBlock
658659 | WhileBlock
659660 | TimesBlock
661+ | LoopBlock
660662 | SwitchBlock
661663 ;
662664
@@ -677,7 +679,8 @@ BreakStatement:
677679 if (
678680 strncmp (head->data, " while" , 5 ) == 0 ||
679681 strncmp(head->data, " switch" , 6 ) == 0 ||
680- strncmp(head->data, " times" , 5 ) == 0
682+ strncmp(head->data, " times" , 5 ) == 0 ||
683+ strncmp(head->data, " loop" , 4 ) == 0
681684 ) {
682685 char labelstr[256 ];
683686 snprintf (labelstr, 256 , " %s_end" , (char *)head->data );
@@ -698,7 +701,8 @@ ContinueStatement:
698701 for (; head; head = head->next) {
699702 if (
700703 strncmp (head->data, " while" , 5 ) == 0 ||
701- strncmp(head->data, " times" , 5 ) == 0
704+ strncmp(head->data, " times" , 5 ) == 0 ||
705+ strncmp(head->data, " loop" , 4 ) == 0
702706 ) {
703707 char labelstr[256 ];
704708 snprintf (labelstr, 256 , " %s_st" , (char *)head->data );
@@ -871,6 +875,32 @@ TimesBlock:
871875 }
872876 ;
873877
878+ LoopBlock :
879+ " loop" {
880+ char labelstr[250 ];
881+ snprintf (labelstr, 250 , " loop_%i_%i" , yylloc.first_line, yylloc.first_column);
882+ char labelstr_st[256 ];
883+ char labelstr_end[256 ];
884+ snprintf (labelstr_st, 256 , " %s_st" , (char *)labelstr);
885+ snprintf (labelstr_end, 256 , " %s_end" , (char *)labelstr);
886+
887+ list_prepend_new (&state->block_stack, strdup(labelstr));
888+ label_create (state, labelstr_st);
889+ } CodeBlock {
890+ char labelstr_st[256 ];
891+ char labelstr_end[256 ];
892+ list_node_t *head = state->block_stack.head;
893+ snprintf (labelstr_st, 256 , " %s_st" , (char *)head->data);
894+ snprintf (labelstr_end, 256 , " %s_end" , (char *)head->data);
895+
896+ expression_create_goto (state, GOTO, labelstr_st);
897+ label_create (state, labelstr_end);
898+
899+ free (head->data);
900+ list_del (&state->block_stack, head);
901+ }
902+ ;
903+
874904SwitchBlock :
875905 " switch" ' (' ExpressionAny [cond ] ' )' {
876906 char name[256 ];
0 commit comments