Firefly – An Educational Vector Graphics Language

Keywords: Compiler design, Programming Languages

This project was done in a team of 3, during the “Programming Languages and Translators” course at Columbia University. I took this course as a summer studies student at ColumbiaU in 2014 and transferred credits for this course back to NTU Singapore to replace the “Compiler Techniques” core course.

We developed an imperative language called “Firefly” that allows programmers to use their knowledge of vector algebra to create complex 2D shapes by drawing lines. Like the language LOGO, Firefly can be used as an aid for teaching students how to program. Programmers can use control structures and special operators in Firefly to draw lines, which can be joined together to create complex shapes, including curves. The backend of our compiler generates “FlatC”, which we define as 3-address “assembly-like” code in C++. This “FlatC” can then be linked with the OpenGL and GLUT libraries and compiled with gcc or g++ to- produce an executable. The executable when run, displays a GLUT window with a shape as output of the FF program.

This language was built using a functional language called OCaml. This project taught me how to code in functional languages and how compilers work and can be designed.

Technical Report:

Here is an example of what Firefly can do:

The following code in Firefly generates a Koch snowflake, as shown. In the background, our compiler generates a Flat-C code that is 322 lines long and employs OpenGL to display the figure.


Koch Input FF code


Koch Snowflake Output