Lecture 2: Declarative Syntax Definition

Eelco Visser
Lecture | PDF
September 03, 2021

In this lecture we study declarative syntax definition.

Slides

Reading Material

The [SEFM 2020] paper gives an overview of SDF3, the language we will use for syntax definition.

The [LDTA 2012] paper introduced ‘template-based syntax definition’. (This was one of the results of the master’s thesis work of Tobi Vollebregt.)

Tutorial and Talk on SDF3

This is part of a tutorial on Spoofax at the PLDI 2020 conference in June 2020.

This is a talk for the OCAML 2020 workshop at the ICFP 2020 conference.

References

  • SEFM 2020 [doi, bib, researchr, ]
    SDF3 is a syntax definition formalism that extends plain context-free grammars with features such as constructor declarations, declarative disambiguation rules, character-level grammars, permissive syntax, layout constraints, formatting templates, placeholder syntax, and modular composition. These features support the multi-purpose interpretation of syntax definitions, including derivation of type schemas for abstract syntax tree representations, scannerless generalized parsing of the full class of context-free grammars, error recovery, layout-sensitive parsing, parenthesization and formatting, and syntactic completion. This paper gives a high level overview of SDF3 by means of examples and provides a guide to the literature for further details.
  • LDTA 2012 [pdf, doi, bib, researchr, ]
    Syntax discoverability has been a crucial advantage of structure editors for new users of a language. Despite this advantage, structure editors have not been widely adopted. Based on immediate parsing and analyses, modern textual code editors are also increasingly syntax-aware: structure and textual editors are converging into a new editing paradigm that combines text and templates. Current text-based language workbenches require redundant specification of the ingredients for a template-based editor, which is detrimental to the quality of syntactic completion, as consistency and completeness of the definition cannot be guaranteed. In this paper we describe the design and implementation of a specification language for syntax definition based on templates. It unifies the specification of parsers, unparsers and template-based editors. We evaluate the template language by application to two domain-specific languages used for tax benefits and mobile applications.