ofc icon indicating copy to clipboard operation
ofc copied to clipboard

Parser not able to handle Hollerith constants with whitespaces

Open dmikushin opened this issue 1 year ago • 4 comments

This code is actually valid:

Error:./ktshld.f:121,30:
   Invalid initializer
      DATA    BLANK , NAME  / 4H    , 4HTRSH, 4HL     /
                              ^

because Hollerith constants may have whitespaces, and they are unquoted. This is one spectacular piece of Fortran, which exists to confuse the whitespace-based tokenizers.

dmikushin avatar Nov 21 '23 12:11 dmikushin

The code for this is here: https://github.com/CodethinkLabs/ofc/blob/b69ad37be62d580eabeb081e64b43afe3c0b3384/src/parse/literal.c#L218

The call ofc_sparse_parent_pointer gets a pointer to the source without the spaces removed, so the code should handle holleriths with spaces in.

This tool does not tokenize or use whitespace in that way at all, it removes all whitespace before parsing as tokenizing legacy fortran is not possible, however it keeps a reference to the original source for situations like this, and for reporting error locations.

ben-brewer-codethink avatar Nov 21 '23 12:11 ben-brewer-codethink

I should further note that this is failing during semantic analysis which should mean that the hollerith was parsed without issue.

The specific error message is here: https://github.com/CodethinkLabs/ofc/blob/b69ad37be62d580eabeb081e64b43afe3c0b3384/src/sema/lhs.c#L2090

ben-brewer-codethink avatar Nov 21 '23 13:11 ben-brewer-codethink

Would it be possible to get a minimal test which triggers this issue?

ben-brewer-codethink avatar Nov 29 '23 11:11 ben-brewer-codethink

Hi @ben-brewer-codethink , I apologize that I won't be able to really minimize the test cases. But as you said the problem should be straight-forward. I'm attaching the original source file mentioned above, FYI it's a part of NASTRAN-95 distribution:

ktshld.f.gz

dmikushin avatar Nov 29 '23 12:11 dmikushin