Mrz 10
12
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.