GRA2MOL is a specially tailored DSL for extracting models from source code developed by Javier Cánovas and Jesús García Molina from the Modelum group in Spain.

Most reverse engineering and software modernization processes require to extract some kind of models from the source code as a way to facilitate the understanding and/or manipulation of the legacy system.
Gra2MoL facilitates this task by simplifying the definition of code-to-model transformations from a grammar definition to a target metamodel. See the general schema of GRA2MOL:

It has three main features: i) it is a rule-based language where each rule specifies a mapping between a grammar element and a metamodel element; ii) it incorporates a powerful query language to retrieve scattered information from the source code syntax tree, and iii) mappings between elements are defined by a special kind of assignment (binding) which is either locally resolved or triggers the execution of another rule.

For instance, the following Gra2MoL rule populates the RDBTrigger element of a PL/SQL metamodel from a SQL Trigger grammar element:

rule 'mapCompilationUnit'
	from Trigger tDef
	to astm::sastm::RDBTrigger
	queries
		stats : /tDef//#statement;
	mappings
		identifierName = new astm::gastm::Name;
		identifierName.nameString = t.trigger_name;
		body = stats;
end_rule

As you can see, a Gra2MoL rule is made up of four main parts: i) the from and to parts, which specify the source grammar element and the target element metaclass, respectively; ii) the queries part, in which we can define queries to retrieve information from the syntax tree of the source code; a query consists of a sequence of query operations in which each operation includes an operator, a node type and optional ?lter and access expressions (in this example the query /tDef//#statement collects all statement grammar elements that are children of tDef, which is the Trigger grammar element received by the rule); and iii), the mappings part which contains a set of bindings to assign a value to the properties of the target elements.

It is also possible to use GRA2MOL to bootstrap the process, i.e. we can automatically derive a metamodel representation for the grammar before starting the reverse engineering process.

For sure, GRA2MOL could be useful to help in the development of new model discoverers for MoDisco . We hope to explore this possibility soon.

 

Want to build better software faster?

Want to build better software faster?

Read about the latest trends on software modeling and low-code development

You have Successfully Subscribed!

Pin It on Pinterest

Share This