<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Transition from EBNF to Xtext</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Jianan Yue</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>State Key Laboratory for Novel Software Technology, Nanjing University Department of Computer Science &amp; Technology, Nanjing University 210023</institution>
          <addr-line>Nanjing</addr-line>
          ,
          <country country="CN">China</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Xtext is a framework for developing programming languages and domain speci c languages (DSLs). Xtext contains a language infrastructure including parsers, compiler and interpreter. In recent years, it has been applied to develop various DSLs. To bene t from Xtext, in certain cases, it is needed to transform an Extend Backus Naur Form (EBNF) based language to the Xtext grammar. For example, the wellknown UML pro le MARTE has a BNF-based Value Speci cation Language (VSL). It is needed to transform MARTE VSL in EBNF to a MARTE VSL Xtext grammar for the purpose of enabling tool integration. In this paper, as the rst step towards a fully automated transformation from EBNF to Xtext, a number of transformation rules are de ned. The ultimate objective of the project is to provide developers a fully featured and customizable Eclipse-based IDE for developing DSLs using EBNF grammar or enabling tool integration by providing transformation from EBNF to Xtext.</p>
      </abstract>
      <kwd-group>
        <kwd>Xtext</kwd>
        <kwd>EBNF</kwd>
        <kwd>meta-model</kwd>
        <kwd>DSL</kwd>
        <kwd>Transformation</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        Xtext[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] gains increasing popularity as a framework to developing Domain
Speci c Languages (DSLs)[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. It generates not only a parser, but also the meta-model
for the grammar and an Eclipse-based IDE integration. Users in speci c elds
can generate their own DSL e ciently.
      </p>
      <p>
        While Model Driven Engineering (MDE)[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] techniques have been developed
and applied widely, a growing number of DSLs in di erent grammar forms (i.e.,
model form and text form) was proposed and applied in many elds. Unlike
traditional programming language, language tools such as Xtext and EMFText[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]
are model-driven in the sense that they link text patterns with model patterns.
However, many DSLs de ne the grammar of text and model separately,
particularly using the EBNF[
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] text form to describe the text grammar and managing
the meta-model to construct the modeling grammar. As the result of such a
fashion of separation of concerns, it is needed in practice to translate a EBNF-like
style to the Xtext grammar form in order to use Xtext. For instance,
Architecture Analysis &amp; Design Language (AADL)[
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] de nes its grammar in text based
on the EBNF pattern. If developers want to support AADL by Xtext, they need
to translate the original de nition to the Xtext form grammar. Another example
is that the well-known MARTE[
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] pro le de nes the Value Speci cation
Language (VSL), which is BNF-based. There is therefore a need to transform the
MARTE BNF into a MARTE Xtext grammar.
      </p>
      <p>
        Few resources [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] have been identi ed to contain discussions on generating
EBNF descriptions for Xtext-based DSLs for the purpose of understanding and
using the Xtext-based DSLs, since EBNF is considered more familiar to users,
compared to Xtext. We did not nd any resource or related work on the transition
from EBNF to Xtext, except [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], where only the motivation of the transition was
described.
      </p>
      <p>The transition method follows certain rules depending on the EBNF
grammar pattern. In this proposal, several common patterns are presented and
transformed to Xtext grammar sentences. After all Xtext codes are generated, we
can use Xtext to get corresponding meta-model and DSL's IDE. As part of the
future work, we will automate the transition.
2</p>
      <p>Relationship between EBNF and Xtext's Grammar
First, the notations used in EBNF can all be translated to corresponding Xtext
notations, as shown in Table 1. In EBNF, the terminals are strings quoted by
a pair of double quotation marks. While single quotation marks can be used in
Xtext, the terminals in Xtext can also be de ned by user using terminal rules.</p>
      <p>In addition, Xtext has more notations. The notation `(...)+' can describe the
cardinalities one or more. The operator `..' can describe character ranges such
as (`0'..`9'), which could de ne the common terminal INT.</p>
      <p>Xtext has a special kind of rules that return the enumeration strings: Enum
Rules. The same pattern can appear in EBNF, but EBNF does not o er simiar
kinds of rules. Thus, when an enumeration pattern is detected in EBNF, it is
transferred into Enum Rules in Xtext.</p>
      <p>A parser rule is regarded as a tree of non-terminal and terminal tokens.
In EBNF, the rules are simply described as the combination of non-terminals,
terminals or both. However, Xtext has an even stronger representation that
can relate to semantics of a meta-model. In Xtext, we can use the assignment
notations `=' and `+=' (multi-valued feature) to assign a feature to a
nonterminal object.</p>
      <p>
        Though left recurrences are allowed in EBNF rules, they cannot occur in
the Xtext input since Xtext leverages the ANother Tool for Language
Recognition (ANTLR)[
        <xref ref-type="bibr" rid="ref10">10</xref>
        ], which implements an LL parser[
        <xref ref-type="bibr" rid="ref11">11</xref>
        ]. Nonetheless, a required
transition can eliminate the left recurrence in EBNF and form reasonable Xtext
rules.
      </p>
      <p>In summary, for as an arbitrary EBNF rule, there exists a corresponding
Xtext format description. Therefore, the transition from EBNF to Xtext is
possible.
3</p>
      <p>EBNF to Xtext Transition Processes
To implement the transition from EBNF to Xtext, certain procedures are
required. As shown in Fig. 1, before we get the Xtext description structure, we
have to make decisions according to the certain patterns of a EBNF rule and
take some actions accordingly as highlighted (yellow boxes) in the gure. In
this section, the four di erent actions highlighted in the yellow rectangles are
discussed respectively.</p>
    </sec>
    <sec id="sec-2">
      <title>Transform Enumeration</title>
      <p>For a EBNF pattern with one terminal in every alternation:
1. Add Enum in the left of the de ned nonterminal;
2. Assign new meta-model features to every alternations in Xtext.
As shown in Row 2 of Table 2, the nonterminal Operation is changed to Enum
Operation, ADD and SUB are two features of the object Operation.</p>
    </sec>
    <sec id="sec-3">
      <title>Remove Left Recursion</title>
      <p>If a left recursion occurs in a EBNF rule:
1. Replace the left recursion by a new nonterminal in corresponding Xtext
input;
2. Add the new de ned nonterminal as a new alternation in Xtext rule;
3. Transport alternations that do not have the left recursion in EBFN rule to
the new de ned nonterminal.</p>
      <p>The left recursion A in Column 1 Row 3 of Table 2 is replaced by AtomA.</p>
    </sec>
    <sec id="sec-4">
      <title>Extract Common Factors</title>
      <p>For a right recursive EBNF grammar pattern like A=B jBA, if B is not a simple
nonterminal or terminal:
1. Extract the common factors B as a new Xtext grammar rule;
2. The original rule is changed to (newid += B)+, where newid is a
multivalued feature of object A in meta-model.</p>
      <p>In Row 4 of Table 2, the common factors B\:"C can be extracted as a new rule.</p>
    </sec>
    <sec id="sec-5">
      <title>Transform Notations</title>
      <p>As shown in the last row of Table 2, for a general EBNF pattern without
recurrence and enumeration, the transition rule is:
1. Change notations to the comparable ones in Xtext as described in the above
section;
2. For every nonterminal in the right-hand of the de nition, add an identi er
and an assignment notation in the left of the nonterminal to assign a feature
to the currently produced object of corresponding meta-model.</p>
      <p>
        Case Study: A Complete Transition Instance
This section illustrates the complete transition from EBNF rules to the
corresponding Xtext rules, as shown in Fig. 2, of a declarative query language named
JIns[
        <xref ref-type="bibr" rid="ref12">12</xref>
        ].
      </p>
    </sec>
    <sec id="sec-6">
      <title>EBNF rules</title>
      <p>S = "select" RS "from" SP ["for" "all" DS] "where" CE
RS = Id":"T|Id":"T RS
DS = RS "satisfying" CE
T = "interface"|"class"|"method"|"object"|"statement"
SP = "repository" STRING
CE = CE"&amp;&amp;"CE|CE"||"CE|"("CE")"|"!"CE|ID"."Att"="STRING
|ID"."Att"="ID"."Att|ID Rel ID;
Att = "name"|"modifier"|"type"|"returnType"|"paramsType"
Rel = "extends"|"implements"|"in"|"call"|"use"
To better bene t from Xtext, in some contexts, it is needed to transform an
Extend Backus Naur Form (EBNF) based language to the Xtext grammar.
Therefore, in this paper, we proposed four processes of transition from EBNF to Xtext.
As a future work, we will develop a tool to support the automated transition
and conduct case studies to evaluate the proposed approach.</p>
      <p>Acknowledgement This work is supported by the National Natural Science
Foundation of China (No.61472180), and by the Jiangsu Province Research
Foundation(BK20141322).</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>1. Xtext, http://www.eclipse.org/Xtext/</mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Fowler</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          : Domain Speci c Language.
          <string-name>
            <surname>Addison-Wesley Professional</surname>
          </string-name>
          ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Schmidt</surname>
          </string-name>
          , D. C.
          <article-title>Guest Editor's Introduction: Model-Driven Engineering</article-title>
          . IEEE Computer 39:
          <fpage>25</fpage>
          -
          <lpage>31</lpage>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>4. EMFText, http://www.emftext.org/index.php/EMFText</mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>Extended</given-names>
            <surname>Backus-Naur</surname>
          </string-name>
          <string-name>
            <surname>Form</surname>
          </string-name>
          , http://en.wikipedia.org/wiki/Extended BackusNaur Form
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>SAE</given-names>
            <surname>Aerospace. SAE</surname>
          </string-name>
          <article-title>AS5506A: Architecture Analysis and Design Language (AADL)</article-title>
          .
          <source>Version 2.0</source>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          <article-title>7. The UML Pro le for MARTE: Modeling and Analysis of Real-Time and Embedded Systems</article-title>
          , http://www.omgmarte.org/
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Generate</surname>
            <given-names>EBNF</given-names>
          </string-name>
          -
          <article-title>Descriptions for Xtext-based DSL</article-title>
          , http://xtexterience.wordpress.com/
          <year>2011</year>
          /05/13/an
          <article-title>-ebnf-grammar-in-xtext/</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Xtext</surname>
            ,
            <given-names>BNF</given-names>
          </string-name>
          , Marte and MSCs, http://5ise.quanxinquanyi.de/2010/03/12/xtextbnf-marte-and-mscs/
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>10. ANTLR, http://en.wikipedia.org/wiki/ANTLR</mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>11. LL parser, http://en.wikipedia.org/wiki/LL parser</mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <surname>Zhang</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zheng</surname>
            ,
            <given-names>X.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zhang</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zhao</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Li</surname>
            ,
            <given-names>X.</given-names>
          </string-name>
          <article-title>A declarative approach for Java code instrumentation</article-title>
          .
          <source>Software Quality Journal:</source>
          <fpage>1</fpage>
          -
          <lpage>28</lpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>