Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Grammar2Ecore
Contents
How to use Grammar to Ecore Generator
This article describes the steps involved in the generation of .genmodel, .ecore and Java from a grammar file using Gymnast, Emfatic and Grammar2Ecore frameworks.
Initial conditions
- Eclipse plug-in project with a sample grammar file (in this example, SVG.ast) exists as shown in Figure 1.
- JavaCC or Antlr can be used as Parser Generators.
- srcGymnast (in Figure 1) is the source folder to which Gymnast runtime core plug-in is added manually. Please refer "Bugzilla entry 233805"
- Dependent Plug-ins are added in the MANIFEST.MF file. Hence right clicking on the grammar file shows options like 'Generate .genmodel and Java', 'Generate .genmodel' etc. Refer Figure 2.
Grammar to Java conversion
This section describes the steps involved in the conversion of grammar file to Java code, along with the generation of .genmodel and .ecore. Problems like compilation errors, missing files etc., may occur at some of the steps in the grammar to Java conversion process. These problems are documented in Grmr2JavaReport, along with the possible workarounds/solutions.
Step 1: Generation of lexer files
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, svgLexer.jj and svgLexer.g are JavaCC and Antlr lexer files respectively. Refer Figure 3.
Step 2: Generation of .ecore and .genmodel
Ecore and Genmodel can be generated from the grammar, using the context menu links 'Generate .ecore' and 'Generate .genmodel'. Refer Figure 4. This step is optional as both the .ecore and .genmodel files will be autogenerated in the step 4.
Step 3: Generation of AST and Parser
Generate AST and Parser packages using Gymnast from the grammar, using the context menu link 'Generate AST'. The project structure is as shown in Figure 5.
Step 4: Generation of Java
Generate the Java code from the grammar file by clicking 'Generate .genmodel and Java' from the grammar file context menu. The project structure is as shown in Figure 6.
File:Grammar2Ecore6.jpg |
Conclusion
This page described the steps to be followed to generate Java from a grammar file (.ast) using Gymnast, Emfatic and Grammar2Ecore frameworks.
Organization
- Miguel Garcia - Mentor
- Rakesh Prithiviraj - Student