@@ -80,9 +80,7 @@ void error_statement(struct basic_ctx* ctx)
8080
8181void if_statement (struct basic_ctx * ctx )
8282{
83- if (debug ) {
84- dprintf ("line %ld if_statement\n" , ctx -> current_linenum );
85- }
83+ if (debug ) dprintf ("line %ld if_statement\n" , ctx -> current_linenum );
8684
8785 accept_or_return (IF , ctx );
8886 bool r = conditional (ctx );
@@ -93,16 +91,15 @@ void if_statement(struct basic_ctx* ctx)
9391 if (tokenizer_token (ctx ) == NEWLINE ) {
9492 /* Multi-statement block IF */
9593 accept_or_return (NEWLINE , ctx );
96- ctx -> if_nest_level ++ ;
9794 return ;
9895 }
9996 statement (ctx );
10097 } else {
10198 if (debug ) dprintf ("conditional is false\n" );
10299
103100 if (tokenizer_token (ctx ) == NEWLINE ) {
104- /* --- FIXED: multiline false-branch with proper nesting --- */
105- /* Enter the block and scan forward once, respecting nested multiline IFs. */
101+ /* --- multiline false-branch with nesting --- */
102+ /* Enter the block and scan forward once, respecting nested multiline IFs */
106103 accept_or_return (NEWLINE , ctx );
107104
108105 int depth = 0 ;
@@ -111,21 +108,15 @@ void if_statement(struct basic_ctx* ctx)
111108
112109 /* Detect nested multiline IF: IF ... THEN NEWLINE */
113110 if (t == IF ) {
114- /* Look ahead to see if this IF starts a multiline block. */
115- const char * save_ptr = ctx -> ptr ;
116- const char * save_nextptr = ctx -> nextptr ;
117- int save_tok = ctx -> current_token ;
118111
119- /* Advance until THEN or end-of-line/input. */
120- int saw_then = 0 ;
112+ /* Advance until THEN or end-of-line/input */
121113 for (;;) {
122114 tokenizer_next (ctx );
123115 int tt = tokenizer_token (ctx );
124116 if (tt == THEN ) {
125- saw_then = 1 ;
126117 tokenizer_next (ctx );
127118 tt = tokenizer_token (ctx );
128- /* Multiline only if THEN is immediately followed by NEWLINE. */
119+ /* Multiline only if THEN is immediately followed by NEWLINE */
129120 if (tt == NEWLINE ) {
130121 depth ++ ;
131122 }
@@ -135,48 +126,45 @@ void if_statement(struct basic_ctx* ctx)
135126 break ;
136127 }
137128 }
138- /* Continue scanning from current position (no rewind). */
129+ /* Continue scanning from current position (no rewind) */
139130 continue ;
140131 }
141132
142- /* At our depth, ELSE NEWLINE starts the else-block. */
133+ /* At our depth, ELSE NEWLINE starts the else-block */
143134 if (t == ELSE ) {
144135 tokenizer_next (ctx );
145136 if (depth == 0 && tokenizer_token (ctx ) == NEWLINE ) {
146- ctx -> if_nest_level ++ ;
147137 accept_or_return (NEWLINE , ctx );
148138 return ;
149139 }
150- /* ELSE on the same line (single-line IF) or nested: ignore and continue. */
140+ /* ELSE on the same line (single-line IF) or nested: ignore and continue */
151141 continue ;
152142 }
153143
154- /* At our depth, ENDIF NEWLINE ends the whole IF without an else. */
144+ /* At our depth, ENDIF NEWLINE ends the whole IF without an else */
155145 if (t == ENDIF ) {
156146 tokenizer_next (ctx );
157147 if (depth == 0 ) {
158148 accept_or_return (NEWLINE , ctx );
159149 return ;
160150 }
161- /* Close one nested multiline IF. */
151+ /* Close one nested multiline IF */
162152 depth -- ;
163153 continue ;
164154 }
165155
166- /* Any other token: just keep scanning. */
156+ /* Any other token: just keep scanning */
167157 tokenizer_next (ctx );
168158 }
169159
170- /* Reached end of input without matching ENDIF: treat as end of block. */
160+ /* Reached end of input without matching ENDIF: treat as end of block */
171161 return ;
172162 }
173163
174- /* Single-line IF ... THEN <stmt> [ELSE <stmt>] (original behaviour). */
164+ /* Single-line IF ... THEN <stmt> [ELSE <stmt>] */
175165 do {
176166 tokenizer_next (ctx );
177- } while (tokenizer_token (ctx ) != ELSE &&
178- tokenizer_token (ctx ) != NEWLINE &&
179- tokenizer_token (ctx ) != ENDOFINPUT );
167+ } while (tokenizer_token (ctx ) != ELSE && tokenizer_token (ctx ) != NEWLINE && tokenizer_token (ctx ) != ENDOFINPUT );
180168
181169 if (tokenizer_token (ctx ) == ELSE ) {
182170 tokenizer_next (ctx );
@@ -329,12 +317,8 @@ void until_statement(struct basic_ctx* ctx)
329317
330318void endif_statement (struct basic_ctx * ctx )
331319{
332- if (ctx -> if_nest_level == 0 ) {
333- tokenizer_error_print (ctx , "ENDIF outside of block IF" );
334- }
335320 accept_or_return (ENDIF , ctx );
336321 accept_or_return (NEWLINE , ctx );
337- ctx -> if_nest_level -- ;
338322}
339323
340324void end_statement (struct basic_ctx * ctx )
0 commit comments