Deca compiler (Java)

Contributors: Mathieu Tillet, Sébastien Cassard, Valentin Sicard, Ronan Demimuid


Every Ensimag student goes through a Software Engineering project by January of their second year. This one-month project aim is to implement in Java a compiler for a sub-language of Java, Deca. From Deca files, the compiler needs to be able to produce the corresponding assembly code, runnable on a provided abstract machine.

During this project, I worked on :

  • Designing and coding of the code generator (from annotated syntax tree to assembly code) : register manager, stack manager, error manager, several assembly operations (ADD, MUL, LOAD, etc… )
  • Integration of classes (attributes and methods) in deca
  • Testing and peer reviewing

Deca language

Deca is a sub-language of Java, allowing for :

  • the declaration of classes with attributes and methods
  • a main program
  • file inclusion (.decah files)

Methodology

This project is an opportunity for students to get used to agile methodology and the use of tools such as Git. Indeed, this project follows a Scrum methodology, with dayly stand-ups meetings and weekly sessions with the professors to make sure the team is on the right path and discuss future plans and risk management. More, work is divided into small tasks, enabling for easy work division.

Special attention is also given to testing, with regular coverage analysis and over 900 tests by the end of the project.

The compiler

The compiler can be divided into 3 separated parts :

  • Lexical and syntaxic analyzer : during this pass, the compiler translates the string characters from the source code into meaningful lexemes (represented as tokens) and generate the corresponding parse tree, making sure the expression made by the tokens is syntactically correct.
  • Semantic Analyzer : next, the compiler checks whether the parse tree constructed follows the rules of Deca. For example, assignment of values or operations are between compatible data types. Also, the semantic analyzer keeps track of identifiers, their types and expressions; whether identifiers are declared before use or not etc. The semantic analyzer produces an annotated syntax tree as an output.
  • Code generator : finally, the assembly code corresponding to the annotated syntax tree is generated.

Extension : Deca Math library

As an extension of the compiler, we also made an high-precision Math library for Deca language, supporting functions like :

  • cos, sin and tan
  • arccos, arcsin and arctan
  • ulp

This library uses a self-made long float class so as to give the best precision possible.