Skip to content

SDF3 — Syntax Definition Formalism

SDF3 is the third version of the Syntax Definition Formalism meta-language in Spoofax for defining the syntax of a language, which is used for both parsing an input into an Abstract Syntax Tree, and to provide syntax highlighting. Through the use of templates SDF3 can also be used to define a pretty-printer.

Reference Sources

Structure

An SDF3 syntax definition is structured as a collection of modules, which may import each other. Each module defines a number of symbols, which are the building blocks of productions. Productions are defined for lexical, context-free, or kernel syntax. Start symbols indicate the entry point of a syntax definition.

Grammars can be disambiguated by means of rejects, priorities, associativity, and restrictions, and permissive grammars are automatically generated for error-recovery parsing. Handwritten recovery rules can be added to tweak recovery behavior.

SDF3 automatically generates a pretty-printer for template-based productions, and provides additional constructs for the definition of layout-sensitive languages.

Several aspects related to syntax definition and parsing can be configured.

Sources

The sources of the SDF3 language can be found at:


Last update: October 17, 2024
Created: October 17, 2024