Change search
ReferencesLink to record
Permanent link

Direct link
Implementing the next generation of the Methodical Accelerator Design language using LuaJIT
Norwegian University of Science and Technology, Faculty of Information Technology, Mathematics and Electrical Engineering, Department of Engineering Cybernetics.
2014 (English)MasteroppgaveStudent thesis
Abstract [en]

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, can therefore be of help to the MAD project and thus also to accelerator physicists in general.

Place, publisher, year, edition, pages
Institutt for teknisk kybernetikk , 2014. , 122 p.
URN: urn:nbn:no:ntnu:diva-25130Local ID: ntnudaim:10641OAI: diva2:732351
Available from: 2014-07-03 Created: 2014-07-03 Last updated: 2014-07-03Bibliographically approved

Open Access in DiVA

fulltext(1708 kB)658 downloads
File information
File name FULLTEXT01.pdfFile size 1708 kBChecksum SHA-512
Type fulltextMimetype application/pdf
cover(205 kB)6 downloads
File information
File name COVER01.pdfFile size 205 kBChecksum SHA-512
Type coverMimetype application/pdf
attachment(2276 kB)4 downloads
File information
File name ATTACHMENT01.zipFile size 2276 kBChecksum SHA-512
Type attachmentMimetype application/zip

By organisation
Department of Engineering Cybernetics

Search outside of DiVA

GoogleGoogle Scholar
Total: 658 downloads
The number of downloads is the sum of all downloads of full texts. It may include eg previous versions that are now no longer available

Total: 85 hits
ReferencesLink to record
Permanent link

Direct link