I have several SDF2 grammars that I’d like to convert to SDF3. The transformation from SDF2’s reductive form for productions to SDF3’s templates appears to be quite straightforward (assuming that constructor names have already been specified in the SDF2 rules) but tedious to do manually. Have any tools (ideally, Spoofax editors) been developed to automate this transformation?

Asked by Peter Mosses on 28 November 2013 at 12:29

There is a builder in the SDF2 editor to do this: Transform -> Show syntax templates (for selection). But currently there are 2 problems with it:

  1. It generates a .spx file, you should change the extension to .sdf3.
  2. It generates one < and > bracket extra around every template. You need to remove these, but that should be possible with a simple find and replace.

I’ll see if I can fix these problems for future use. Also, if you want a nice pretty printer, the generated templates need to be adapted, because it will just straightforwardly convert them.

Answered by Gabriël Konat on 28 November 2013 at 15:51

Good, many thanks! I see that the two problems with the builder in the SDF2 editor have already been fixed: it now generates an .sdf3 file, and the templates don’t have the extra brackets.

This makes migration of larger grammars from SDF2 to SDF3 templates quite easy. Currently, however, the SDF3 module produced by the builder (when the entire SDF2 module is selected) includes only the templates (lexical syntax is ignored) and the module name at the top of the generated file is always example. If it could instead produce a copy of the entire selected SDF2 module text with the context-free syntax sections replaced by templates sections (and exports deleted) I think the result would then be directly usable without further editing. (My SDF2 grammar interleaved a number of context-free and lexical syntax sections, and I had to make a copy manually, then copy and paste the generated templates into the right places.)

The builder in the SDF2 editor would in effect then be the inverse (up to layout) of the transformation from SDF3 to SDF2 that happens when building the editor project, and allow automatic migration from SDF2 to SDF3.

Answered by Peter Mosses on 30 November 2013 at 11:59

To further facilitate migration from SDF2 to SDF3, could the builder in the SDF2 editor also support transformation of lexical syntax rules from reductive to productive form? It appears that Spoofax-1.2 requires the use of the productive form, and it seems odd that one currently has to do such a straightforward transformation manually when migrating.

Answered by Peter Mosses on 22 May 2014 at 23:09

In fact, I am working on a more complete builder to convert full SDF2 definitions to SDF3. By using this new builder it will also be possible to convert any SDF2 section into SDF3 format. This builder should be available to all users in the next few weeks.

Answered by Eduardo Amorim on 23 May 2014 at 01:21