The Spoofax Name Binding Language

September 10, 2012

We have extended the Spoofax Language Workbench with a domain-specific language for specifying the name binding and scope rules of programming languages. Instead of programmatically encoding name resolution algorithms, as is standing practice, a language designer defines name binding in terms of four basic domain-specific concepts: ‘definitions’, ‘references’, ‘scopes’, and ‘imports’. With these concepts a wide variety of name bindings can be expressed non-algorithmically. For example, the following rules define the binding of base class references (inheritance) and types to class definitions in C#:

  Class(NonPartial(), c, _, _) : 
    defines unique class c
  Class(Partial(), c, _, _) : 
    defines non−unique class c 
  Base(c) : 
    refers to class c
  ClassType(c) : 
    refers to class c

From such a definition we automatically derive a name resolution algorithm that is used as the basis for editor services such as reference resolution and code completion. Our hope is that NBL can play the role for name binding that BNF plays for syntax definition. That is, that a single declarative definition can be used as the basis for implementation and documentation.

NBL is already available in the nightly builds of Spoofax. In the coming months we will be spreading the word at various events. We will present a poster at SPLASH and SLE. I will present our NBL paper at SLE 2012, and the language will feature in my grammarware tutorial at SLE as well. I may be giving a talk in the Bay Area as well.

For a full account of NBL see our SLE 2012 paper:

Gabriël D. P. Konat, Lennart C. L. Kats, Guido Wachsmuth, Eelco Visser. Declarative Name Binding and Scope Rules. In Krzysztof Czarnecki, Görel Hedin, editors, Software Language Engineering, 5th International Conference, SLE 2012, Dresden, Germany, September 26-28, 2012, Revised Selected Papers. Volume 7745 of Lecture Notes in Computer Science, pages 311-331, 2013.

Abstract: In textual software languages, names are used to reference elements like variables, methods, classes, etc. Name resolution analyses these names in order to establish references between definition and use sites of elements. In this paper, we identify reoccurring patterns for name bindings in programming languages and introduce a declarative metalanguage for the specification of name bindings in terms of namespaces, definition sites, use sites, and scopes. Based on such declarative name binding specifications, we provide a language-parametric algorithm for static name resolution during compile-time. We discuss the integration of the algorithm into the Spoofax Language Workbench and show how its results can be employed in semantic editor services like reference resolution, constraint checking, and content completion.