<!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>Extension of Domain-Specific Language and its Operational Semantics⋆</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>William Steingartner</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Davorka Radaković</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Boris Dovčík</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Technical University of Košice, Faculty of Electrical Engineering and Informatics</institution>
          ,
          <addr-line>Košice</addr-line>
          ,
          <country country="SK">Slovakia</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>University of Novi Sad, Faculty of Sciences, Department of Mathematics and Informatics, Division of Informatics</institution>
          ,
          <addr-line>21000 Novi Sad</addr-line>
          ,
          <country country="RS">Serbia</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>A strong foundation in formal methods for software engineering is important in educating novice programmers. Semantic modeling is the necessary foundation for formal methods. The increasing utilization of domain-specific languages (DSL) underscores their importance in practical applications. Therefore, incorporating them into the curriculum of the Semantics of Programming Languages represents a notable departure from the traditional way of teaching the semantics of (mostly) imperative languages. Previously, we developed a practical way to visualize natural semantics calculations for a selected domain-specific language for motion control of a robot in an orthogonal grid. The main goal of this article is to present a tool designed and developed by us, which is intended for interactive visualization of the chosen semantic method and its calculations. In this article, we extend the previous visualization with an extended version of the selected DSL to give a robot a more compact movement by angle (which is multiple of 90 degrees) in the desired direction. In this way, we teach students the basics of formal semantics and how to extend DSL, i.e. to extend syntax by new commands and maximize students' learning eficiency. The findings of this paper would be of interest to educators and students.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;formal semantics</kwd>
        <kwd>natural semantics</kwd>
        <kwd>visualization</kwd>
        <kwd>experiments</kwd>
        <kwd>NextUI</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        To novice computer science students it is significant to comprehend how the program is performed
and what steps are taken. Accordingly, they must grasp the specific steps through which a program is
executed by the machine. The principles based on formal methods guarantee the correctness of the
designed and developed systems [
        <xref ref-type="bibr" rid="ref1 ref2">1, 2</xref>
        ]. The operational semantics is used to describe these processes.
It contains two approaches – natural and structural operational semantics [
        <xref ref-type="bibr" rid="ref3 ref4">3, 4, 5</xref>
        ]. Teaching novice
students to formal methods in theoretical computer science is a challenging task. Due to the
COVID19 pandemic, and lack of face-to-face teaching interaction, another help to online lessons is diverse
visualizations of algorithms and scientific concepts. The use of software tools enabling interaction
and visualization of calculations [6, 7, 8, 9, 10] can be viewed as a contemporary teaching method that
enhances its appeal. Throughout the project, our motivation came from the results in the following
areas: visualization of algorithms and methods, operational semantics, domain-specific languages, and
logic. Since before the COVID-19 pandemic at the Faculty of Electrical Engineering and Informatics,
Technical University of Košice, we have developed several software tools [11, 12, 13] (for our teaching
subject) that help students grasp the subject’s material. Developed tools were intended for students
studying primarily the course Semantics of Programming Languages, in addition to related courses
focused on the formal semantics of languages, properties of programming languages, or introduction
to programming. This paper is an extension to the work in [14] where we presented a visualization
of the natural semantics of selected DSL and we follow some principles from [15]. In this paper, we
present a new teaching tool for visualizing natural semantics calculations for a selected domain-specific
language for motion control of a robot in an orthogonal grid with extensions of the angle of movement.
The main goal of this article is to present a tool designed and developed by us, which is intended for
interactive visualization of the chosen semantic method and its calculations. We formulated the natural
semantics of the DSL language for robot control based on research results, and we verified and proved
its equivalence with existing semantic methods within our research in [16]. In this work, we build on
previous results achieved in science and research, as well as in technological development.
      </p>
      <p>The structure of this paper is the following: the next section reviews related work. Further, we
present the syntax and semantics of the extended robot language (Section 3). Section 4 then presents
the application implementation and its graphical user interface. Lastly, Section 5 outlines the conclusion
on the presented topic.</p>
    </sec>
    <sec id="sec-2">
      <title>2. Related Works</title>
      <p>Numerous authors implement visual tools designed to aid students in mastering subjects. They employ
visualization software or create tools to augment students’ learning experiences, aiming to bridge
theoretical concepts with practical applications. This approach fosters a clearer comprehension of the
applied procedures and principles taught in the course.</p>
      <p>An example of a visualization tool for teaching compilers VCOCO (Visible COmpiler Compiler) is
[17]. It depends on COCO/R [18, 19] that is responsible for creating analyzers, and it creates visual
representations that can be manipulated by students.</p>
      <p>Another use of DSL for robots, Mernik demonstrated in [20]. It shows how diferent language
compositions can be realized using LISA and Robot DSL, another research area in Software Language
Engineering.</p>
      <p>The RISC Algorithm Language (RISCAL) is a language for the formal modeling of theories and
algorithms given in [14], and it supports full (first-order) predicate logic on top of a rich basis of types
(integers, tuples, records, arrays, sets, recursive types) with corresponding operations. This educational
tool includes the automatic generation of checkable verification conditions from algorithms, the
visualization of the execution of procedures and the evaluation of formulas illustrating the computation
of their results, and the generation of Web-based student exercises and assignments from RISCAL
specifications. Further, the usage and implementation of RISCAL, a model checker for mathematical
theories and algorithms based on a variant of First-order logic within models, is reported in [21]. They
reported enhancing education in computer science and mathematics, in particular in academic courses
on logic, formal methods, and formal modeling (see [22]).</p>
      <p>Tsimbolynets and Perháč present in [6, 11] a tool developed to visualize the translation process of a
program written in a simple imperative programming language by structural operational semantics,
also known as small-step operational semantics. It is OS-independent; therefore, it is implemented as a
web application like our visualization tool.</p>
      <p>The paper [12] introduces a language definition tool that utilizes a metamodel specification rather
than grammar as the basis of the language definition. Inspired by the Java tool YAJCo, it employs typical
object-oriented techniques, defining the metamodel as classes in Python. The parsing process results
in a graph of objects, exemplified through a case study involving a basic imperative programming
language.</p>
    </sec>
    <sec id="sec-3">
      <title>3. The Extended Robot Language</title>
      <p>The extended robot control language is a domain-specific language used for describing the movement
of a robot in a defined orthogonal two-dimensional system. We note that the first idea about this robot
language was presented in [23].</p>
      <sec id="sec-3-1">
        <title>3.1. Syntax of the Extended Robot Language</title>
        <p>The language of the robot is very simple. It contains commands for controlling the robot’s rotation, and
movement, returning to the initial state, skip command, and a pattern for the sequencing of commands.
Therefore, the simplest way of defining syntax is using the Backus-Naur Form, for which two syntactic
domains (categories) were defined:
 ∈ Num
 ∈ Statm
— numerals,
— statements.</p>
        <p>The language of the robot uses concepts used in LOGO or Karel the Robot which makes this language
closer to real languages. Then the syntax is as follows:</p>
        <p>::= turn left | turn right | forward | forward  | reset | skip | ; .</p>
        <p>The statements turn left and turn right express a change in an angle of movement by 90 degrees
to left or right, respectively. The statements forward and forward  express the movement of the
robot in a direction that is defined by the angle. Argument  specifies the number of steps of the
movement. The statement reset represents an instantaneous return to the initial position specified by
the user at the beginning. The skip statement is an empty statement, and its role is mostly in proof of
semantic equivalence. This syntax is now extended by new commands:</p>
        <p>::= . . . turn left  | turn right .</p>
        <p>These statements change the angle of movement by  · 90 degrees in the desired direction.</p>
      </sec>
      <sec id="sec-3-2">
        <title>3.2. Semantics of the Extended Robot Language</title>
        <p>As semantic domains, we consider here standard numerical sets for naturals with zero (N0) and integers
(Z) as given in [14, 24].</p>
        <p>Here, the configuration in natural semantics shall be extended. Configuration must express the
current position with the direction. Direction is given by an angle of movement in the orthogonal
system. We consider the following directions (given as angles in degrees):
• 0 represents the up,
• 90 represents the right,
• 180 represents the down,
• 270 represents the left movement direction.</p>
        <p>In this model, the robot can turn only by multiples of 90 degrees, and the values of angles we consider
as elements of the set Angle = Z. A configuration is an element of the semantic domain defined as
follows:</p>
        <p>Config= Point ×</p>
        <p>Angle.</p>
        <p>Then elements of this semantic domain are tuples consisting of a point and actual angle: (,  ). The
semantic function is then defined as follows</p>
        <p>S ′ : Statm → (Config⇀ Config)
and the function for every statement is given by</p>
        <p>S ′J  K(,  ) =
︂{ (′,  ′), if ⟨, (,  )⟩ → (′,  ′),</p>
        <p>⊥, otherwise.</p>
        <p>
          Here, the tuple ⟨, (,  )⟩ is a new configuration in natural semantics for the extended language,
and ⟨, (,  )⟩ → (′,  ′) is a new transition relation. The semantic rules for statements were defined
in [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ] and [5], for the new statements we define new rules as the following:
⟨turn left, (,  )⟩ → (,  ′′) ⟨turn left , (,  ′′)⟩ → (,  ′)
⟨turn left , (,  )⟩ → (,  ′)
(turn-l-nns)
⟨turn right, (,  )⟩ → (,  ′′) ⟨turn right , (,  ′′)⟩ → (,  ′)
⟨turn right , (,  )⟩ → (,  ′)
(turn-r-nns)
For both given rules, we formulate the following:
•  ′′ = ( ⊕ 90) mod 360,
•  ′ = ( ′′ ⊕ 90 ⊗ N J  K) mod 360, which corresponds to
 ′ = ( ⊕ 90 ⊗
        </p>
        <p>) mod 360,</p>
        <p>N J K
for N J K</p>
        <p>= N J  K ⊕ 1, where N J  K, N J  K ∈ N0.</p>
        <p>In the case of both commands, we can observe the following equivalences:
if  ∈ {0, 90, 180, 270}, then ⟨turn left , (,  )⟩ ≡ ⟨ skip, (,  )⟩,
if  ∈ {0, 90, 180, 270}, then ⟨turn right , (,  )⟩ ≡ ⟨ skip, (,  )⟩,
where N J K</p>
        <p>mod 4 = 0. We note that N J · K is a semantic function that sends numerals to naturals
(or zero):</p>
        <p>N : Num → N0.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. Implementation</title>
      <p>The application Operics for visualizing the operational semantics of robot language is available online
at [25]. Next.js framework and the NextUI library were used to design our GUI. The application Operics
utilizes the microservices architecture. Visualization logic is split between the frontend, which provides
an interface for a user to interact with the application, and the backend, which logic is separated into
two modules, one for grammar processing and the other for subsequent interpretation of input and
output generation.</p>
      <p>The UI component (Figure 1) provides two ways of inputting code: through the text area and file
upload. The robot grid (Figure 2) is the interpreter of possible states on the interface. At first, it is
initialized with the creation of the whole grid and the robot on it.</p>
      <sec id="sec-4-1">
        <title>4.1. The Interpretation Module</title>
        <p>The interpretation module simplified controller architecture is shown in Figure 3. The TreeBuilderService
creates a derivation tree of the natural semantics in the form of an object Tree. Method
applyNaturalSemantics is extended for the rule processing of extended robot control language. Methods of
the GeneratorService which is run after TreeBuilderService use a constructed Tree object and generate
the desired output format. The extended state of the robot inherits from the basic state of the robot
and extends it by the rotation angle. Subsequently, state transitions, natural semantics in the form of
LATEXcode, or graphic visualization in the form of a PDF file are generated based on the language version
used. The endpoints were extended by adding/alternative postfix to the existing paths creating two
new endpoints for extended robot control language.</p>
        <p>As an important and (no less) interesting element of controlling the robot, we mention that the user
can step the robot’s movement himself, or start automatic stepping (run-at-once) from any point, i.e.
from the beginning of the program, and during stepping let the robot catch up to end of the program.
After performing the program, user receives a visible output consisting of more information. First of all,
the grid with the full path of robot is visualized (this is what the grid component provides, see Figure 2.
Formally, the robot is in individual states during its run (its activity) until it reaches the end (result)
state. The list of all reached states is provided as another result (Figure 4).</p>
        <p>Last but not least, a tree of natural semantics is also provided as a result, in which individual
transitional sessions (big steps) are expressed, with the help of which the robot gets from the initial
state to the final state. An example of such tree is in Figure 5.</p>
        <p>We note that the individual results from the Operics program as presented in Figures 2, 4 and 5
express the solution or the result of the interpretation of the program expressed in Figure 1.</p>
      </sec>
      <sec id="sec-4-2">
        <title>4.2. The module for the graphical web interface</title>
        <p>The robot movement is visualized on the robot grid using the react-konva library. The initial state of
the robot and the current state of the robot are shown under the grid. Depending on the language
version used they are shown either as configuration of points  and :</p>
        <p>⟨, ⟩
or for an extended version with an angle of rotation</p>
        <p>⟨, ,  ⟩.</p>
        <p>The rotation of the robot is shown as an arrow that points to the direction described by the angle of
the movement. Calling reset command and moving the robot through the same paths multiple times
can be confusing. For that reason when reset command is used the the color of the path is changed
enabling thus easier recognition of current and past paths.</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>5. Conclusion</title>
      <p>In this paper, we focused on the formulation and definition of semantic methods for describing the
meaning of programs in a simple domain-specific language for controlling a robot in an orthogonal
system with extensions of the angle of movements. We presented a software tool for formulating
semantic methods, serving as an educational aid to enhance its appeal. As mentioned in [14] regarding
the previous version of this tool, our application also presents opportunities for further development.
We also would like to take advantage of the flexibility of this DSL to extend it with loops, to define
conditionals, and to introduce some kind of state machine so our DSL for controlling the robot could
become closer to real languages.</p>
    </sec>
    <sec id="sec-6">
      <title>Acknowledgments</title>
      <p>This work was supported by national KEGA project 030TUKE-4/2023 – “Application of new principles
in the education of IT specialists in the field of formal languages and compilers”, granted by the Cultural
and Education Grant Agency of the Slovak Ministry of Education. An international cooperation
was supported by CEEPUS Network CZ-1503-04-2324 (Umbrella) – “Development of Computational
Thinking”.
[5] W. Steingartner, V. Novitzká, Metódy formálnej sémantiky programovacích jazykov [Methods of</p>
      <p>Formal Semantics of Programming Languages], Technical University of Košice, 2022. (in Slovak).
[6] V. Tsimbolynets, J. Perháč, Visualization Tool for Structural Operational Semantics of Simple</p>
      <p>Imperative Languages, IPSI Transactions on Internet Research 19 (2023) 66–74.
[7] S. Szymoniak, Time Influence on Security Protocol, in: H. K. Raian Ali, L. Maciaszek (Eds.),
Proceedings of the 16th International Conference on Evaluation of Novel Approaches to Software
Engineering (ENASE), ScoTePress, 2021, pp. 181–188.
[8] W. Schreiner, F.-X. Reichl, Mathematical Model Checking Based on Semantics and SMT, IPSI</p>
      <p>Transactions on Internet Research 16 (2020) 4–13.
[9] G. Savić, M. Segedinac, M. Čeliković, I. Luković, A Meta-model for Key Performance Indicators in</p>
      <p>Higher Education, IPSI Bgd Transactions on Internet Research 19 (2023) 76–91.
[10] W. Schreiner, W. Steingartner, Visualizing Logic Formula Evaluation in RISCAL, Technical Report,
Research Institute for Symbolic Computation (RISC), Johannes Kepler University, Linz, Austria,
2018.
[11] V. Tsimbolynets, J. Perháč, Visualization of imperative programs translation with structural
operational semantics, in: 2022 IEEE 16th International Scientific Conference on Informatics
(Informatics), 2022, pp. 328–333. doi:10.1109/Informatics57926.2022.10083474.
[12] S. Chodarev, S. Ilyas, Metamodel-based language definition with python, IPSI Transactions on</p>
      <p>Internet Research 19 (2023) 32–38.
[13] D. Mihályi, M. Peniašková, J. Perháč, J. Mihelič, Web-based Questionnaires for Type Theory</p>
      <p>Course, Acta Electrotechnica et Informatica 17 (2017) 35–42.
[14] W. Steingartner, D. Radaković, R. Zsiga, Some Aspects about Visualization of Natural Semantics
for a Selected Domain-Specific Language, IPSI Transactions on Internet Research 19 (2023) 46–54.
[15] J. Dostal, X. Wang, W. Steingartner, P. Nuangchalerm, Digital Intelligence – New Concept in
Context of Future of School Education, in: L. Chova, A. Martinez, I. Torres (Eds.), 10th International
Conference of Education, Research and Innovation (ICERI2017), ICERI Proceedings, 2017, pp. 3706–
3712. 10th Annual International Conference of Education, Research and Innovation (ICERI), Seville,
SPAIN, NOV 16-18, 2017.
[16] W. Steingartner, V. Novitzká, W. Schreiner, Proof of equivalence of semantic methods for a selected
domain-specific language, Journal of Applied Mathematics and Computational Mechanics 23
(2024) 79–92. URL: https://doi.org/10.17512/jamcm.2024.2.07. doi:10.17512/jamcm.2024.2.07.
[17] R. D. Resler, M. D. Deaver, VCOCO: A visualisation tool for teaching compilers, in: Annual
Conference on Innovation and Technology in Computer Science Education, ser. ITiCSE ’98, 1998,
pp. 199–202.
[18] H. Mössenböck, The Compiler Generator Coco/R User Manual, Johannes Kepler University Linz,</p>
      <p>Institute of System Software, 1990.
[19] H. Mössenböck, A generator for production quality compilers, in: D. Hammer (Ed.), Compiler</p>
      <p>Compilers, Springer, Berlin, Heidelberg, 1991, pp. 42–55.
[20] M. Mernik, An object-oriented approach to language compositions for software language
engineering, Journal of Systems and Software 86 (2013) 2451–2464.
[21] W. Schreiner, Theorem and algorithm checking for courses on logic and formal methods, in:
W. N. Pedro Quaresma (Ed.), Theorem Proving Components for Educational Software (ThEdu’18),
volume 290 of EPTCS, Open Publishing Association, 2019, pp. 56–75.
[22] W. Schreiner, Logic and semantic technologies for computer science education, in: 2019 IEEE 15th</p>
      <p>International Scientific Conference on Informatics, IEEE, 2019, pp. 415–420.
[23] M. Pereira, M. Mernik, D. Cruz, P. Rangel Henriques, Program comprehension for domain-specific
languages, Comput. Sci. Inf. Syst. 5 (2008) 1–17. doi:10.2298/CSIS0802001P.
[24] W. Steingartner, V. Novitzká, Operational semantics in a domain-specific robot control language:</p>
      <p>A pedagogical use case, Computer Science and Information Systems 21 (2024) 1077–1095.
[25] Operics, Operics: Online tool for natural semantics, n.d. URL: https://
operics-frontend-g7mvk5367q-od.a.run.app/en/natural, accessed: 2024-07-14.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>S.</given-names>
            <surname>Szymoniak</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Kesar</surname>
          </string-name>
          ,
          <article-title>How can best practices of cybersecurity include artificial intelligence within smart cities, in: The Leading Role of Smart Ethics in the Digital World</article-title>
          , Universidad de La Rioja,
          <year>2024</year>
          , pp.
          <fpage>135</fpage>
          -
          <lpage>142</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>L.</given-names>
            <surname>Jancik</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Kvet</surname>
          </string-name>
          ,
          <article-title>Analytical tool for oracle sql statements</article-title>
          ,
          <source>in: 2024 35th Conference of Open Innovations Association (FRUCT)</source>
          , Tampere, Finland,
          <year>2024</year>
          , pp.
          <fpage>275</fpage>
          -
          <lpage>283</lpage>
          . doi:
          <volume>10</volume>
          .23919/FRUCT61870.
          <year>2024</year>
          .
          <volume>10516421</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>F.</given-names>
            <surname>Nielson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Nielson</surname>
          </string-name>
          ,
          <article-title>Semantics with Applications</article-title>
          .
          <source>An Appetizer</source>
          , Springer-Verlag London Limited,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>W.</given-names>
            <surname>Steingartner</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Novitzká</surname>
          </string-name>
          ,
          <article-title>Natural semantics for domain-specific language</article-title>
          , in: L.
          <string-name>
            <surname>Bellatreche</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Dumas</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          <string-name>
            <surname>Karras</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          <string-name>
            <surname>Matulevičius</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          <string-name>
            <surname>Awad</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Weidlich</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Ivanović</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          Hartig (Eds.),
          <source>New Trends in Database and Information Systems</source>
          , Springer International Publishing, Cham,
          <year>2021</year>
          , pp.
          <fpage>181</fpage>
          -
          <lpage>192</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>