Online Fortran Compiler

Can we add an online Fortran compiler and some example codes to the Fortran Lang website? The Julia Lang website used to have these before Julia gained so many users.


@fortran4r good idea. Would you (or anyone) be interested in helping making this a reality:

We are looking for contributors.

I am not talking about web assembly. I am talking about something like this:

Sure, there is also which has several Fortran compilers.

For both of these services you need to maintain the servers which is a lot of work and costs money.

The advantage of WASM is that it runs in the browser (all major browsers now seem to support it), so one can host it from a static website.

Why not simply add a link of an existing online Fortran compiler to the Fortran Lang website?


Can you please submit a pull request to the website?

Something bare-bones like would be relatively simple to implement in Fortran and cheap to maintain. A HTTP POST request to the server which compiles and runs the program and returns the output in the HTTP response. Then websockets protocol for more real-time experience (i.e. live update of output in the browser). But an even lower-hanging fruit (web-development wise), is to embed a JupyterHub notebook (or binder, I forget what’s the best current approach for that) with a LFortran kernel, so I suggest doing that as the step after a link to an external online compiler.


I think I just got something even better working this morning, here is a demo: Emscripten-Generated Code, it runs LFortran itself in WASM, so it is hosted by a static site (GitLab Pages in this case). You have to click the “Run LFortran” button. You can modify the code.

This currently doesn’t have the LLVM backend, so it can’t actually compile the Fortran code to WASM to execute. It currently runs twice: parse+AST and parse+AST+ASR and shows the results (it even shows syntax and semantic errors). For me the results are immediate. What is your experience with the above link? How fast does it load and how fast is it to get the results?

I tested in Firefox, Chrome, Safari on macOS and on Safari, Firefox on iPhone. It works great.

So instead of running twice, if it does parse+AST+ASR+WASM backend (our own), it will be as fast. The WASM file is 1MB download currently.

Once the WASM backend works (one way or another), then we can get it working as a jupyterlite kernel. So it will be the Jupyter notebook, but instead of being hosted by a server, it will be hosted by a static site, for free. And faster (no communication to a server).


Between 1 and 2 seconds to load the page, and immediate result (AST & ASR) as I click the button.
I see a black rectangle centered at the top of the page. Is it normal?

same experience, the rectangle is black. is it supposed to show the output?

@vmagnin awesome, thanks! The black rectangle is “canvas” that is there by default, and one can draw on it from C++. I don’t use it for this demo. I plan to polish the page later (and remove this canvas), for now I just quickly put it together using existing templates.

@fortran4r the black rectangle does not show output. The output is shown after you click the “Run LFortran” button, right above the button. You can modify the text area and click the button again, and the output will change. The change should be immediate.


Another simple online Fortran compiler:

(don’t forget the END statement to test Fortran code)

Try It Online is a family of online interpreters for an evergrowing list of practical and recreational programming languages.

TIO hosts 260 practical and 420 recreational programming languages, for a total of 681 languages.

1 Like