<!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>Defining Semantic Variations of Diagrammatic Languages Using Behavioral Programming and Queries</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Michael Bar-Sinai</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Gera Weiss</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Assaf Marron</string-name>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Computer Science Department, Ben-Gurion University</institution>
          ,
          <addr-line>Be'er-Sheva</addr-line>
          ,
          <country country="IL">Israel</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Computer Science Department, Ben-Gurion University</institution>
          ,
          <addr-line>Be'er-Sheva</addr-line>
          ,
          <country country="IL">Israel</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Faculty of Mathematics and Computer Science, Weizmann Institute of Science</institution>
          ,
          <addr-line>Rehovot</addr-line>
          ,
          <country country="IL">Israel</country>
        </aff>
      </contrib-group>
      <fpage>5</fpage>
      <lpage>11</lpage>
      <abstract>
        <p>-We present a methodology for describing executable semantics of diagrammatic modeling languages, and an execution engine based on such definition. Under proposed methodology, languages are defined using a set of pairs, composed of a query and a group of mappers. The queries, defined over the language's diagrammatic syntax, return language constructs. These constructs are mapped by the mappers to behavioral programming-based models. Resultant definition is executable, can inter-operate with similar definitions of other languages, and is accessible to practitioners who read code but shy away from transition formulae. We demonstrate our approach by defining a subset of the LSC language, and by implementing an LSC runtime engine based on that definition.</p>
      </abstract>
      <kwd-group>
        <kwd>Modeling</kwd>
        <kwd>Computer Languages</kwd>
        <kwd>Software Engineering</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>I. INTRODUCTION</title>
      <p>
        Diagrammatic modeling languages hold great promise for
software engineering, being able to depict — quite literally
— structural and behavioral specifications. While some
diagrammatic languages have been adopted for
documentation and high-level design, their promise is still largely
unrealized when it comes to describing executable
models. Almost 30 years after Harel presented StateCharts [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ],
diagrammatic languages are still considered “doodles” by
many practitioners [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
      </p>
      <p>A few factors that might be holding back the adoption of
diagrammatic languages for execution are lack of accessible
definition of executable semantics, and the absence of
runtimes that can interoperate with text-based code.</p>
      <p>This paper proposes an approach for defining executable
semantics for diagrammatic languages. The definition is
accessible to anyone who can read procedural formulation,
and lends itself to runtime engine implementation. As the
runtime is based on the Behavioral Programming paradigm,
it can easily integrate with text-based code.</p>
      <p>The rest of this paper is organized as follows: Section II
briefly introduces Behavioral Programming. Sections III
and IV introduce and discuss the concept of querying
diagrams and mapping them to BP-based code, respectively.
Sections V and VI apply the approach to a subset of the
Live Sequence Chart language (LSC). Section VII describes
a runtime tool for LSC, implemented based on those
definitions. Section VIII demonstrates how the proposed
approach can be used to accommodate semantic variation
points. Section IX looks at related work, and Section X
concludes.</p>
      <p>II. A QUICK INTRODUCTION TO BEHAVIORAL PROGRAMMING</p>
      <p>
        Behavioral Programming (BP) [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], introduced by Harel,
Marron and Weiss in 2012 [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], is a programming paradigm
rooted in scenario-based programming. BP programs are
composed of threads of behavior, called b-threads.
Bthreads run in parallel to coordinate a sequence of events
via a synchronized protocol, as follows. During program
execution, when a b-thread wants to synchronize with its
peers, it submits a statement to the central event arbiter.
This statement declares which events it requests to be
selected, which events it waits for (but does not request),
and which events it would like to block (prevent from
being selected). When all b-threads have submitted their
statements, the arbiter selects an event that was requested
but not blocked. It then wakes up the b-threads that
requested or waited for that event. The rest of the b-threads
remain at their state, until an event they requested or
waited for is selected. Blocked and waited-for events can
be described using a predicate or a list. Requested events
have to be specified explicitly. In this paper, submitting the
synchronization statement is done by calling bsync.
      </p>
      <p>III. SEMANTIC MAPPING TO BEHAVIORAL PROGRAMMING
When defining semantics for a diagrammatic language,
we propose the language developer defines a set of pairs,
composed of a query and multiple mappers, and a set of BP
events called Source-Semantic Events. The queries, defined
over the source language’s terms and semantics, take a
diagram and return a set of language constructs. The
BPmappers take each returned construct and generate a set
of b-threads, called construct agent b-threads, or CABs.</p>
      <p>
        CABs act on behalf of their construct during program
execution. Source Semantic Events are used to signal events
in the original program, e.g. “message passed” for LSCs or
“step completed” in an Activity Diagram [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. The mapping
process is described in Figure 1.
      </p>
      <p>The set of query-mapper pairs define the executable
semantics of the diagrammatic language. Run together, CABs
generated by query-mapper pairs produce a valid execution
of the mapped program. An execution of a program is
considered “valid” if the order of the Source Semantic
Events in its trace complies with the requirements of the
diagrammatic language.</p>
      <p>From a BP point of view, there is nothing special about a
CAB or an source-semantic event. While both carry special
semantics for the diagrammatic program, these semantics
are only present in the interpretation of the behavioral
program’s event log — not while the program is executing.
BThread
Registration</p>
      <p>BProgram</p>
      <p>Query
source
code
result1
result2</p>
      <p>•••
resultk</p>
      <p>Semantic
Mapping</p>
      <p>CAB
C•••AB
CAB
CAB
C•••AB
CAB
CAB
C•••AB</p>
      <p>CAB
Source Language</p>
      <p>Mapping</p>
      <p>Behavioral Programming
Fig. 1. Defining operational semantics for diagrammatic languages using
querying and mapping. Queries select constructs from a diagram. Selected
constructs are mapped to one or more Construct Agent B-threads (CABs).
Run together, those CABs generate a valid execution of the original
program.</p>
    </sec>
    <sec id="sec-2">
      <title>IV. DISCUSSION</title>
      <p>Describing the semantics of a formal diagrammatic
language by mapping its constructs to BP is advantageous for
a number of reasons. Resultant definitions are both formal
and accessible, as they use simple code snippets rather
than transition formulae. Furthermore, the definitions are
executable, so language developers can test and verify them,
and readers can write programs to test their understanding.
This combination of readability, formality and executability
improves upon existing practices.</p>
      <p>
        Formality and executability are crucial for removing
ambiguities. Obviously, non-formal definitions might be
ambiguous (e.g. Chan et. al. about Java [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] and Fecher
et. al. about UML2.0 [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]). But even fully formal semantics
definitions that use transition formulae are prone to errors,
as shown by Klein et. al. in [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ].
      </p>
      <p>The structure of the resultant definition is intuitive and
easy to navigate, as the query-mappers pair structure is
similar to that of a language reference. Our experience is
that many CABs can be reused across multiple constructs.
As CABs define semantics, this is not just regular code reuse,
but also concept and comprehension reuse.</p>
      <p>The proposed approach allows language developers to
independently mix and match semantic variations of
language constructs, as changing the semantics of a single
construct is done by changing the relevant mapper only.
Adding and removing language constructs can be
experimented with in a similar way (See Section VIII).</p>
      <p>
        Additionally, this type of definition allows for
program analysis. For example, model checking tools such as
BPMC [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], can verify that under a given specification, a
certain event will always precede another.
      </p>
      <p>Finally, since BP serves as common ground to
diagrammatic languages defined using the proposed approach,
these executable definitions allows for language
interoperation. We have demonstrated such interoperation between
LSC and UML Activity Diagram.</p>
      <p>Our proposed approach is, of course, not perfect. When
a language construct is mapped to many CABs, the reader
is required to keep in mind the state of those CABs in order
to fully comprehend that construct’s behavior. This issue is
somewhat alleviated by CAB comprehension reuse. Another
issue is that the definition relies on BP, which is still in early
adoption stages.</p>
      <p>V. CASE STUDY: SEMANTIC VARIATIONS OF LSC</p>
      <p>
        We will now demonstrate our approach by creating the
operational semantics of a subset of Live Sequence Charts
(LSC). LSC is a diagrammatic programming language that
extends classical message sequence charts, mainly with
a universal interpretation and must/may, monitor/execute
modalities. The language was developed by Damm and
Harel [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] and was first implemented by a tool called
PlayEngine [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ]. A UML compliant variant is implemented by
the PlayGo tool [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ]. The semantics of the PlayGo
version, which slightly differ from Play-Engine’s, are described
in [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ].
      </p>
      <p>An LSC system consists of scenarios and objects. Each
scenario describes a facet of the system’s behavior and is
described in a live sequence chart (an LSC). The overall
system behavior is the result of concurrent execution of all
the LSCs it contains. An example LSC is shown in Figure 2.</p>
      <p>Objects, which appear in LSCs as lifelines, can send
messages to each other or to themselves. Sending these
messages is depicted in the charts by horizontal arrows between
lifelines. Messages can be tagged as must occur (“hot”, red)
or may occur (“cold”, blue), and as executed (“execute”,
solid) or waited for (“monitor”, dashed). The Play-Engine
variant supports both synchronous and asynchronous
messages; in PlayGo, all messages are synchronous.</p>
      <p>Each LSC is comprised of lifelines and messages. LSCs
may contain variable assignments and flow-control
elements, such as loops and conditional execution. Special
kinds of lifelines represents the user and the environment.
Conditional guards, shown as elongated hexagons, specify
statements that must be true for the execution to continue.
A special condition called SYNC, always evaluates to true
and is used to synchronize lifelines.</p>
      <p>card1:Card card2:Card
click()
click()</p>
      <p>SYNC
!(c1.value.equals(c2.value))</p>
      <p>flipDown()
flipDown()
p:Panel
beep()</p>
      <p>The point where a lifeline intersects with a message,
a condition, or any other language construct, is called a
location. During execution, lifelines proceed along their
locations in downward vertical order. The collection of all
current lifeline locations in an LSC, called a cut, is the
equivalent of a program counter in traditional code.</p>
      <p>The execution of an LSC consists of a series of events,
such as message passing or condition evaluations. An event
is called enabled when all its preconditions have been
met — involved lifelines have arrived at their respective
locations, and variables have been bound, etc. At runtime,
the LSC engine repeatedly selects an enabled event for
execution. Then lifelines move to their next locations, and
the chart’s cut is updated.</p>
      <p>The system avoids executing forbidden events whenever
possible. Forbidden events may be specified in various
ways: A scenario of events ending in a hot false
condition is considered forbidden. When an LSC is “strict”,
all events that appear in it and are not enabled by its
cut are forbidden. Finally, the Play-Engine variant allows
tagging individual events as forbidden in some designated
scope. When a forbidden event is nevertheless executed, an
exception called violation occurs.</p>
      <p>LSC is an interesting language for demonstrating our
proposed approach, since it is a real-world diagrammatic
language with non-trivial semantics. Additionally, it has
multiple semantic variants, which allows us to mix and
match semantics of specific constructs.</p>
      <p>This paper focuses on the operational semantics of a
single LSC and on a subset of the constructs. The construct
subset was selected such that it contains examples for all
construct types, and so it can be intuitively extended.</p>
    </sec>
    <sec id="sec-3">
      <title>VI. A VISUAL DICTIONARY FOR LSC</title>
      <p>In this section we present a visual dictionary that lists the
syntactic query and BP-mapping for each LSC construct.
Query matches are highlighted with a yellow background.
For example, in the Sync definition (Subsection VI-B), the
SYNC hexagon and the intersection of its upper edge are
matched, and are labeled snc and l1 to ln for the purpose of
the BP-mapper pseudo-code that follows. CABs composing
the BP-mapping for the construct matched by each query
appear after the query’s diagram. Re-used CABs are referred
to by name, and listed at Subsection VI-J. This graphical
representation of the queries is an idea for future
implementations that may allow for an intuitive specification of
language constructs. In our current implementation we use
a textual query language and the graphical representation
is compiled manually for the sake of readability.</p>
      <p>All CABs exit when an exit event of their parent chart is
triggered. This is done using the BP idiom of break-upon:
bthreads terminate when an event whose a member of their
set of break-upon events is triggered. We use break-upon
for readability — it is possible to simulate it using pure
Request-WaitFor-Block, by adding the break-upon event set
to the wait parameter of every bsync, and then exiting if the
triggered event is a member of this set.</p>
      <p>BP allows blocking and waiting for abstract sets of
events. The model in this paper uses two such event
sets: VisibleEvents, which contains all message passings,
and ExitEvents(chart), which contains all events signaling
execution termination of a chart or a subchart.</p>
      <p>Code listings in this paper serve both as an
implementation and as a specification. Thus, we invite the
reader to read them as both imperative and declarative.
As an imperative code, bsync(waitFor:E, block:VisibleEvents)
reads “wait for E, and until then block all visible events”.
When read declaratively, it says “No visible event can
happen until E does”.</p>
      <sec id="sec-3-1">
        <title>A. Lifeline</title>
        <p>chartName</p>
        <p>L1
loop until *</p>
        <p>name
Li
l1
cond
l2
l3
cond
msg
msg
msg
l4
ln</p>
        <p>Ln
chart</p>
        <p>Lifeline CABs are responsible for advancing the chart’s
cut. A lifelineCAB, started by its parent chart, begins by
waiting for its parent chart’s start event (first bsync). It then
advances along its locations, repeatedly requesting to enter
and leave them. During execution, a lifelineCAB blocks its
parent chart from ending normally.</p>
        <p>During the execution of subcharts, such as Loop
(Subsection VI-I), lifelineCABs wait for the subchart to be over;
L1
L1</p>
        <p>L2
L2
This CAB forces the message passing event to be
enabled prior to being triggered. The concept of an
event being “enabled” is part of the LSC language, and
so Enabled(m) serves as a source semantic event.</p>
      </sec>
      <sec id="sec-3-2">
        <title>D. Hot, Executed Message</title>
        <p>A “hot” message has to be executed once it was enabled
(unlike a “cold” message which may or may not happen).
The difference in behavior is achieved by adding a single
CAB, as shown below. The rest of the CABs are reused.
m(v1,..vn) l
l1 message(v1,..vn)
2
² Same CABs as for the cold, executed message.
² A TriggeredBlockUntilCAB, where the trigger event is
Enabled(m), after which the event set ExitEvents(chart)
is blocked until Message(m) is selected.</p>
        <p>E. Cold, Monitored Message
inside the subchart, new lifelineCABs act on behalf of the
lifelines. This is achieved by the if statement at the top of
the iteration loop.</p>
        <p>² Lifeline CAB:
lifelineCAB (chart , l1 , ..., ln):
bsync ( waitFor : ChartStart ( chart ) )
for ( i 2 [1.. n] ):
if ( li is at bottom of subchart ):
bsync ( wait : Done (subchart),</p>
        <p>block : ChartEnd ( chart )
bsync ( request : Enter (li),</p>
        <p>block : ChartEnd ( chart ), VisibleEvents )
bsync ( request : Leave (li),</p>
        <p>block : ChartEnd ( chart ))</p>
      </sec>
      <sec id="sec-3-3">
        <title>B. Sync</title>
        <p>² For each i 2 {1, . . . , n} instantiate a BlockUntilCAB,
blocking Enabled(snc) until Enter(li) is selected.
² For each i 2 {1, . . . , n} instantiate a BlockUntilCAB,
blocking Leave(li) until snc is selected.
² Instantiate the following CAB:
syncCAB ( snc ):
bsync ( request : Enabled ( snc ), block : Sync ( snc ))
bsync ( request : Sync ( snc ), block : VisibleEvents )
This CAB enforces the SYNC to be enabled prior to
being triggered. By blocking VisibleEvents in the second
bsync, this CAB ensures that once enabled, the SYNC
will be triggered prior to any visible event.</p>
      </sec>
      <sec id="sec-3-4">
        <title>C. Cold, Executed Message</title>
        <p>² Instantiate two BlockUntilCABs, blocking Enabled(m) until
Enter(li) is selected (for i 2 {1, 2}). In case the sender
lifeline is also the receiver, it is possible to omit one of
these CABs.
² Instantiate two BlockUntilCABs, blocking Leave(li) for i 2
{1, 2} until Message(m) is selected.
² For each variable v not affected by m, instantiate a
BlockUntilCAB, blocking Enabled(m) until Bound(v) is
selected. These CABs prevent m from being enabled until
all variables it depends on are bound.
² For each variable v affected (bound) by m, instantiate a
BindFromCAB, binding v when Message(m) is selected. These
CABs announce the binding made by m for v.
² Instantiate a single ceMessageCAB (shown below):
ceMessageCAB (m):
bsync ( request : Enabled (m), block : Message (m))
bsync ( request : Message (m))
m(v1,..vn) l
l1 message(v1,..vn)
2
² Except for the ceMessageCAB, all CABs used for the cold,
executed message (Subsection VI-C) are reused “as is”
for the cold, monitored one.
² Instantiate a single cmMessageCAB (below). This CAB is
identical to the ceMessageCAB, except for the second bsync
call which waits for the message passing event rather
than requests it.
cmMessageCAB (m):
bsync ( request : Enabled (m), block : Message (m))
bsync ( waitFor : Message (m))</p>
      </sec>
      <sec id="sec-3-5">
        <title>F. Hot, Monitored Message</title>
        <p>L1</p>
        <p>L2
m(v1,..vn) l
l1 message(v1,..vn)
2
² Same CABs as for the cold, monitored message.
² An additional TriggeredBlockUntilCAB, as for the hot,
executed message.</p>
      </sec>
      <sec id="sec-3-6">
        <title>G. Cold Condition</title>
        <p>L1</p>
        <p>L2
l1</p>
        <p>l2
² For i 2 {1..n}, instantiate a BlockUntilCAB, blocking</p>
        <p>Enabled(cnd) until Enter(li) is selected.
² For i 2 {1..n}, instantiate a BlockUntilCAB, blocking</p>
        <p>Leave(li) until Condition(cnd) is selected.
² Instantiate a single coldConditionCAB (below) with the
matched parameters.
coldConditionCAB ( cnd ):
bsync ( request : Enabled ( cnd ),</p>
        <p>block : Condition ( cnd ))
if ( evaluate ( cnd ) ):</p>
        <p>resultEvent = Condition ( cnd )
else :</p>
        <p>resultEvent = ColdViolation ( cnd )
bsync ( request : resultEvent , block : VisibleEvents )</p>
      </sec>
      <sec id="sec-3-7">
        <title>H. Hot Condition</title>
        <p>cnd
² Same as cold condition (Subsection VI-G), except that
hotConditionCAB requests a HotViolation event.</p>
      </sec>
      <sec id="sec-3-8">
        <title>I. Loop</title>
        <p>An LSC loop is a type of a subchart: It can contain any
LSC construct, including other loops, but uses the lifelines
of its parent chart. A cold violation of a loop terminates it,
but not its parent chart.</p>
        <p>For every match of:</p>
        <p>L1</p>
        <p>L2
l1,1 l2,1
loop until *x ctrl</p>
        <p>Ln
ln,1</p>
        <p>loop
l1,2 l2,2
ln,2</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Instantiate the following CABs:</title>
      <p>² BlockUntilCAB, waiting for Leave(li,1), while blocking</p>
      <p>Enabled(loop).
² loopCAB (see below) with the matched parameters.
loopCAB ( loop , ctrl ):
bsync ( request : Enabled ( loop ) )
loopIteration (loop , ctrl )
bsync ( request : Done ( loop ), block : VisibleEvents )
loopIteration ( loop , ctrl ):
if ( ctrl &gt; 0 ):
startCABs ( loop )
bsync ( request : ChartStart ( loop ),block : VisibleEvents )
event = bsync ( request : ChartEnd ( loop ),</p>
      <p>waitFor : ExitEvents ( loop ))
if ( event is ChartEnd ( loop ) ):
loopIteration (ctrl -1, loop )
loopIteration. After the last iteration, it announces the
loop is done by requesting a Done(loop) event.
Blocking VisibleEvents ensures that once the loop is done,
it is declared as such prior to any message being
passed. The loopIteration sub-routine starts by checking
whether a new iteration is needed. If so, it creates
the CABs for the loop subchart, and requests its start
event to be fired. This event signals the lifeline CABs
of the subchart to start advancing along their location
list. When the subchart execution is done, loopIteration
checks whether the subchart ran to completion. If
so, another iteration is attempted1. While the loop
construct is executing, the lifelines of the parent chart
waitFor it to end before entering their next location,
below the chart.</p>
      <sec id="sec-4-1">
        <title>J. Reused CABs</title>
        <p>Common behavior aspects of constructs of the LSC
language are captured for reuse by the following CABs:
1) BlockUntilCAB: This CAB block an event until another
one is triggered. Used in all constructs to enforce correct
execution order, the code for this CAB consists of a single
bsync call.
blockUntilCAB ( blocked , waitedFor ):
bsync ( waitFor : waitedFor , block : blocked )
2) TriggeredBlockUntilCAB: This CAB waits for an event,
and then blocks a set of events until another event is
selected.
triggeredBlockUntilCAB ( trigger , blocked , waitedFor ):
bsync ( waitFor : trigger )
bsync ( waitFor : waitedFor , block : blocked )
3) BindFromCAB: This CAB is responsible for binding a
single variable to a value extracted from a message. It waits
for the message to be sent, and then requests a binding
event announcing the new binding.
bindFromCAB ( message , variable ):
selected = bsync ( waitFor : message )
value = selected . message . get ( variable )
bsync ( request : Bound ( variable , value ),
block : VisibleEvents )</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>VII. IMPLEMENTATION</title>
      <p>
        In order to test our approach, we implemented an LSC
runtime engine. The engine takes an XML description of an
LSC as input. It then uses XQuery [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ] for both querying
the source code and for generating BP code. The BP code
is then executed normally, using a standard BP library.
      </p>
      <p>Input: LSCs are described using straightforward
XMLbased format. Reminiscent to a verbal description of an
LSC, the format includes nodes such as &lt;lifeline&gt; and
&lt;message&gt;.</p>
      <p>A loopCAB starts by requesting its loop is enabled. It
then runs the loop repeatedly, using the sub-routine
1For the special case of control value *, which means unbounded
amount of iterations, we define *-1=*.</p>
      <p>
        Queries and BP-Mappers: Queries over the XML files
are done using XQuery. We use the BaseX [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ] query engine
which implements the XQuery 3.1 W3C standard [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ], with
no modifications. As LSCs contain recursive structures, the
XQuery program consists of a top-level recursive query
which is used to query to top-level chart. It then recurses
down the chart containment hierarchy, querying over each
construct it finds and mapping it to BP code. Construct
queries look very much like the construct definitions listed
above, phrased in XQuery (see Listing VII.1).
declare function local : message ( $msg as node () )
as xs: string {
let $l1 := lsc : loc ( $msg /@from , $msg / @fromloc )
(* more value definitions ( omitted ) *)
return string - join ((
lsc : blockUntilCAB ( $msgEnabled , lsc : Enter ($l1 , $chartId )),
lsc : blockUntilCAB ( $msgEnabled , lsc : Enter ($l2 , $chartId )),
lsc : messageCAB ($l1 ,$l2 , $content ),
lsc : blockUntilCAB ( lsc : Leave ($l1 , $chartId ), $msgEvent ),
lsc : blockUntilCAB ( lsc : Leave ($l2 , $chartId ), $msgEvent )
), $newline )
};
Listing VII.1. XQuery code for detecting &lt;message&gt; nodes and generating
the BPjs-based Javascript code that implements them. Compare this to
the definition of cold, executed message (Subsection VI-C). The methods
called by this query, such as lsc:messageCAB, return Javascript code.
      </p>
      <p>
        BP engine: Generated BP code uses Javascript and the
BPjs [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ] library. BPjs was originally developed for [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ]. As
part of this work, we have heavily modified it to become a
general purpose BP library. These modifications, however,
did not include changes to specifically accommodate code
generated by the XQuery part of the engine.
      </p>
      <p>Using this engine, LSCs described using our XML
format can be directly executed. The code is available at
https://github.com/michbarsinai/BP-javascript-search.</p>
    </sec>
    <sec id="sec-6">
      <title>VIII. SEMANTIC VARIATIONS</title>
      <p>
        Previous sections presented the concept of querying
source code and mapping the results to BP as a mechanism
for “breathing semantics into diagrammatic languages”, to
paraphrase [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]’s title. This mechanism allows for
independently adding, removing, and altering the semantics of
each construct, and for adding new constructs or removing
them altogether. This section demonstrates such alterations,
using the LSC example presented above.
      </p>
      <sec id="sec-6-1">
        <title>A. Asynchronous Message</title>
        <p>The messages described in Section VI are synchronous.
We will now add an asynchronous message, which allows
the sending lifeline to advance passed the send location
without waiting for the receiving lifeline to receive the
message. This type of messages exists only in the
PlayEngine variant; PlayGo does not support it.</p>
        <p>Instantiate the following CABs:
² BlockUntilCAB, blocking Enabled(m), waiting for Enter(l1).
² BlockUntilCAB, blocking Received(m), waiting for Enter(l2).
² BlockUntilCABs, blocking Received(m), waiting for Sent(m).
² BlockUntilCAB, blocking Leave(l1), waiting for Sent(m).
² BlockUntilCAB, blocking Leave(l2), waiting for Received(m).
² For each variable v not affected by m, a BlockUntilCAB,
blocking Enabled(m), waiting for Bound(v).
² For each variable v affected (bound) by m, a BindFromCAB,
blocking Sent(m), waiting for v.
² A single asyncMessageSendCAB (shown below), forcing the
message sending event to be enabled prior to being
triggered.
asyncMessageSendCAB (m):
bsync ( request : Enabled (m), block : Sent (m))
bsync ( request : Sent (m))
² A single asyncMessageReceiveCAB, requesting that the
message is received.
asyncMessageReceiveCAB (m):</p>
        <p>bsync ( request : Received (m))
As there are blockUntilCABs blocking the message from
being received prior to being enabled, fully bound,
sent, and having a lifeline in location to receive it, this
CAB does not need to handle all these preconditions
and their possible orderings.</p>
        <p>The mapping for asynchronous messages can be used
either as a replacement for the synchronous message
mapping, making all messages asynchronous (e.g. in a “what
if we made all messages asynchronous” scenario), or as a
mapping for a new type of specification idiom.</p>
      </sec>
      <sec id="sec-6-2">
        <title>B. Strict vs. Tolerant Modes</title>
        <p>An LSC can be strict or tolerant. A Strict LSC is violated if
an event that appears in it happens when it is not enabled.
Such event will not cause any violation for a tolerant LSC.
In PlayGO, all LSCs are strict. In Play-Engine, both modes
are allowed.</p>
        <p>Strictness can be imposed by adding b-threads to the
mapping of a chart, one for each message appearing in
the LSC. Each b-thread is initialized with the events that
are present in its respective chart. The function cut(chart)
returns the cut of chart, which is the set of all the locations
its lifelines are currently in. Obtaining the cut of a given
chart does not require direct communication with that chart
or its lifelines — the cut can be obtained by waiting for the
Enter events of that chart’s locations. A cut is considered
HOT if at least one of its locations is HOT.
chartEvents = events_of ( chart )
nonBlocked = ;
repeat :
event = bsync ( waitFor : AllEvents ,</p>
        <p>block : chartEvents \ nonBlocked )
if ( event is Enabled (x) ):</p>
        <p>nonBlocked = nonBlocked [ {x}
else if ( event 2 nonBlocked ):</p>
        <p>nonBlocked = nonBlocked \ { last_event }
else :
if ( isHot ( cut ( chart )) ):</p>
        <p>bsync ( request : HotViolation , block : VisibleEvents )
else :</p>
        <p>bsync ( request : ColdViolation , block : VisibleEvents )
Listing VIII-B.2. Enstrictor, a b-thread that makes an LSC strict</p>
      </sec>
      <sec id="sec-6-3">
        <title>C. Adding a Type System by Blocking</title>
        <p>The LSC implementation presented so far uses dynamic
typing, as it does not verify that receiving lifelines
implement the messages they receive. Using event blocking, we
can block messages unimplemented by their receiver in a
purely incremental manner, by adding a b-thread.</p>
        <p>BP allows b-threads to block sets of events by
passing a predicate to bsync. InvalidMessages, defined in
Listing VIII-C.3, is a predicate valid for all messages
unimplemented by their receiver. In order to prevent these
messages, the typeSystemBThread can be added to the system.
InvalidMessages ( msgEvent ):
return</p>
        <p>msgEvent . message 62 msgEvent . receiver . definedMessages
typeSystemBThread :</p>
        <p>bsync ( block : InvalidMessages )
Listing VIII-C.3. Type System Event Set and BThread. This code assumes
each lifeline has a list of defined operations</p>
        <p>Traditionally, when typing constraints are imposed on
a program, they are imposed on all of it. Our proposed
approach of imposing typing constraints offers more
flexibility: It can be lifted or imposed with no change to the rest
of the code. It can be limited to parts of the code by altering
the predicate. Or, it can pass the invalid method call to a
special handler that can perform any arbitrary operation.
This is somewhat similar to SmallTalk’s doesNotUnderstand:
method, invoked when an object receives a message it has
no method for.</p>
      </sec>
    </sec>
    <sec id="sec-7">
      <title>IX. RELATED WORK</title>
      <p>
        The notion of describing semantics by mapping one
domain onto another is not new. AToM3 [
        <xref ref-type="bibr" rid="ref18">18</xref>
        ], for example,
is a tool for creating and transforming meta-models, uses
graph-based meta-models and transformations to achieve
this. UML [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] has its own metamodel, used to describe
its diagrams. Executable UML [
        <xref ref-type="bibr" rid="ref19">19</xref>
        ] (also known as fUML)
adds executable semantics to a subset of UML’s diagrams.
Our work differs from both in that it does not use a
metamodel per se — the queries extract data from the source
language, but the result is still in the source language, not
in a metamodel.
      </p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref20">20</xref>
        ], Latombe et. al. presented a way of coping with
semantic variations in domain specific modeling languages.
They use a 2-tier structure, where the top tier lists all
options according to a set of available semantics, and
the lower level selects the correct option according to the
desired semantic variant. Our approach differs in that it
uses changes in queries and mappers to vary the semantics.
Thus, options not available by the selected variant are not
generated.
      </p>
      <p>
        This work was also partly motivated by the call expressed
in [
        <xref ref-type="bibr" rid="ref21">21</xref>
        ], for endowing the conventions behind complex
diagrams (biological ones, in the case of [
        <xref ref-type="bibr" rid="ref21">21</xref>
        ]) with explicit
formal semantics.
      </p>
    </sec>
    <sec id="sec-8">
      <title>X. CONCLUSION</title>
      <p>By querying the syntax of a diagrammatic language and
mapping the result to BP-based code, we can formally
define the operational semantics of said language. Resultant
definition has a is executable, accessible to practitioners
who shy from state change formulae but read code readily,
and allows the language developer to independently
experiment with different semantics of language constructs. We
have demonstrated the proposed approach using a subset
of the LSC language, and presented a working software tool
based on that definition.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>D.</given-names>
            <surname>Harel</surname>
          </string-name>
          , “
          <article-title>Statecharts: A visual formalism for complex systems</article-title>
          ,”
          <source>Science of Computer Programming</source>
          , vol.
          <volume>8</volume>
          , no.
          <issue>3</issue>
          , pp.
          <fpage>231</fpage>
          -
          <lpage>274</lpage>
          ,
          <year>1987</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>D.</given-names>
            <surname>Harel</surname>
          </string-name>
          and
          <string-name>
            <given-names>B.</given-names>
            <surname>Rumpe</surname>
          </string-name>
          , “Meaningful Modeling:
          <article-title>What's the Semantics of</article-title>
          “Semantics”?” IEEE Computer Magazine,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>A.</given-names>
            <surname>Marron</surname>
          </string-name>
          .
          <article-title>Behaviroal programming website</article-title>
          . [Online]. Available: http://www.b-prog.org
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>D.</given-names>
            <surname>Harel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Marron</surname>
          </string-name>
          , and G. Weiss, “Behavioral programming,
          <source>” Communications of the ACM</source>
          , vol.
          <volume>55</volume>
          , no.
          <issue>7</issue>
          ,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>OMG</given-names>
            ,
            <surname>Unified Modeling Language Superstructure Specification</surname>
          </string-name>
          ,
          <year>v2</year>
          .0,
          <string-name>
            <surname>Aug</surname>
          </string-name>
          .
          <year>2005</year>
          . [Online]. Available: http://www.omg.org
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>J.</given-names>
            <surname>Chan</surname>
          </string-name>
          and
          <string-name>
            <given-names>W.</given-names>
            <surname>Yang</surname>
          </string-name>
          , “Ambiguities in java,
          <source>” CTHPC</source>
          , vol.
          <volume>2</volume>
          , pp.
          <fpage>51</fpage>
          -
          <lpage>62</lpage>
          ,
          <year>2002</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>H.</given-names>
            <surname>Fecher</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Schönborn</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Kyas</surname>
          </string-name>
          , and W. de Roever, “
          <article-title>29 new unclarities in the semantics of uml 2.0 state machines</article-title>
          ,
          <source>” Formal Methods and Software Engineering</source>
          , pp.
          <fpage>52</fpage>
          -
          <lpage>65</lpage>
          ,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>C.</given-names>
            <surname>Klein</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Clements</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Dimoulas</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Eastlund</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Felleisen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Flat</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>McCarthy</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Rafkind</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Tobin-Hochstadt</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>R.</given-names>
            <surname>Findler</surname>
          </string-name>
          , “
          <article-title>Run your research, on the effectiveness of lightweight mechanization</article-title>
          .
          <source>” POPL</source>
          ,
          <year>January 2012</year>
          , pp.
          <fpage>285</fpage>
          -
          <lpage>296</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>D.</given-names>
            <surname>Harel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Lampert</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Marron</surname>
          </string-name>
          , and G. Weiss, “
          <string-name>
            <surname>Model-Checking Behavioral</surname>
            <given-names>Programs</given-names>
          </string-name>
          ,”
          <source>in Proc. 11th Int. Conf. on Embedded Software (EMSOFT)</source>
          ,
          <year>2011</year>
          , pp.
          <fpage>279</fpage>
          -
          <lpage>288</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>W.</given-names>
            <surname>Damm</surname>
          </string-name>
          and
          <string-name>
            <given-names>D.</given-names>
            <surname>Harel</surname>
          </string-name>
          , “LSCs: Breathing Life into Message Sequence Charts,”
          <source>J. on Formal Methods in System Design</source>
          , vol.
          <volume>19</volume>
          , no.
          <issue>1</issue>
          , pp.
          <fpage>45</fpage>
          -
          <lpage>80</lpage>
          ,
          <year>2001</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>D.</given-names>
            <surname>Harel</surname>
          </string-name>
          and
          <string-name>
            <given-names>R.</given-names>
            <surname>Marelly</surname>
          </string-name>
          , Come,
          <article-title>Let's Play: Scenario-Based Programming Using LSCs and the Play-Engine</article-title>
          . Springer,
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>D.</given-names>
            <surname>Harel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Maoz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Szekely</surname>
          </string-name>
          , and
          <string-name>
            <given-names>D.</given-names>
            <surname>Barkan</surname>
          </string-name>
          , “
          <article-title>PlayGo: towards a comprehensive tool for scenario based programming</article-title>
          ,” in ASE,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>A.</given-names>
            <surname>Marron</surname>
          </string-name>
          and
          <string-name>
            <given-names>S.</given-names>
            <surname>Szekely</surname>
          </string-name>
          ,
          <source>LSC Language Reference Manual. Department of Computer Science and Applied Mathematics Weizmann Institute of Science</source>
          , 04
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>J.</given-names>
            <surname>Robie</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Dyck</surname>
          </string-name>
          , and
          <string-name>
            <given-names>J.</given-names>
            <surname>Spiegel</surname>
          </string-name>
          , XQuery
          <volume>3</volume>
          .1:
          <string-name>
            <surname>An</surname>
            <given-names>XML</given-names>
          </string-name>
          <string-name>
            <surname>Query Language</surname>
          </string-name>
          , Std.,
          <year>2015</year>
          . [Online]. Available: http://www.w3.org/TR/xquery-31/
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>C.</given-names>
            <surname>Grun</surname>
          </string-name>
          , “Pushing XML Main Memory Databases to their Limits,”
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <given-names>M.</given-names>
            <surname>Bar-Sinai</surname>
          </string-name>
          and
          <string-name>
            <given-names>M.</given-names>
            <surname>Weinstock. BP-Javascript</surname>
          </string-name>
          <string-name>
            <surname>.</surname>
          </string-name>
          [Online]. Available: https://github.com/michbarsinai/BP-javascript-search
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <given-names>M.</given-names>
            <surname>Weinstock</surname>
          </string-name>
          , “
          <article-title>A behavioral programming approach to search based software engineering</article-title>
          ,”
          <source>in Proceedings of the ACM Student Research Competition at MODELS</source>
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          [18]
          <string-name>
            <surname>J. de Lara</surname>
            and
            <given-names>H.</given-names>
          </string-name>
          <string-name>
            <surname>Vangheluwe</surname>
          </string-name>
          , “
          <article-title>Atom3: A tool for multi-formalism and meta-modelling.” in FASE, ser</article-title>
          . Lecture Notes in Computer Science, R. Kutsche and H. Weber, Eds., vol.
          <volume>2306</volume>
          . Springer,
          <year>2002</year>
          , pp.
          <fpage>174</fpage>
          -
          <lpage>188</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          [19]
          <string-name>
            <surname>OMG</surname>
          </string-name>
          ,
          <article-title>Semantics Of A Foundational Subset For Executable UML Models (FUML™</article-title>
          )
          <year>v1</year>
          .
          <fpage>2</fpage>
          .1,
          <string-name>
            <surname>January</surname>
          </string-name>
          <year>2016</year>
          . [Online]. Available: http: //www.omg.org/spec/FUML/1.2.1/
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          [20]
          <string-name>
            <given-names>F.</given-names>
            <surname>Latombe</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Crégut</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Deantoni</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Pantel</surname>
          </string-name>
          , and
          <string-name>
            <given-names>B.</given-names>
            <surname>Combemale</surname>
          </string-name>
          , “
          <article-title>Coping with Semantic Variation Points in Domain-Specific Modeling Languages,”</article-title>
          <source>in 1st International Workshop on Executable Modeling (EXE'15)</source>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          [21] E. Fox Keller and D. Harel, “
          <article-title>Beyond the gene</article-title>
          ,”
          <source>PLoS ONE</source>
          , vol.
          <volume>2</volume>
          , no.
          <issue>11</issue>
          , pp.
          <fpage>1</fpage>
          -
          <issue>11</issue>
          ,
          <year>11 2007</year>
          . [Online]. Available: http: //dx.plos.
          <source>org/10.1371%2Fjournal.pone.0001231</source>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>