Syntax Definition Formalism

The Syntax Definition Formalism (SDF) is a metasyntax used to define context-free grammars: that is, a formal way to describe formal languages. It can express the entire range of context-free grammars. Its current version is SDF3.[1] A parser and parser generator for SDF specifications are provided as part of the free ASF+SDF Meta Environment. These operate using the SGLR (Scannerless GLR parser). An SDF parser outputs parse trees or, in the case of ambiguities, parse forests.

Overview

Features of SDF:

  • Supports the entire range of context-free languages
  • Allows modular syntax definitions (grammars can import subgrammars) which enables reuse
  • Supports annotations

Examples

The following example defines a simple Boolean expression syntax in SDF2:

module basic/Booleans

exports
  sorts Boolean
  context-free start-symbols Boolean

context-free syntax
   "true"                      -> Boolean
   "false"                     -> Boolean
   lhs:Boolean "|" rhs:Boolean -> Boolean {left}         
   lhs:Boolean "&" rhs:Boolean -> Boolean {left}       
   "not" "(" Boolean ")"       -> Boolean           
   "(" Boolean ")"             -> Boolean

 context-free priorities
   Boolean "&" Boolean -> Boolean >
   Boolean "|" Boolean -> Boolean

Program analysis and transformation systems using SDF

gollark: It started accepting undamaged stuff.
gollark: I'll just filter it to "these random items I put in" or something.
gollark: Unfortunately it doesn't seem able to specifically match "all damaged items" but this is better than nothing.
gollark: I never thought of using it with no item filter to just accept "all damaged stuff".
gollark: Oh, right, that's clever.

See also

References

Further reading


This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.