# Testing LFortran's parser and formatter

**URL:** <https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558>\
**Category:** Uncategorized\
**Created:** [July 14, 2021, 4:28am UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558 "2021-07-14T04:28:38Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 14, 2021, 4:28am UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/1 "2021-07-14T04:28:38Z")

</div>

We just released a new version of LFortran 0.11.0. You can install it using Conda:

```auto
conda create -n test1 lfortran=0.11.0
conda activate test1

```

Or you can compile from source. Our GSoC student @ThirumalaiShaktivel has done a tremendous job fixing every bug that we knew about in the parser and we tested it on quite a few codes. Now it’s a good time for the wider community to test it out. If you discover any bugs, please report them here or create an issue at: [Issues · lfortran / lfortran · GitLab](https://gitlab.com/lfortran/lfortran/-/issues).

How to test:

```auto
lfortran fmt some_file.f90

```

If it prints the code back (in color), it works. If you get any kind of errors, it’s a bug in the compiler and we would appreciate it if you let us know about it. You can also replace the original file by `lfortran fmt -i some_file.f90` (be careful, only do this if the original file is checked into git). If you compile the reformatted code with another Fortran compiler, it should compile and run correctly.

We are aware of the following issues, that we will fix soon:

- comments are currently skipped (this includes pragmas like openmp)
- empty lines are skipped
- the location information can sometimes be incorect in AST (so when you get a syntax error, the line/column number might not be accurate)

If you discover anything else, please let us know.

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [July 14, 2021, 7:24am UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/2 "2021-07-14T07:24:02Z")

</div>

Thanks, this is really cool. I just went ahead and tested it on all my Fortran source with

```auto
for i in $(fd '\.f90$' .); do lfortran fmt $i > /dev/null || echo $i; done

```

It seems to get most of the source I was throwing at it. Already started reporting at the issue tracker for the failures I encountered.

---

<div class="post-metadata">

**Author:** ![icpup](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@icpup](https://fortran-lang.discourse.group/u/icpup)\
**Post date:** [July 14, 2021, 1:14pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/3 "2021-07-14T13:14:40Z")

</div>

I had difficulty to install from source tar ball. I got a cmake error as below, not sure what it relates to.

cmake -DWITH\_LLVM=yes -DCMAKE\_INSTALL\_PREFIX=/usr/local .  
ZLIB\_INCLUDE\_DIR: /usr/include  
ZLIB\_LIBRARY: /usr/lib/libz.a  
CMake Error at cmake/FindZLIB.cmake:7 (add\_library):  
add\_library cannot create imported target “p::zlib” because another target  
with the same name already exists.  
Call Stack (most recent call first):  
/usr/lib64/cmake/llvm/LLVMConfig.cmake:220 (find\_package)  
CMakeLists.txt:83 (find\_package)

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 14, 2021, 1:36pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/4 "2021-07-14T13:36:42Z")

</div>

Thank you everybody, I woke up this morning and saw 12 new bugs to fix!

[https://gitlab.com/lfortran/lfortran/-/issues?label\_name=Parser](https://gitlab.com/lfortran/lfortran/-/issues?label_name=Parser)

and two more issues with the formatter ([Issues · lfortran / lfortran · GitLab](https://gitlab.com/lfortran/lfortran/-/issues?label_name=fmt)). We’ll fix them soon.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 14, 2021, 1:41pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/5 "2021-07-14T13:41:09Z")

</div>

> [@icpup](#):
>
> I had difficulty to install from source tar ball. I got a cmake error as below, not sure what it relates to.
> 
> cmake -DWITH\_LLVM=yes -DCMAKE\_INSTALL\_PREFIX=/usr/local .  
> ZLIB\_INCLUDE\_DIR: /usr/include  
> ZLIB\_LIBRARY: /usr/lib/libz.a  
> CMake Error at cmake/FindZLIB.cmake:7 (add\_library):  
> add\_library cannot create imported target “p::zlib” because another target  
> with the same name already exists.  
> Call Stack (most recent call first):  
> /usr/lib64/cmake/llvm/LLVMConfig.cmake:220 (find\_package)  
> CMakeLists.txt:83 (find\_package)

I think this error was fixed by @awvwgk recently ([Use CMake's built-in zlib finder (!1044) · Merge requests · lfortran / lfortran · GitLab](https://gitlab.com/lfortran/lfortran/-/merge_requests/1044)). There is no `FindZLIB.cmake` file anymore. Can you try to use the 0.11.0 release? Either latest master or the source tarball from [Download -](https://lfortran.org/download/). Also, make sure you use LLVM version 11, not 12. We have not upgraded to LLVM 12 yet.

Btw, to just test the parser and formatter, you don’t need LLVM so you can compile with `-DWITH_LLVM=no`.

---

<div class="post-metadata">

**Author:** ![icpup](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@icpup](https://fortran-lang.discourse.group/u/icpup)\
**Post date:** [July 14, 2021, 6:26pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/6 "2021-07-14T18:26:30Z")

</div>

Thanks. I tried 0.11.0 release. CMake is OK, but make failed

[55%] Building CXX object src/lfortran/CMakeFiles/lfortran\_lib.dir/codegen/llvm\_array\_utils.cpp.o

In file included from /home/XX/lfortran-0.11.0/src/lfortran/codegen/evaluator.cpp:44:  
/home/XX/lfortran-0.11.0/src/lfortran/codegen/KaleidoscopeJIT.h:22:10: fatal error: llvm/ExecutionEngine/Orc/LambdaResolver.h: No such file or directory  
22 | #include “llvm/ExecutionEngine/Orc/LambdaResolver.h”  
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
compilation terminated.  
make[2]: \*\*\* [src/lfortran/CMakeFiles/lfortran\_lib.dir/build.make:496: src/lfortran/CMakeFiles/lfortran\_lib.dir/codegen/evaluator.cpp.o] Error 1  
make[2]: \*\*\* Waiting for unfinished jobs…  
make[1]: \*\*\* [CMakeFiles/Makefile2:317: src/lfortran/CMakeFiles/lfortran\_lib.dir/all] Error 2  
make: \*\*\* [Makefile:166: all] Error 2

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 14, 2021, 11:44pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/7 "2021-07-14T23:44:08Z")

</div>

> [@icpup](#):
>
> Thanks. I tried 0.11.0 release. CMake is OK, but make failed
> 
> [55%] Building CXX object src/lfortran/CMakeFiles/lfortran\_lib.dir/codegen/llvm\_array\_utils.cpp.o
> 
> In file included from /home/XX/lfortran-0.11.0/src/lfortran/codegen/evaluator.cpp:44:  
> /home/XX/lfortran-0.11.0/src/lfortran/codegen/KaleidoscopeJIT.h:22:10: fatal error: llvm/ExecutionEngine/Orc/LambdaResolver.h: No such file or directory  
> 22 | #include “llvm/ExecutionEngine/Orc/LambdaResolver.h”  
> | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I think you are using LLVM 12. You have to use LLVM 11, we have not ported to LLVM 12 yet. Or compile without LLVM, see above how to do it.

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [July 15, 2021, 8:19am UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/8 "2021-07-15T08:19:54Z")

</div>

In my case the lfortran package could not be found (probably I would have to update the conda channels first):

```nohighlight
$ conda create -n test1 lfortran=0.11.0
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - lfortran=0.11.0

...

```

However a two-step procedure (1 - create environement, 2 - install package) worked:

```auto
$ conda create -n test1
$ conda activate test1
$ conda install -c conda-forge lfortran 

```

---

<div class="post-metadata">

**Author:** ![epagone](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/epagone/32/252_2.png) [@epagone](https://fortran-lang.discourse.group/u/epagone)\
**Post date:** [July 15, 2021, 9:25am UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/9 "2021-07-15T09:25:39Z")

</div>

@certik would it be complicated to provide single file binaries for end-users for all typical platforms (like it is currently done for `fpm`) to lower the barrier?

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 15, 2021, 11:54am UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/10 "2021-07-15T11:54:49Z")

</div>

> [@ivanpribec](#):
>
> However a two-step procedure (1 - create environement, 2 - install package) worked:
> 
> ```auto
> $ conda create -n test1
> $ conda activate test1
> $ conda install -c conda-forge lfortran 
> 
> ```

Or you can do in one step:

```auto
conda create -n test1 -c conda-forge lfortran
conda activate test1

```

Yes, I forgot to add to use `conda-forge`. It is enabled by default for me.

> [@epagone](#):
>
> @certik would it be complicated to provide single file binaries for end-users for all typical platforms (like it is currently done for `fpm` ) to lower the barrier?

It would not be complicated — in fact we already do precisely that for Linux, you can find the latest one here:

[https://gitlab.com/lfortran/lfortran/-/jobs/1426090202/artifacts/browse/lfortran-0.11.0-59-g9fec843b/](https://gitlab.com/lfortran/lfortran/-/jobs/1426090202/artifacts/browse/lfortran-0.11.0-59-g9fec843b/)

But I have not tested it for this release yet. If anyone wants to help us set this up for macOS and Windows also, we would really appreciate it.

---

<div class="post-metadata">

**Author:** ![epagone](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/epagone/32/252_2.png) [@epagone](https://fortran-lang.discourse.group/u/epagone)\
**Post date:** [July 15, 2021, 12:04pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/11 "2021-07-15T12:04:09Z")

</div>

> [@certik](#):
>
> …in fact we already do precisely that for Linux, you can find the latest one here…

Fantastic, thank you. I’m a Linux user, I will try it as soon as I can.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 15, 2021, 1:53pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/12 "2021-07-15T13:53:24Z")

</div>

> [@epagone](#):
>
> Fantastic, thank you. I’m a Linux user, I will try it as soon as I can.

Please report any bugs. Here is the place that builds it:

- [.gitlab-ci.yml · 69443adbca0645b68c3d02d819984b8585566f92 · lfortran / lfortran · GitLab](https://gitlab.com/lfortran/lfortran/-/blob/69443adbca0645b68c3d02d819984b8585566f92/.gitlab-ci.yml#L68)

Here is the relevant part of the CMake build system that builds the binary tarball using `cpack`:

- [CMakeLists.txt · 69443adbca0645b68c3d02d819984b8585566f92 · lfortran / lfortran · GitLab](https://gitlab.com/lfortran/lfortran/-/blob/69443adbca0645b68c3d02d819984b8585566f92/CMakeLists.txt#L39)

I think the binary is not tested at the CI, so we should add a test for it (to unpack it and run some example say in the latest Ubuntu docker image) and then we should set it up to upload somewhere and link to it at [Download -](https://lfortran.org/download/), just like we handle source tarballs there already.

---

<div class="post-metadata">

**Author:** ![epagone](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/epagone/32/252_2.png) [@epagone](https://fortran-lang.discourse.group/u/epagone)\
**Post date:** [July 15, 2021, 5:34pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/13 "2021-07-15T17:34:55Z")

</div>

The `lfortran` binary worked really well out of the box (i.e. extract and run). Thanks!

I have uncovered a couple of bugs that I have reported on GitLab, as instructed.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 15, 2021, 5:58pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/14 "2021-07-15T17:58:54Z")

</div>

I saw them, thank you! Thanks also for trying it.

---

<div class="post-metadata">

**Author:** ![icpup](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@icpup](https://fortran-lang.discourse.group/u/icpup)\
**Post date:** [July 15, 2021, 10:16pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/15 "2021-07-15T22:16:01Z")

</div>

I have tried a simple test program in both lfortran terminal and jupyter notebook. On terminal, the Enter to submit is awkward. People usually use Enter to make a new line in source file. On jupyter, running a cell once is ok, but the 2nd time raises “semantic error: Program already defined”

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [July 16, 2021, 12:43am UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/16 "2021-07-16T00:43:39Z")

</div>

I have limited time to try it, but I made a script to pull all registered fpm packages and then use lfortran as the compiler via a little wrapper script and flag actual errors and eliminated obvious duplicates. Generally looked very promising, but had a few interesting outputs using -i on all the packages that might be related to these files with actual failures so just bundled these up in a tar file first. I am sure some are still duplicates, but I think it will still be useful, as that is the result of thousands of files from a good number of authors using significantly different programming styles (so even there is a decent number here it is quite good, and a higher percentage succeeded than with ifx, but that is not quite fair because ifx does not do BLOCK yet and allocatable CHARACTER arrays of allocatable length, which was the majority of ifx(1) issues, as that is commonly used in this set):

```bash
wget http://www.urbanjost.altervista.org/REMOVE/lfortran_error.tgz 
#or
curl --output lfortran_error.tgz http://www.urbanjost.altervista.org/REMOVE/lfortran_error.tgz 

```

hopefully I will have time to do this a little more formally as bug reports but that will be a while and I think this will be useful now(?).

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 16, 2021, 1:42am UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/17 "2021-07-16T01:42:37Z")

</div>

> [@icpup](#):
>
> I have tried a simple test program in both lfortran terminal and jupyter notebook. On terminal, the Enter to submit is awkward. People usually use Enter to make a new line in source file.

Thanks for trying it! What key would you find more natural to submit the cell? IPython, Python and Julia also use Enter I believe, so we used the same key. But we can change it.

> [@icpup](#):
>
> On jupyter, running a cell once is ok, but the 2nd time raises “semantic error: Program already defined”

You probably tried a program. Yes, we have to make redefinitions work still. In this thread I am only asking to test the parser, not the rest of the compiler, as we are still working on implementing enough features before we release the MVP. You can test the parser with `lfortran fmt`.

> [@urbanjost](#):
>
> `wget http://www.urbanjost.altervista.org/REMOVE/lfortran_error.tgz `

Awesome, thank you @urbanjost! Note that the `gcp.f90` is already fixed in master, but some of the other ones still don’t work. We’ll fix it soon. @ThirumalaiShaktivel, would you mind please taking the tarball and reporting all errors in there? It contains a list of `.f90` files that failed with the last release.

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [July 16, 2021, 1:48pm UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/18 "2021-07-16T13:48:05Z")

</div>

Great it that was useful, fmt\_i.tgz in the same directory might be useful, although I admit I have not looked through it yet myself. It is the before and after copies of the files that compiled before reformatting with “-i” but did not after. At least one of them has to do with a discussion I had in the past about unary operators and complex constants (changing “(-3.0, 4.0)” to “(-(3.0),4.0)” ) is non-standard. Who would have thought?

PS:  
making a \_scratch directory and pulling all the fpm(1) packages using fpm-search is pretty straight-forward, and gives you a lot of tests already in git(1). I use that a lot for testing fpm(1).  
What is a kluge but handy is to create an “lf” compiler command and using it as the compiler on the packages on the fpm(1) command. You want it to keep going on an error. On a ULS if you make a little bash(1) script like

```auto
#!/bin/bash
##################################################
#@(#) call lfortran for formatting and keep going on error
##################################################
(
   FILE=$2
   echo ">>>>lfortran $FILE fmt"
   case "$FILE" in
   *dependencies/*);;
   *.f90|*.F90) 
      # create ANSI color version
      (lfortran fmt $FILE >$FILE.txt|| echo "OUCH $FILE")|xargs
      # actually replace the files with reformatted version
      #(lfortran fmt -i $FILE || echo "OUCH $FILE")|xargs
   ;;
   esac
)
#######################################
exit 0
#######################################

```

you can do a lot of tests, skipping the .c and .f files and not stopping on error. Interesting for testing compilers and fpm or looking for examples of usage

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [August 16, 2021, 11:59am UTC](https://fortran-lang.discourse.group/t/testing-lfortrans-parser-and-formatter/1558/19 "2021-08-16T11:59:55Z")

</div>

Thank you everybody for testing! We believe we have now fixed all reported bugs and it’s time for round 2. I created a new thread for that at [Testing LFortran’s parser and formatter (Round 2)](https://fortran-lang.discourse.group/t/testing-lfortran-s-parser-and-formatter-round-2/1704).
