Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank characters preceding initial left parentheses or in-between of format specification #4040

Closed
gxyd opened this issue May 20, 2024 · 1 comment · Fixed by #4044
Closed
Labels
bug Something isn't working fmt Issues/bugs related to the `lfortran fmt` source code formatter

Comments

@gxyd
Copy link
Contributor

gxyd commented May 20, 2024

Bug Description

Blank characters can precede the initial left parentheses of format specification. E.g. 2 (2I3, I5) is a valid format specification and so is 2 (2I 3, I5), and is to be interpreted the same way as 2(2I3, I5). Below is a screenshot from J3 SD-007r1.pdf (Draft Fortran 2023), pg 288, section 13.2:

Screenshot 2024-05-20 at 2 06 37 PM

Steps to reproduce

For the below Fortran program:

program main
    implicit none
    integer :: i, j
    i = 19
    j = 20
    print 9, i, i + 1, j + 1, i + 2, j + 2
    9 FORMAT (I12, /, ' Dates: ', 2 (2I3, I5))
end program main

on it's execution with LFortran, we get an output an output as below (without any error, but informing of unsupported format " "):

Printing support is not available for   format.
Printing support is not available for   format.
          19
 Dates:  20 21

while on execution of the above program with GFortran we get the below output:

          19
 Dates:  20 21   21 22

while if we try with space between the format specification itself:

program main
    implicit none
    integer :: i, j
    i = 19
    j = 20
    print 9, i, i + 1, j + 1, i + 2, j + 2
    9 FORMAT (I12, /, ' Dates: ', 2 (2I 3, I5)) ! notice the space `2I 3`
end program main

LFortran raises a tokenizer error:

tokenizer error: Token '2' is not recognized in `format` statement
 --> test.f90:1:2
  |
1 | program main
  |  ^ 

which seems to be the correct output.

System information

macbook air m1

@gxyd gxyd added bug Something isn't working fmt Issues/bugs related to the `lfortran fmt` source code formatter labels May 20, 2024
@gxyd
Copy link
Contributor Author

gxyd commented May 20, 2024

I'll look into the issue.

@gxyd gxyd changed the title Blank characters preceding initial left parentheses of format specification Blank characters preceding initial left parentheses or in-between of format specification May 20, 2024
gxyd added a commit to gxyd/lfortran that referenced this issue May 20, 2024
gxyd added a commit to gxyd/lfortran that referenced this issue May 22, 2024
Blank characters may precede the initial left parenthesis of the
format specification and additional blank characters may appear
at any point within the format specification, with no effect on
the interpretation of the format specification.

e.g.; `(I 1 2)` is same as `(I12)` for format specification
and are both valid.

Earlier, we used to raise tokenizer error because of no support
for it

issue was initially raised in lfortran#4040
gxyd added a commit that referenced this issue May 25, 2024
Blank characters may precede the initial left parenthesis of the
format specification and additional blank characters may appear
at any point within the format specification, with no effect on
the interpretation of the format specification.

e.g.; `(I 1 2)` is same as `(I12)` for format specification
and are both valid.

Earlier, we used to raise tokenizer error because of no support
for it

issue was initially raised in #4040
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fmt Issues/bugs related to the `lfortran fmt` source code formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant