How to use Gymnast Generator

Gymnast is a framework for jumpstarting text editors for custom Domain Specific Languages, written by Chris Daly, and summarized in these slides.

Gymnast is being distributed along with Emfatic, as their developer communities overlap (at least, so far).

In the past, many improvements has been included in Gymnast. For example, JavaCC and Antlr lexer files can be autogenerated now instead of manually creating and adding them to the project. This article reflects those changes made to the Gymnast framework. Please refer to Grammar2Ecore for details on the generation of Java classes from grammar.

Where to download Gymnast from

Overview

Gymnast comprises two main parts (Runtime and Generator), each of which can in turn be divided into Core and User Interface. This section is all about using the Gymnast Generator to:

create .ast files

configure options in that file

autogenerate lexer files, and

manually add the parser's .jar to the (Build path or Plugin dependencies)

Generation of lexer files

The grammar file can be checked for well-formedness by clicking 'Check Well-formedness' from the context menu. After checking for the well-formedness of the grammar, JavaCC and Antlr lexer files can be auto generated by clicking 'Generate JavaCC lexer file' and 'Generate Antlrv2 lexer file' from the context menu of the grammar file. This autogeneration of lexer files is one of the enhancements made to Gymnast. In this example, emfaticLexer.jj and emfaticLexer.g are JavaCC and Antlr lexer files respectively (Figure 3).

Figure 3 Generated lexer files

Generation of AST and Parser

After the generator is run (by rightclicking on emfatic.ast and choosing "Generate AST") the result looks as in Figure
4.

Figure 4 After Gymnast Generator

Not shown here is the added plugin dependency to org.antlr, which can be installed as described in the next section.

Gymnast reports its operation on the console:

Figure 5 Console output of Gymnast Generator

What if you target ANTLR instead of JavaCC

In that case, the code generated for the parsing infrastructure will depend on the ANTLR parser generator framework.
The easiest way to install a plugin with ANTLR is to get it from the update site on SourceForge by following these steps:
<p/>

Click on Install when you see a pop-up message warning about unsigned features.

When prompted, click on Yes to restart the workbench.

Choosing target parser

The choice of target parser is made with the option parserGenerator = ". . ." (Figure 6). Unlike ANTLR, JavaCC requires no runtime library: all the code it needs gets generated.

Figure 6 How to choose a parser

Exploring the generated artifacts

The generated grammar files (for the ANTLR example the one highlighted in Figure 7) are not supposed to be messed up by the user, however in order to explore them the following Eclipse plug-ins prove useful: