Topic
Prev Next

Grammar Syntax

Grammars define how a text is to be broken up into a structure, which is exactly what is needed when you are converting code into a UML representation. At the simplest level, a grammar is just instructions for breaking up an input to form a structure. Enterprise Architect uses a variation of Backus–Naur Form (BNF) to express a grammar in a way that allows it to convert the text to a UML representation. What the grammar from Enterprise Architect offers over a pure BNF is the addition of processing instructions, which allow structured information to be returned from the parsed results in the form of an Abstract Syntax Tree (AST). At the completion of the AST, Enterprise Architect will process it to produce a UML model.

Syntax

Syntax

Detail

See also

Comments

Comments have the same form as in many programming languages.

// You can comment to the end of a line by adding two /s.

/* You can comment multiple lines by adding a / followed by a *.

The comment is ended when you add a * followed by a /. */

Instructions

Instructions specify the key details of how the grammar works. They are generally included at the top of the grammar, and resemble function calls in most programming languages.

Grammar Instructions

Rules

Rules make up the body of a grammar. A rule can have one or more definitions separated by pipe delimiters (|).

For a rule to pass, any single complete definition must pass. Rules are terminated with the semi-colon character (;).

Grammar Rules

Definitions

A definition is one of the paths a rule can take. Each definition is made up of one or more terms.

Definition Lists

A definition list corresponds to one or more sets of terms. These will be evaluated in order until one succeeds. If none succeed then the containing rule fails. Each pair of definitions is separated by a | character.

This is a simple rule with three definitions:

<greeting> ::= "hello" | "hi" | ["good"] "morning";

Terms

A term can be a reference to a rule, a specific value, a range of values, a sub-rule or a command.

Grammar Terms

Commands

Like instructions, commands resemble function calls. They serve two main purposes:

  • To process tokens in a specific way or
  • To provide a result to the caller
Grammar Commands Context Labels

Learn more