Ofort interpreter for Fortran

I forked the new CodeBench project (compiler tools for Mac and iPad), extracted just the Fortran interpreter, and increased its coverage of Fortran using Codex, now covering much of Fortran 95 and parts of later standards. The interpreter is written in C and can be compiled with gcc or clang. It’s called ofort because in the original project it was named the OfflinAi Fortran Interpreter. It can be run interactively or with ofort foo.f90 but does not produce stand-alone executables. There is much of Fortran remaining to be covered, but I think it is already interesting to play with.

A sample session is

c:\c\public_domain\github\ofort>ofort
Enter Fortran source.
Commands: . runs, .run [n] [-- args] repeats, .time [n] [-- args] times, .runq [n] [-- args] runs and quits, .quit quits, .clear clears, .del n[:m] deletes lines, .ins n text inserts, .rep n text replaces, .rename old new renames, .list lists, .decl lists declarations, .vars [names] lists values, .info [names] lists details, .shapes [names] lists array shapes, .sizes [names] lists array sizes, .stats [names] lists array stats, .load file loads, .load-run file loads/runs.

ofort> integer, parameter :: n = 10**7
ofort> integer, parameter :: dp = kind(1.0d0)
ofort> real(kind=dp) :: x(n)
ofort> call random_number(x)
ofort> print*,sum(x)/size(x)
ofort> .time 5
0.5000781
0.5001794
0.4998747
0.4998919
0.4998335

   total          avg           sd          min          max
6.210490     1.242098     0.070298     1.176757     1.361660 s

ofort> .shapes
x: 10000000
ofort> q
Saved main.f90
1 Like