Compiler projects fall 2018
EDAN70: Project in Computer Science
Datalog Implementation in JastAdd
Hampus Balldin
Abstract:
This paper presents the implementation of a new programming language belonging to the Datalog family. A short background on Datalog, its theoretical foundations, and its applicability for practical problems is introduced. A number of extensions to the core Datalog language are presented, the most novel of which is to allow predicates to be used as terms in atoms. As will be shown, this enables a compact description of various meta properties such as encoding what tables to output, or to give static types to predicates.
(paper)
(code)
Extending Java with String Interpolation Using ExtendJ
Wilhelm Lundström and Oskar Damkjaer
Abstract:
String interpolation is a syntactic feature commonly found scripting languages such as Python and Perl. It can be used to simplify the code for printing and manipulating strings, making the code easier to both read and to write. There is currently no support for this feature in Java (the current version being Java 11).
In this project, we bring string interpolation to Java by extending the extendable Java compiler ExtendJ[4]. The implementation is functional and backwards compatible, so existing code will not be affected by this extension (save for rare, specific cases).
Our implementation is rather light weight, yet effective. The full feature of string interpolation is implemented in a few short files, yet has a significant potential effect on the way Java code is written.
We evaluate the impact of this feature by analysing how effectively it could be used in larger Java projects. Looking at open source projects, we examined how much string interpolation could be used in the projects.
(paper)
(code)
Language Server Protocol for ExtendJ
Fredrik Siemund and Daniel Tovesson
Abstract:
Microsoft’s Language Server Protocol (LSP) has been implemented with ExtendJ in two widely popular Integrated Development Environments (IDE), Eclipse and Sublime Text. LSP is a way of supplying high level support — such as code completion, hover tooltips, jump-to-definition and find-references — for a programming language in a wide variety of editors. ExtendJ is an extensible compiler for Java, specified using reference attribute grammars. Because of the time limit of the project, only error checking was implemented. As the user writes Java code, the IDEs will highlight erroneous code and thereby simplify the process of finding errors. On the client side, this was done by configuring two extensions, one for each IDE. On the server side, a language server was created that compiles the file with ExtendJ every time it is changed by the user to search for compilation errors. To make LSP work flawlessly with ExtendJ, an extension to ExtendJ was created.
(paper)
(code)
Design By Contract Implementation For ExtendJ
Martin Lindström and Jakob Hök
Abstract:
The paper demonstrates how Design By Contract (DBC) was integrated into the aspect-oriented Java compiler ExtendJ by using annotations. The scope of the implementation was limited to only include preconditions, i.e., only method-input validation. Adding DBC into Java, is a handy way of validating execution and also to improve readability. Therefore, DBC is a desirable feature to implement. ExtendJ makes use of aspect-oriented programming to compile Java code. Extending the compiler was therefore convenient and allowed the implementation to conform to the open-closed principle. The preconditions’ byte code was inserted before the method’s or constructor’s byte code. Hence, the precondition validation is run before the method’s code. An exception is thrown if any precondition is not met. In the end, the extension supports preconditions NotNull, MinValue, MaxValue, Not and arbitrary preconditions with the annotation Requires.
(paper)
(code)
Declarative Program Analysis and Interpretation for AttoL
Anton Göransson
Abstract:
I have implemented an interpreter for a small object-oriented language called AttoL. I then experimented with different kinds of program analysis. This was all done using JastAdd, which makes it possible to write declarative code. The idea is that the interpreter will be used for experimenting with declarative program analysis with attribute grammar since it has not been done that much before. I then evaluated my implementation by comparing program execution speed and source lines of code to the original AttoL implementation. The results were positive and I definitely think that JastAdd is a viable option for implementing program analysis. Because of JastAdd’s modularity is easy to add new functionality without having to change old one, creating a maintainable and decoupled system.
(paper)
(code)
Extending Java with the Exponentiation and Safe Navigation Operators
Emma Asklund and Victor Winberg
Abstract:
This report describes the implementation of the exponentiation and safe navigation operators as extensions to the Java compiler ExtendJ. Our implementations of these operators in ExtendJ is functional and can be used to compile existing Java programs. Bytecode generation is also supported. The implementation of these operators is small, thanks to mapping to pre-existing language constructs.
We have evaluated the safe navigation operator by looking into benefits of using the save navigation operator in three Java and three Groovy open source projects. The conclusion after looking into these six projects is that the safe navigation operator is not as useful as we thought it would be.
(paper)
(code)
Reference Attribute Grammars in Python
Christoffer Olsson and Liang Ce
Abstract:
This is a short report on a Python library that implements so called reference attribute grammars. Reference attribute grammars are in short a way to give attributes to already existing tree data structures. Attributes are computed properties of nodes in a tree, defined by equations. The ability to attribute trees is something that is very useful in for example compiler construction. There are already several implementation of reference attribute grammars in languages such as Java and Scala. However there are none in more dynamic languages such as Python. Therefore this report presents a small library written in Python that enables an end user to attribute any tree like data structure in the very same language.
(paper)
(code)
Reducing error prone code by analyzing immutability
Oskar Berg and Ruolangxing Zhang
Abstract:
Immutability is long known for its advantages of automatically being thread-safe and it works without synchronization issues. As we were very interested in this area and intend to reduce errors for programmers. We built a tool based on java compiler Extendj, so when compiling the program, the tool produces warnings for potentially wrong mutable fields, which includes every mutable parameter type as well as every static field that are mutable. To achieve this we implemented functions such as isMutable(), exposeReference() and so on. These are two typical cases that mutability could cause errors. It is a useful tool which can be further developed.
(paper)
(code)
Language Server Protocol for ExtendJ
Joakim Ericson
Abstract:
Integrated Development Environments (IDEs) are popular tools and while they have their benefits, such as diagnostic messages in the editor, code completion, or debugging. However a drawback of most modern IDEs is the fact that they only work with a handful of languages, that they are developed for. The Language Server Protocol (LSP) was developed to extract some of the language related functionality of an IDE 1and make it available for any editing software that would implement a client for the LSP. Currently there are two major language servers for Java. One using the official Javac compiler, and the other using Eclipse’s jdt compiler. While both of these solutions work fine for working with the standard features of Java, if there were new features of Java that one wanted to test and still have full support by a language server, that would not work currently. Thus we propose to create one using the compiler ExtendJ2, that is developed at Lund University. We decided that we wanted to implement a language server using ExtendJ due to the fact that it is designed to be easy to extend Java with new features. Since this proposal combines ExtendJ with the LSP any existing editor, such as vim or sublime, both of which has a working client would be usable. And can provide helpful features such as code completion and other such features that an IDE would traditionally provide. While adding the extensibility of ExtendJ to the mix.
(paper)
(code)