Shunting Yard Algorithm - Expression Parser

Hi, I hope you all are well and safe given the world situation.

I often write some utility code in my private projects, but sometimes they never get in production. So here is some spare code to I’d like to share:


This lib takes a expression, split in tokens, convert it to a reverse polish notation and then eval it using user defined callback functions. It’s really simple but I’m happy it works and can be extended to way more complex situations.

PS: I was told on reddit to post here too :slight_smile:


Welcome @14ngp to the Discourse!

it’s cool you are sharing using fpm! It was so easy to test your project, just three commands:

$ git clone
$ cd  shunting-yard-fortran
$ fpm run

It seems a nice project, probably some people here will be interested!
I remember my father was using reverse polish notation on his HP calculator at the beginning of the 80’s, and some years later with the Forth language. But I have myself never used it.

1 Like

Welcome, and thanks for introducing your expression parser. Your GitHub project MFI: Modern Fortran interfaces to BLAS and LAPACK is also interestng.

1 Like

The RPN is a really weird notation to write (IMO), but is really simple to evaluate it’s expressions thus it simplifies a lot such algorithm. I was curious to integrate fpm in some of my projects already, since I’ve been following closely the stdlib and fpm projects. I really liked how easy it was to use and integrate the fpm (way easier than Makefiles :slight_smile: ).

1 Like

Thanks, I created that one to simplify the BLAS/LAPACK calls on my main project (which is rewrite a old electronic structure of semiconductors legacy code in Modern Fortran), so I’ve started with the subroutines I needed most. I hope to get back to that soon, and also integrate the CUDA / OpenACC stuff in it.

1 Like