The aim of this project was to create an interpreter for a language of our construction in OCaml that would operate on numerical inputs over
According to the specification, the first deliverable was to submit the interpreter and solutions to the first 5 problems. Once this was concluded, 5 more problems would be given. If our interpreter needed changing, because the language could not solve the problems or due to a bug, there would be a 25% overall penalty. Therefore, we had to be sure we had a language that could solve any problem and an interpreter that operated as expected.
We settled on designing a language inspired by Assembly. We knew that Assembly is a low-level, albeit verbose language, capable of anything a higher-level language could also do. As long as we had all the necessary instructions for numerical operations, we should be able to solve any problem.
We made a special effort to keep the interpreter code simple, as the more lines of code we introduce, the greater chance of a bug to occur. The lexer was 60 lines, the parser 119 lines and the main interpreter 198 lines. It’s quite amazing what you can do in so few lines. We also made sure there were no ambiguities in the parser so we could be sure of its determistic parsing nature.
The project went well with most of the code written over a couple of weeks in March 2016. We are both competent programmers so the hardest part of the project was just learning the nuances of OCaml. We were awarded 95% for this project.