lfortran / lfortran

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

Semantics: Implement correct handling of PARAMETER #389

Open certik opened 2 years ago

certik commented 2 years ago

Original issue: https://gitlab.com/lfortran/lfortran/-/issues/510

Currently parameter statements like the following:

program parameter_01
implicit none
integer :: i, j, k
parameter(i = 1)
parameter(j=2, k=3)
print *, i, j, k
end program

Have no valid ASR representation.

lfortran --show-asr integration_tests/parameter_01.f90
Semantic error: Attribute declaration not supported

Essentially this is a bug on multiple levels, as this parameter is not the attribute at all; but the parameter statement defined in the draft 2018 standard as: image

gnikit commented 1 year ago

FYI a potential additional complication is where implicit none is absent. For example this is valid code

program main
    logical T
    parameter(epsilon=1.0E-6, PI=3.141593, T=.true.)
    print*, epsilon, pi, t
end program main
certik commented 1 year ago

We just implemented implicit typing, so we should have that feature. I think we have almost everything by now, we just have to set the appropriate flag at the ASR level for the variable (or declare it if it is implicitly typed), I think this is quite easy to fix.