Skip to content

Commit

Permalink
lex body statements inside do while loops (lfortran#4516)
Browse files Browse the repository at this point in the history
  • Loading branch information
KGB99 authored Jul 16, 2024
1 parent 0b34868 commit fec15bc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ RUN(NAME if_05 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc cpp wasm c)

RUN(NAME while_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc cpp x86 wasm c)
RUN(NAME while_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc cpp wasm c)
RUN(NAME while_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc wasm EXTRA_ARGS --fixed-form)

RUN(NAME doloop_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc c cpp x86 wasm)
RUN(NAME doloop_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc c cpp x86 wasm)
Expand Down
23 changes: 23 additions & 0 deletions integration_tests/while_03.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
program while_03
implicit none
integer :: n, i, j

i = 0
n = 2

do while ( n >= 2 )
if( n >= i ) then
if( n >= i ) then
do j= i+1,n
i = j + i
end do
endif
n = n - 1
else
i = j + i
endif
end do

return
end

4 changes: 1 addition & 3 deletions src/lfortran/parser/fixedform_tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ struct FixedFormRecursiveDescent {
push_token_advance(cur, "while");
tokenize_line(cur); // tokenize rest of line where `do while` starts
while (!next_is(cur, "enddo\n")) {
tokenize_line(cur);
lex_body_statement(cur);
}
push_token_advance(cur, "enddo");
tokenize_line(cur);
Expand Down Expand Up @@ -1540,7 +1540,6 @@ struct FixedFormRecursiveDescent {
// we can define a global assignment
unsigned char *nline = cur; next_line(nline);
// eat_label(cur);

if (next_is(cur, "include")) {
push_token_advance(cur, "include");
tokenize_line(cur);
Expand Down Expand Up @@ -1587,7 +1586,6 @@ bool FixedFormTokenizer::tokenize_input(diag::Diagnostics &diagnostics, Allocato
f.t.string_start = string_start;
f.t.cur_line = string_start;
f.t.line_num = 1;

f.lex_global_scope(cur);
tokens = std::move(f.tokens);
stypes = std::move(f.stypes);
Expand Down

0 comments on commit fec15bc

Please sign in to comment.