Fortran one-line toy interpreter

I uploaded to GitHub an interactive console program FortranShell that runs on Windows and Linux, where you enter code and then enter run, which causes the code to be saved to a file, compiled with gfortran, and run, with output appearing within the program. You can enter more code and then run again. I think it is fun for experimenting with Fortran, and it could be enhanced to link to compiled libraries such as Lapack and stdlib and become more useful.

A sample session is

c:\fortran\test>fedit.exe
> print*,2**5;
          32
> del
> imp
> integer :: i
> do i=1,4
> print*,i,i**2
> end do
> list
1: implicit none
2: integer :: i
3: do i=1,4
4: print*,i,i**2
5: end do
> run
           1           1
           2           4
           3           9
           4          16
> q
STOP done -- code saved in temp.f90

The help lists some features:

 enter a line of Fortran code. Otherwise, ...
 quit or q to quit
 run or r to compile and run executable
 a line of code terminated by ; causes the program to be compiled and run
 runold or ro to run executable again without recompiling
 compile to compile without running executable
 list or l for a program listing with line numbers
 barelist or bl for a program listing without line numbers
 del to delete all code; del i to delete line i ; del i j to delete lines i to j
 line n <code> to replace the current line n with <code>
 insert n <code> to move lines n on down by 1 and put <code> on line n
 imp is expanded to implicit none

Running fedit.exe main.f90 would import main.f90 instead of starting from scratch.

1 Like