# Online Fortran Compiler

**URL:** <https://fortran-lang.discourse.group/t/online-fortran-compiler/2171>\
**Category:** Meta\
**Created:** [October 27, 2021, 3:10am UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171 "2021-10-27T03:10:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![fortran4r](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@fortran4r](https://fortran-lang.discourse.group/u/fortran4r)\
**Post date:** [October 27, 2021, 3:10am UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/1 "2021-10-27T03:10:40Z")

</div>

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.

---

<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:** [October 27, 2021, 3:21am UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/2 "2021-10-27T03:21:40Z")

</div>

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

- [Draft: Compile LFortran itself to WASM (!1549) · Merge requests · lfortran / lfortran · GitLab](https://gitlab.com/lfortran/lfortran/-/merge_requests/1549)

We are looking for contributors.

---

<div class="post-metadata">

**Author:** ![fortran4r](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@fortran4r](https://fortran-lang.discourse.group/u/fortran4r)\
**Post date:** [October 27, 2021, 3:28am UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/3 "2021-10-27T03:28:16Z")

</div>

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

> **[Online Fortran Compiler - online editor](https://www.onlinegdb.com/online_fortran_compiler)**
>
> OnlineGDB is online IDE with fortran compiler. Quick and easy way to run fortran program online.

---

<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:** [October 27, 2021, 3:43am UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/4 "2021-10-27T03:43:25Z")

</div>

Sure, there is also [https://godbolt.org/](https://godbolt.org/) 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.

---

<div class="post-metadata">

**Author:** ![fortran4r](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@fortran4r](https://fortran-lang.discourse.group/u/fortran4r)\
**Post date:** [October 27, 2021, 3:49am UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/5 "2021-10-27T03:49:38Z")

</div>

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

---

<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:** [October 27, 2021, 1:57pm UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/6 "2021-10-27T13:57:30Z")

</div>

Can you please submit a pull request to the website?

---

<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:** [October 27, 2021, 3:52pm UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/7 "2021-10-27T15:52:41Z")

</div>

Something bare-bones like [https://play.rust-lang.org/](https://play.rust-lang.org/) 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.

---

<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:** [October 27, 2021, 7:34pm UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/8 "2021-10-27T19:34:14Z")

</div>

I think I just got something even better working this morning, here is a demo: [Emscripten-Generated Code](https://certik.gitlab.io/lfortran/wasm_demo.html), 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).

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [October 27, 2021, 7:41pm UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/9 "2021-10-27T19:41:30Z")

</div>

> [@certik](#):
>
> What is your experience with the above link? How fast does it load and how fast is it to get the results?

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?

---

<div class="post-metadata">

**Author:** ![fortran4r](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@fortran4r](https://fortran-lang.discourse.group/u/fortran4r)\
**Post date:** [October 27, 2021, 7:51pm UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/10 "2021-10-27T19:51:57Z")

</div>

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

---

<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:** [October 27, 2021, 7:54pm UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/11 "2021-10-27T19:54:23Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 20, 2023, 6:16pm UTC](https://fortran-lang.discourse.group/t/online-fortran-compiler/2171/12 "2023-12-20T18:16:02Z")

</div>

Another simple online Fortran compiler: [https://tio.run/#fortran-gfortran](https://tio.run/#fortran-gfortran)

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

> [Try It Online](https://tio.run/) 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.
