Implementing the next generation of the Methodical Accelerator Design language using LuaJIT
MetadataShow full item record
To further the boundaries of human knowledge, physicists at CERN use large particle accelerators to smash elementary particles together at high energies. To design these accelerators, the physicists need a language specially designed for the task, to allow them to spend their time doing physics instead of programming. The Methodical Accelerator Design (MAD) project at CERN is developing this kind of languages. The author of this thesis was chosen to cooperate in this project to aid in the implementation of the new iteration of the MAD language. A new version is needed, because the old version (MAD-X) has several problems that will make it unsuitable for the next generation of accelerators. The project this report is based on is an application able to run code written in Lua, the new language MAD, and MAD-X. The implemented MAD application is written in the Lua language and run using the excellent Just-In-Time compiler LuaJIT.The application contains a parser constructor factory and a generator factory to facilitate addition of different languages. Using the factories, the user can chose between three different input languages and two different output languages. The parsers are implemented using LPEG, a module creating top-down parsers. With the help of LPEGs regex module, the grammars of the implemented languages are written in a syntax closely related to Extended Backus Naur Form. The parsers then create an Abstract Syntax Tree that is used by the generators to create Lua or MAD code. The Lua code can then be run using LuaJIT, while the MAD code can be used to debug the application.To make the application fully able to interpret all Lua files and act as one would expect interpreters to act, a module for correctly mapping errors to their correct lines is implemented. The implementation utilises a map that contains all the generated codes lines and their corresponding lines in the input code.The application is extended with support for a new language, MAD, which is an extension of Lua. MAD contains support for C-style include statements and a short function syntax for functions that can be lazily evaluated. MAD is also extended to be backwards compatible with MAD-X, by translating MAD-X code into Lua code.A stand-alone framework for unit testing is implemented, allowing all modules in the MAD application to be tested quickly and easily. The framework is inspired by the pre-existing BTD and Lunit-frameworks.The future works of the application are discussed and solutions to potential problems are suggested. The interpreter is tested against other Lua interpreters and is shown to be able to compete on an equal basis. The application is also shown to be easily extendible, helped by the unit testing framework that easily allow the module designers to test their functions and APIs. The implemented application, which can be found at https://github.com/ldeniau/mad/, can therefore be of help to the MAD project and thus also to accelerator physicists in general.