Grammar Framework

Enterprise Architect provides reverse engineering support for a number of popular programming languages. However, if the language you are using is not supported, you can write your own grammar for it, using the in-built Grammar Editor. You can then incorporate the grammar into an MDG technology to provide both reverse engineering and code synchronization support for your target language.

The framework for writing a grammar and importing it into Enterprise Architect is the direct complement to the Code Template Framework. While code templates are for converting a model to a textual form, grammars are required to convert text to a model. Both are required to synchronize changes into your source files.

An  example language source file and an example Grammar for that language are provided in the Code Samples directory, which you can access from your installation directory (the default location is C:\Program Files\Sparx Systems\EA). Two other grammar files are also provided, illustrating specific aspects of developing Grammars.

Components

Component

Description

See also

Grammar Syntax

Grammars define how a text is to be broken up into a structure, which is necessary when you are converting code into a UML representation. At the simplest level, a grammar is instructions for breaking up an input to form a structure.

Enterprise Architect uses a variation of Backus–Naur Form (nBNF) to include processing instructions, the execution of which returns structured information from the parsed results in the form of an Abstract Syntax Tree (AST), which is used to generate a UML representation.

 

Grammar Syntax

Grammar Editor

The Grammar Editor is an in-built editor that you can use to open, edit, validate and save grammar files.

 

Editing Grammars

Grammar Debugging

You can debug the grammar files you create using two facilities:

The Parser, which generates the AST for the Grammar
The Profiler, which also parses the Grammar and generates the AST but which exposes the Profiling pathway to show exactly what happened at each step of the process

 

 

Parsing AST Results

Profiling Grammar Parsing

 

Learn more

Add Code Modules (to an MDG Technology)