ofc
ofc copied to clipboard
Parser not able to handle Hollerith constants with whitespaces
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.
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.
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
Would it be possible to get a minimal test which triggers this issue?
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: