User-Defined Operators Including Name Binding for New Language Constructs
User-defined syntax extensions are useful to implement an embedded domain specific language (EDSL) with good code-readability. They allow EDSL authors to define domain-natural notation, which is often different from the host language syntax. Nowadays, there are several research works of powerful user-defined syntax extensions.
One promising approach uses user-defined operators. A user-defined operator is a function with user-defined syntax. It can be regarded as a syntax extension implemented without macros. An advantage of user-defined operators is that an operator can be statically typed. The compiler can find type errors in the definition of an operator before the operator is used. In addition, the compiler can resolve syntactic ambiguities by using static types. However, user-defined operators are difficult to implement language constructs involving static name binding. Name binding is association between names and values (or memory locations). Our inquiry is whether we can design a system for user-defined operators involving a new custom name binding.
This paper proposes a variant of a lambda expression, named a context-sensitive expression. A context-sensitive expression looks like a normal expression but it implicitly takes parameters. To realize user-defined name binding, these parameters are accessed through public members such as methods and operators of one parameter object instead of through parameter names. Programmers can emulate name binding by such methods or operators, for example, they can emulate a local variable through getter operator and setter operator. We also present turnstile type to give a type to a context-sensitive expression, DSL class to cooperate with syntax extension, and generic name to recognize arbitrary names given by users.
A contribution of this paper is that we reveal we can integrate a system for managing names and their scopes with a module and type system of an object-oriented language like Java. Programmers can define new language constructs involving custom name binding and another programmers can use them by importing modules. The compiler can statically verify the types of both the definition and usage of the language constructs.
We have implemented ProteaJ2, which is a programming language based on Java and it supports our proposal. We describe a parsing method that adopts eager disambiguation for fast parsing and discuss its time complexity. To show the practicality of our proposal, we have conducted two micro benchmarks to see the performance of our compiler. We also show several use cases of DSL classes for demonstrating DSL classes can express various language constructs.
Our ultimate goal is to let programmers add any kind of new language construct to a host language. To do this, programmers should be able to define new syntax, name binding, and type system within the host language. This paper shows programmers can define name binding with their own syntax.
Wed 5 AprDisplayed time zone: Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna change
10:45 - 12:15 | |||
10:45 30mTalk | Language Oriented Modularity: From Theory to Practice Research Papers Link to publication DOI | ||
11:15 30mTalk | A Module-System Discipline for Model-Driven Software Development Research Papers Link to publication DOI | ||
11:45 30mTalk | User-Defined Operators Including Name Binding for New Language Constructs Research Papers Link to publication DOI |