lfortran / lfortran

Official main repository for LFortran
https://lfortran.org/
Other
958 stars 155 forks source link

Fail to parse label on declaration statement #5353

Open pjh40 opened 2 days ago

pjh40 commented 2 days ago

Attempting to parse

subroutine foo
100 integer x
end subroutine foo

with LFortran SHA 4068df32ee4 gives the error:

syntax error: Token 'x' (of type 'identifier') is unexpected here
 --> func.f90:2:13
  |
2 | 100 integer x
  |             ^ 

Section 6.2.5 "Statement labels" of the the F23 standard states:

Any statement that is not part of another statement [,deprecated comment,] may begin with a statement label...

This syntax is supported by GCC.

certik commented 1 day ago

I see --- I wasn't sure if you can put labels before declaration statements also. I think we need to first fix #5273, and then it should be easy to just allow a label before any statement.

P.S. Is there any usage of labels before declarations? I am assuming you can't "goto" or "enddo" them, so not sure what else I could do with them.

pjh40 commented 1 day ago

No, there is no use of them apart from branch targets or FORMAT statements. The FVCS_95 suites test for it though, so I'd guess we'd encounter them in the wild. Probably had something to do with numbering cards for sorting.