# Emulators and interpreters in Fortran

**URL:** <https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042>\
**Category:** Uncategorized\
**Created:** [January 16, 2023, 9:12pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042 "2023-01-16T21:12:59Z")\
**Posts on this page:** 18\
**Page:** 1

<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:** [January 16, 2023, 9:12pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/1 "2023-01-16T21:12:59Z")

</div>

Fortran is often perceived as a language suitable exclusively for numerical applications and not much else. However, digging a bit into the history I’ve discovered that a few computer emulators were written in Fortran:

- Launched in 1971, the [4004](https://www.intel.de/content/www/de/de/history/museum-story-of-intel-4004.html) was Intel’s first microprocessor. It was part of the MCS-4 micro computer set used in the Busicom electronic calculator (an emulator can be seen [here](https://dutchen18.gitlab.io/emu-rs/)). The index of the [MCS-4 Users Manual](http://www.bitsavers.org/components/intel/MCS4/MCS-4_UsersManual_Feb73.pdf) mentions a MCS-4 Fortran Assembler/Simulator Package. According to [another page](https://en.wikipedia.org/wiki/Talk%3AIntel_4004) this was a cross-assembler running on a PDP-8 and implemented in Fortran IV.
- According to DEC employee Larry McGowan in [How the PDP-11 Was Born](http://www.hampage.hu/pdp-11/birth.html), a simulator called SIM-11 was written for the PDP-10 which was used to test software and early programs before the first [PDP-11](https://en.wikipedia.org/wiki/PDP-11) prototype was built. The PDP-11 was released in 1970.
- In the book _FORTRAN TOOLS: For VAX/VMS and MS-DOS_ (1989), the authors Jones & Crabtree (presumably employed by [Hughes Aircraft Company](https://en.wikipedia.org/wiki/Hughes_Aircraft_Company), later sold to Raytheon) provide listings for a virtual machine used to run a Fortran-like interpreted language called `spl` (simple programming language).
- [SPICE2](https://www2.eecs.berkeley.edu/Pubs/TechRpts/1975/9602.html) was computer program used to simulate semiconductor circuits developed at the Electronics Research Laboratory at the University of California in 1975. I guess it was not an interpreter, however the input decks might be seen as an early example of domain-specific simulation language. SPICE2 is not to be confused with the NASA [SPICE](https://en.wikipedia.org/wiki/Spacecraft_Planet_Instrument_C-matrix_Events) information system. The [Cedar](https://en.wikipedia.org/wiki/Electronic_design_automation) EDA program (briefly named JuliaSPICE?) seems like a descendant of SPICE2 written in Julia. (It appears to be closed-source.)

Are you aware of any other historical emulators or interpreters written in Fortran? Do any of your Fortran programs in use today have an embedded interpreter? In case yes, what do you use it for?

---

<div class="post-metadata">

**Author:** ![jacobwilliams](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jacobwilliams/32/10_2.png) [@jacobwilliams](https://fortran-lang.discourse.group/u/jacobwilliams)\
**Post date:** [January 16, 2023, 9:27pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/2 "2023-01-16T21:27:51Z")

</div>

NASA’s [Copernicus](https://www.nasa.gov/centers/johnson/copernicus/index.html) contains a basic equation parser, which allows the user to input equations that can be included in the optimization problem, without having to compile anything. The parser is written in Fortran, and is similar to [other Fortran equations parsers out there](https://github.com/jacobwilliams/fortran_function_parser#other-codes).

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [January 16, 2023, 9:34pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/3 "2023-01-16T21:34:54Z")

</div>

Does the original MATLAB count? There were copies of it on GitHub but I can’t seem to find one now.

---

<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:** [January 16, 2023, 9:58pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/4 "2023-01-16T21:58:44Z")

</div>

It certainly does. I know @urbanjost has a derived [version](http://www.urbanjost.altervista.org/LIBRARY/EXE/MATLAB88/index.html) of it. Cleve Moler also wrote about in [A History of MATLAB](https://dl.acm.org/doi/10.1145/3386331).

@jacobwilliams, Copernicus looks impressive! I noticed [EIS-2](https://github.com/csbrady-warwick/EIS-2) is missing from your list of equation parsers. It was featured at FortranCon 2020 in the [talk from Christopher Brady](https://tcevents.chem.uzh.ch/event/12/contributions/44/attachments/30/99/Brady.pdf). The book [Illustrating FORTRAN](https://www.cambridge.org/de/academic/subjects/computer-science/programming-languages-and-applied-logic/illustrating-fortran?format=PB&isbn=9780521288101) (1982) also has an exercise on reverse polish notation illustrating the use of stacks.

 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/d/da444fd54ce97150506cbb0222d3379b5272a146.jpeg)

There is also the [Fortran 2018 RPN Calculator](https://github.com/scivision/rpn-calc-fortran) which provides _a lot_ more than just basic arithmetics.

---

<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:** [January 17, 2023, 2:37am UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/5 "2023-01-17T02:37:46Z")

</div>

I have used two interactive FORTRAN77 interpreters written in Fortran but a cursory search  
did not produce any copies of them.

There are at least two scheme interpreters written in Fortran

DISCUS had/has a FORTRAN77-like interpreter

I thought there was a FORTRAN77-like interpreter in ROOT from CERN,  
but if there was it appears to be gone.

Westinghouse had a shell program written in fortran that incorporated graphics, a functional language and extensive math functions and a set of operators for working on tables of numeric values and self-describing data files that has been in use for at least thirty years although I do not know if it is actively maintained.

If I get some time I might be able to track some of those down. I know the scheme interpreters are used in actively maintained programs but I have lost track of some of the others

The NCL scripting language for NCAR graphics had a huge amount of Fortran in it and I believe the original was all Fortran-based; but I think it migrated toward C; not sure but it had a huge amount of Fortran libraries available from NCL and is still available but no longer supported.

---

<div class="post-metadata">

**Author:** ![interkosmos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/interkosmos/32/296_2.png) [@interkosmos](https://fortran-lang.discourse.group/u/interkosmos)\
**Post date:** [January 17, 2023, 11:40am UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/6 "2023-01-17T11:40:36Z")

</div>

The [DISLIN Graphics Command Language](https://www.dislin.de/gcl.html) (DISGCL) is a scripting language for the DISLIN plotting library and seems to be written in Fortran.

---

<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:** [January 18, 2023, 1:13am UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/7 "2023-01-18T01:13:39Z")

</div>

> [@urbanjost](#):
>
> The NCL scripting language for NCAR graphics had a huge amount of Fortran in it and I believe the original was all Fortran-based; but I think it migrated toward C; not sure but it had a huge amount of Fortran libraries available from NCL and is still available but no longer supported.

By the looks of [this open letter](https://www.ncl.ucar.edu/open_letter_to_ncl_users.shtml) from 2019 they’ve already migrated to Python. This [transition guide](https://www.ncl.ucar.edu/Document/Manuals/NCL_to_Python/Transition_Guide_NCL_PyNGL.pdf) shows the same examples side-by-side in NCL and Python. There is quite a resemblance between Fortran and NCL. For the purposes used Python is not that different either.

---

<div class="post-metadata">

**Author:** ![jacobwilliams](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jacobwilliams/32/10_2.png) [@jacobwilliams](https://fortran-lang.discourse.group/u/jacobwilliams)\
**Post date:** [January 18, 2023, 1:56am UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/8 "2023-01-18T01:56:47Z")

</div>

Interesting. I was not aware of NCL. [This directory](https://github.com/NCAR/ncl/tree/develop/ngmath/src/lib/gridpack) has a lot of interpolation code. Some of which I’ve never seen before (e.g. SPLPAK). Definitely something that needs to be rescued and modernized!

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [January 18, 2023, 4:05am UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/9 "2023-01-18T04:05:46Z")

</div>

[S](https://bookdown.org/rdpeng/rprogdatascience/history-and-overview-of-r.html), the predecessor of R, was written in Fortran:

> S is a language that was developed by John Chambers and others at the old Bell Telephone Laboratories, originally part of AT&T Corp. S was [initiated in 1976](http://cm.bell-labs.com/stat/doc/94.11.ps) as an internal statistical analysis environment—originally implemented as Fortran libraries. Early versions of the language did not even contain functions for statistical modeling.
> 
> In 1988 the system was rewritten in C and began to resemble the system that we have today (this was Version 3 of the language).

[LISPF4](https://github.com/blakemcbride/LISPF4) is a Lisp interpreter originally written in Fortran.

---

<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:** [January 18, 2023, 3:00pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/10 "2023-01-18T15:00:28Z")

</div>

Thinking of S/R; DATAPLOT from NIST is an interpreter as well as a huge amount of Fortran statistical code, and includes vast amounts of documentation and generates plots as well.

---

<div class="post-metadata">

**Author:** ![gak](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gak/32/146_2.png) [@gak](https://fortran-lang.discourse.group/u/gak)\
**Post date:** [January 21, 2023, 9:52pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/11 "2023-01-21T21:52:06Z")

</div>

The IBM Fortran H compiler (late 70s?) was largely written in Fortran H . Fortran H had extensions for bitwise operations and structures. I haven’t been able to find source for it, though.

---

<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:** [January 22, 2023, 5:05am UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/12 "2023-01-22T05:05:11Z")

</div>

Some interesting history

> **[06GreatCompilers.pdf](https://www.clear.rice.edu/comp512/Lectures/06GreatCompilers.pdf)**
>
> 1322.36 KB

and do-it-yourself instructions

[http://bitsavers.informatik.uni-stuttgart.de/pdf/ibm/360/fortran/GY28-6642-4\_FortH\_PgmLogMan.pdf](http://bitsavers.informatik.uni-stuttgart.de/pdf/ibm/360/fortran/GY28-6642-4_FortH_PgmLogMan.pdf)

but no code. I have heard similar (a lot of bootstrapping Fortran code) but have never seen it  
and I looked for it a while ago; but more-or-less just out of curiosity.

Fortran compilers were on machines with as little as 4K words of memory (might be off, but still amazingly little). Amazing they got it working.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [January 22, 2023, 11:50am UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/13 "2023-01-22T11:50:13Z")

</div>

Some current projects are  
[M\_matrix](https://github.com/urbanjost/M_matrix): Fortran callable version of old matlab-like interface, by @urbanjost

[syntran](https://github.com/JeffIrwin/syntran), by Jeff Irwin, which can run the following code (taken from the Readme.md):

```auto
{
	// Calculate π
	let pi = 0.0;

	for k in [0: 10]
	{
		pi = pi + 1 / (16.0 ** k) *
			(
				4.0 / (8*k + 1) -
				2.0 / (8*k + 4) -
				1.0 / (8*k + 5) -
				1.0 / (8*k + 6)
			);
	}

	pi;
	// 3.141593E+00

	// x is 30 degrees (in radians)
	let x = pi / 6;

	// Calculate sin(x) using Taylor series

	// Initialize Taylor series terms
	let xpow = x;
	let factorial = 1;
	let sign = 1;

	// Sum odd terms only
	let sinx = 0.0;
	for k in [1: 10]
	{
		sinx = sinx + sign * xpow / factorial;
		xpow = xpow * x ** 2;
		factorial = factorial * (2*k) * (2*k + 1);
		sign = -sign;
	}

	sinx;
	// 4.999999E-01
}

```

---

<div class="post-metadata">

**Author:** ![R\_cubed](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/r_cubed/32/263_2.png) [@R\_cubed](https://fortran-lang.discourse.group/u/R_cubed)\
**Post date:** [January 22, 2023, 6:03pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/14 "2023-01-22T18:03:26Z")

</div>

The early Prolog implementations were bootstrapped using Fortran:

> **[Prolog and Logic Programming Historical Sources Archive
        —
       ...](https://www.softwarepreservation.org/projects/prolog)**
>
> A collection of artifacts from logic programming languages beginning with Marseille Prolog.

> Blockquote  
> From June to the end of the year [1973], Gérard Battani, Henri Meloni, and Rent Bazzoli, postgraduate students at the time, wrote the interpreter in FORTRAN and its supervisor in Prolog

Some of the very early Lisp environments were implement in ancient dialects of Fortran:

> **[History of Lisp](http://jmc.stanford.edu/articles/lisp.html)**
>
> Professor John McCarthy's page

> Blockquote  
> This paper concentrates on the development of the basic ideas of LISP and distinguishes two periods - Summer 1956 through Summer 1958 when most of the key ideas were developed (some of which were implemented in the FORTRAN based FLPL), and Fall 1958 through 1962 when the programming language was implemented and applied to problems of artificial intelligence. After 1962, the development of LISP became multi-stranded, and different ideas were pursued in different places.

Slightly related, I see this as my ideal computing environment, with Fortran, C, or C++ being used for performance critical areas.

Marsh, B. D., Williams, T. M., & Mathieson, G. L. (1990). The Use of Mixed Prolog/Fortran for Battle Simulation. The Journal of the Operational Research Society, 41(4), 311–318. [The Use of Mixed Prolog/Fortran for Battle Simulation on JSTOR](https://doi.org/10.2307/2583801)

> Blockquote  
> A mixed-system architecture is developed, in which Fortran and Prolog are each used to best advantage, and which allows discrete events to be combined with pseudo-continuous processes. The architecture is analysed in terms of a number of performance metrics. The paper concludes that the mixed architecture is feasible, practicable and brings a variety of benefits.

---

<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:** [January 23, 2023, 7:46pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/15 "2023-01-23T19:46:58Z")

</div>

Thanks for sharing the interesting finds.

The computer algebra system [FORM](https://en.wikipedia.org/wiki/FORM_(symbolic_manipulation_system)) also started out in Fortran. It was featured last year in an article: [Crucial Computer Program for Particle Physics at Risk of Obsolescene | QuantaMagazine](https://www.quantamagazine.org/crucial-computer-program-for-particle-physics-at-risk-of-obsolescence-20221201/)

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [March 31, 2023, 2:46pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/16 "2023-03-31T14:46:45Z")

</div>

A current project is [GitHub - TimBellerby/PM-Programming-Language: An open source parallel programming language aimed at scientific modelling. Implemented in Fortran 95.](https://github.com/TimBellerby/PM-Programming-Language)

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [August 20, 2023, 7:08pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/17 "2023-08-20T19:08:11Z")

</div>

[GitHub - ktye/i: interpret](https://github.com/ktye/i) has implementations of [K](https://en.wikipedia.org/wiki/K_(programming_language)) in various languages, including [Fortran 77](https://github.com/ktye/i/releases/download/latest/k.f). It’s a single file without comments and many `INTEGER*4` and `REAL*8` declarations that does compile with gfortran and produces an interpreter that ran a few K commands I tried. Compiling the source with Intel Fortran gives

```auto
k.f(16888): error #6404: This name does not have a type, and must have an explicit type. [FGET]
      S = FGET(C)
----------^
compilation aborted for k.f (code 1)

```

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [August 20, 2023, 11:46pm UTC](https://fortran-lang.discourse.group/t/emulators-and-interpreters-in-fortran/5042/18 "2023-08-20T23:46:30Z")

</div>

The fget() function/subroutine is not specified by the fortran standard. Here is a link that describes the gfortran fget() intrinsic. Its history traces back to the earlier g77 and f2c compilers.

> **[FGET (The GNU Fortran Compiler)](https://gcc.gnu.org/onlinedocs/gfortran/FGET.html)**
>
> FGET (The GNU Fortran Compiler)

Here is a link that describes the intel implementation, which involves a module.

> **[FGETC](https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-1/fgetc.html)**
>
> Portability Function: Reads the next available character from a file specified by a Fortran unit number.
