The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code, not in reams of trivial code that bores the reader to death - Guido van Rossum

Welcome everyone, I am your host Nikhil Maan aka Sc0rpi0n101 and I will be barraging you with blogs of my progress with my GSoC project. This is the blog for the first week of work. The official coding started May 27.

Today is May 31, it’s been 5 days of work and I’ve had some progress since Monday and had the meeting for the first week yesterday. The week has not been as productive as I would’ve liked to be but I managed to get in some work. I spent most of the week in research. I’ve had a lot of Distractions this week, some were Uni work, sometimes I was just slacking. Do I feel I could’ve done more? Yes, definitely. Do I plan to be more productive in the coming weeks? Well, I plan to. We’ll have to see how it goes. Now, on to the story what I’ve done this week.

The Original Plan


The plan for this week originally was to read up on Clang and cppyy to see how useful they could be for the project and have a small Lfortran conversion to SymPy implemented by the end of the week. I was supposed to research on the cppyy and Clang APIs for C parser and start work on the Fortran parser by trying out and creating small implementations for Fortran to SymPy conversion and find out the current issues in LFortran and features that might need improvements and report them so that they can be worked on soon.

Now that the plan is set, it’s time to get to the actual work. So, the first job was to research about Clang.

The Clang Situation

The typical first step to researching a project would be to look at the documentation and go through it. So, the first step was to find the Clang documentation but it was not easy to find. The Clang documentation is not that well updated and not easily available. I had to put some efforts to find the official documentation and it was only available as a Doxygen HTML render; the story doesn’t end there.

Bad Docs

The documentation present for Clang is also not very detailed or beginner friendly. It mostly comprised of the variables in the source code and a minuscule summery. The whole documentation is full of list of variables and functions like these with not much explanation and it looks very confusing and unorganized. The documentation was not very helpful in my research. So, I had to turn to manually go through the source code to find any use of Clang.

While going through the source code, I did find some code that would be useful in my project. During the research, I also came across libclang, which is the C API and library for clang and it also has python wrapper functions which also works as a python API. The API is working properly and can be used for the parser but it might need some improvements to better match the requirements of SymPy.

I also came across a few other projects similar to mine including a project that was code conversion from C++ to Python using libclang, but it is written in C. It has many similarities to what I’m trying to do. I took inspiration and some ideas from these projects and trying out small implementations of my project.

Using CPPYY?


The next step for my research was to look at cppyy which is a relatively latest project using Clang and figure out if it will be useful. cppyy is an automatic C++-Python binding generator. It is also in some ways similar to my project and I wanted to see if I could use it somewhere in the project. cppyy is also using Clang to extract C++ AST and is relatively faster than it’s competition.

In terms of its usage, the AST Visitor is better in Clang and I want to use Clang to create the base for my parser. cppyy does have C++ to python bindings and source code for that can be used and some of the implementations can be useful in the project. So, I will be using cppyy to improve the parser after basing it on Clang to extract the AST.

Now that the plan for C parser is decided and the work is in motion, it’s time to talk about the Fortran part. I do not have much experience with Fortran but I been practicing using Fortran for this project. LFortran is also a compiler that I’ve not used till now. So, I needed to learn more about LFortran first before trying to use it for parsing. The first step to exploring LFortran is also to read through its documentation.



LFortran is a modern open-source interactive Fortran compiler built on top of LLVM. The LFortran documentation was significantly better than the Clang documentation I had to power through previously. The LFortran documentation was a walk in the park as compared to the Clang Documentation. It was well organized, rendered and pretty useful for beginners. It could still be improved, and I have some ideas regarding that but it is still helpful. It has some examples of how to use the ASR and AST and helped me start with some small implementations.

Having gone through the documentation and learning to use the compiler, it was now the time to go through the actual source code and source code and figure out how I was going to use it. LFortran generates the Abstract Syntax Tree (AST) from the Fortran source code. The AST then can be converted to Abstract Semantic Representation (ASR) using LFortran. So, the ASR can be extracted from the source code using only LFortran which can then be just manipulated and converted directly to SymPy syntax.

This has been my progress with the project in the last 4 days; as you all can see, it is very apparent that most of the work has been researching and I have only started working on the implementations. So. came Thursday, May 30; it was time for the Week 1 meeting and time to discuss with my mentors what work had been done and what was to be done next.

The Meeting


If I go through all the details of the meeting, it’s going to be very detail oriented and dull. You all will get bored reading about that. So, here is a summary of the meeting for the ones that are still curious:

  • Create a small implementation for Fortran to SymPy conversion using one of the examples form LFortran Documentation.
  • Create a PR in SymPy for the implementation
  • Work on the Clang conversion and create a SymPy PR to discuss the code.
  • Complete the Week 1 and Week 0 blog post.

So, What Now?


Friday also turned out to be not productive at all; I had to move since the semester has just ended. I could only work on the blog posts. But after I finish writing this, I plan to work on making those PRs as soon as possible as I have a free weekend and I want to get the initial implementations running. After that, I plan to improve the implementations with feedback from the SymPy community.

Tune in next time to find out how much work I manage to do this week. Will I be able to complete and test some of the implementations by next week? or Would I still be stuck on researching for another week?


Subscribe to the blog to get weekly updates of my work and other experiences.