Xtext, BNF, Marte and MSCs

Currently we are doing some work on the specification of non-functional properties (such as timing) in the ITEA2 VERDE project. In VERDE, the UML profile MARTE plays a major role. MARTE has a BNF-based Value Specification Language that can be used to specify, amongst other things, timing like The VSL is specified in typical BNF notation

<value-specification> ::= <literal> | <enum-specification> | <interval> |
<collection> | <tuple> | <choice> | <expression> |
<time-expression> | <obs-call-expression>

Creating a Xtext grammar is very easy, but re-typing and manually transforming from BNF to Xtext is boring. Obviously, with a Xtext grammar for BNF, we could easily transform the MARTE BNF into a MARTE Xtext grammar and work with that. The first shot is a grammar like

grammar de.itemis.verde.Bnf with org.eclipse.xtext.common.Terminals

generate bnf “http://www.itemis.de/verde/Bnf”

Model:
(rules+=Rule)*;

Rule : “<“name=RULENAME”>” “::=” e=Expression ;

Expression :
el+=OredElement (“|” el+=OredElement)*;

OredElement:
(terms+=Term)+;

//LineEnd: EOL+;

//List: Term | (t=Term l=List);

Term: o=OptionalExp | l=ListExp | k=KeyConstr | r=RuleCall;

OptionalExp:    “[” x=Expression “]” (mult?=”*”)?;
ListExp:  “(” x=Expression “)” (plus?=”+”)? (mult?=”*”)? ;
KeyConstr:  k+=Keyword (“..” k+=Keyword)? ;

Keyword:
text=STRING;

RuleCall:
“<“ref=[Rule|RULENAME]”>”;

terminal RULENAME : (‘a’..’z’|’A’..’Z’|’-‘) (‘a’..’z’|’A’..’Z’|’-‘|’0’..’9′)* ;

An additional Xpand templates generates a nice Xtext grammar. Now we just have to get rid of the left recursion. As there is an algorithm for that too, we are thinking of putting that algorithm in the generator.

Another application could be the generation of a parser for the textual format for message sequence charts, as this definition is also available in BNF.

2 thoughts on “Xtext, BNF, Marte and MSCs

  1. I stumbled upon this post and I was wondering if you can provide some of the details (yes it is is a fairly old post, I realise) related to the XPand templates used to generate Xtext grammar model from a BNF model as I have to deal with a similar issue. The algorithm for getting rid of problems such as left recursion will also be highly appreciated. Thanks in advance!

  2. Sorry, it is fairly old and we didn’t pursue this much further, so I don’t have the files anymore.

Leave a Reply

Your email address will not be published. Required fields are marked *