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

Line continuations for strings in Fortran77Legacy #108

Open
ccotter opened this issue Sep 6, 2019 · 3 comments
Open

Line continuations for strings in Fortran77Legacy #108

ccotter opened this issue Sep 6, 2019 · 3 comments

Comments

@ccotter
Copy link

ccotter commented Sep 6, 2019

Lexing

      program foo1
          print *,"hi
     .            there"
      endprogram

with Fortran77Legacy yields the token TString (2:19)-(3:24) "hi\n . there"

Apparently this compiles this gfortran gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC) and emits

$ ./line-continuation
 hi                                                               there

At the very least, I don't the line continuation character . or newline \n should appear in the token, although I'm not exactly sure what the string should be, specifically, how many blanks ought to be in the token string.

@dorchard
Copy link
Member

dorchard commented Sep 6, 2019

Interesting. I've never seen this before. Do you know where this particular style of continuation line came from? The gfortran behaviour is not really what I would expect! I agree that it seems we haven't quite got the representation right here, but I'm not quite sure exactly what representation to use. I count 12 spaces between the period and 'there' in the code, but 62 spaces between 'hi' and 'there' in the output. Weird! At least our token shows that this must have come from a continuation line (because the source span crosses two lines) but it also doesn't seem to be capturing the right number of spaces either (and could conflate various different source programs into this representation).

@dorchard
Copy link
Member

dorchard commented Sep 6, 2019

Okay. I recounted more carefully. There are actually 63 spaces between hi and there in the output. According to the Fortran standard, line lengths should be at most 72 characters long. In the source you provided, the hi finishes at character 21 and the number of spaces between the . and there is 12. So I think one of either two things is happening:

  1. Your source file includes spaces up to character 72 which means there are 72-21 = 51 spaces on that line, which with the 12 spaces on the next line, gives us the 63 spaces seen in the output.
  2. gfortran is interpreting . to mean that it should add these additional spaces up to the maximum line length itself.

What do you think? How many spaces are after hi in the source file you tried?

@dorchard
Copy link
Member

dorchard commented Jun 4, 2020

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants