From fec15bc50bff7c2d99e1729fc8d5bb6261345cf0 Mon Sep 17 00:00:00 2001 From: KGB99 <80490551+KGB99@users.noreply.github.com> Date: Tue, 16 Jul 2024 18:24:35 +0100 Subject: [PATCH] lex body statements inside do while loops (#4516) --- integration_tests/CMakeLists.txt | 1 + integration_tests/while_03.f90 | 23 +++++++++++++++++++++ src/lfortran/parser/fixedform_tokenizer.cpp | 4 +--- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 integration_tests/while_03.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 71847f7002..71ede8fa1f 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -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) diff --git a/integration_tests/while_03.f90 b/integration_tests/while_03.f90 new file mode 100644 index 0000000000..b7c571c2ed --- /dev/null +++ b/integration_tests/while_03.f90 @@ -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 + diff --git a/src/lfortran/parser/fixedform_tokenizer.cpp b/src/lfortran/parser/fixedform_tokenizer.cpp index f54fe39f6e..b6c79e362a 100644 --- a/src/lfortran/parser/fixedform_tokenizer.cpp +++ b/src/lfortran/parser/fixedform_tokenizer.cpp @@ -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); @@ -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); @@ -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);