Home

Features

Case Studies

Video Demos

Publications

People

Contact

 

Case Study I: Imperative Domain-Specific Language:

An imperative programming language is centered around assignment expressions or control flow statements, which allow one to change the contents of cells in the memory store. The Robot DSL is an imperative language that consists of five moves to control robot movement: up, down, right, left, and knight. Every move will increase or decrease the position of the robot along the x or y coordinates. As a side effect, each move will also increase an internal timer by one unit. Additional Robot DSL statements are: initial statement, set statement, and print statement. The figure below is part of sample code written in the Robot DSL - lines 11 to 13 represent the definition of "up move"; line 21 initializes the robot's beginning position to (0, 0); line 25 forces (5, 6) as the robot's new current position; line 28 prints the robot's current position.

...

11     Down: 

12      position(+0,-1) 

13     Down:  F_end

14     Knight:

15      position(+0,+1)

16      position(+0,+1)

17      position(+0,+1)

18      position(+1,+0)

19     Knight: F_end

20   M_end

21   Init position(0,0)

22   Call left

23   Call down

24   Call knight

25   Set position(5,6)

26   Call up

27   Call right

28   Print position

...

  • Imperative DSL Debugger for Robot Language

  • Imperative DSL Unit Test Engine for Robot Language

All four test cases passed

 

Test cases testleft and testup failed

 

Case Study II: Declarative Domain-Specific Language

 

The Feature Description Language (FDL) is a textual DSL to describe feature diagrams that are used in software product lines. In our case study, we use a car's features as a target example of FDL. A car consists of a Carbody, Transmission, Engine and HorsePower. pullsTrailer is an optional feature. Carbody and pullsTrailer are atomic features. There are 36 possible car instances from the sample car specification shown below.

  • Sample Car FDL Code

1  Car : all (carbody, Transmission, Engine, Horsepower, opt(pullsTrailer))
Transmission : one-of (automatic, manual)
3  Engine : more-of (electric, gasoline)
Horsepower : one-of (lowPower, mediumPower, highPower)
5  include pullsTrailer
6  pullsTrailer requires highPower

 

  • Declarative DSL Debugger for a Car Specified in FDL

 

 

Case Study III: Hybrid Domain-Specific Language: Extension of Robot DSL

 

Some DSLs include embedded GPL code within the DSL description. The figure below is an example of a hybrid Robot program, which is an extension of the Robot DSL described in Case Study 1. In order to bring the I/O operation, user-interface, and random number generator functionalities to the basic Robot DSL, we extend the Robot DSL by adding inlined Java code within the Robot DSL. The figure below introduces another move for the robot called "Random," which allows the robot controller to specify the ranges of a random number generator for the x and y coordinates of the robot. The Robot imperative DSL is a hybrid DSL that is a mixture of Robot DSL and Java language constructs. Without spending much of the effort and time to implement the Robot DSL by adding a formalized "Random" construct, the hybrid Robot DSL represents a quick solution to extend the basic language. In this figure, lines 13 to 27 represent the definition of the Random move method, and lines 14 to 26 specify the semantics of "Random" written in Java (denoted as {...}). Line 35 is the code in the main program where "Random" is called.

 

...

13   Random:

14    {

15     String answer;

16     int max;

17     JOptionPane myGUI = new JOptionPane();

18     Random rand = new Random();

19     answer = myGUI.showInputDialog("Generate a random number for X-axis ...");

20     max = Integer.parseInt(answer);

21     x = rand.nextInt(max);

22     answer = myGUI.showInputDialog("Generate a random number for Y-axis ...");

23     max = Integer.parseInt(answer);

24     y = rand.nextInt(max);

25     myGUI.showMessageDialog(null, "Generated Position(" + x + "," + y+ ")");

26    }

27   Random: F_end

28   M_end

29   Init position(0,0)

30   Call left

31   Call down

32   Call knight

33   Set position(5,6)

34   Call up

35   Call random

...

 

 

  • Hybrid DSL Debugger for Robot Hybrid DSL

 

Case Study IV: Hybrid Domain-Specific Language: SWUL

 

Some DSLs include the embedded DSL description within the GPL code. SWUL was created by the Stratego group (Strategies for Program Transformation) to "give programmers the power of Java with an easy and straightforward way to create user interfaces" [1]. The figure below is an example of a SWUL program, which is a DSL application for creating Java SWING interfaces. The SWUL language code is embedded in Java. "In this fashion it provides a concrete syntax for creating SWING objects" [1]. A SWUL application becomes the hybrid DSL code that is a mixture of SWUL specification and Java language constructs. Our DSL Debugger Framework is able to bridge the mismatch between Java and SWUL and generate a debugger for SWUL without spending much of the effort and time adjusting the SWUL grammar. In the figure below, lines 6 to 18 represent the SWUL code and the rest of the code is written in Java.

  • Sample SWUL Code: WelcomeSwing.javaswul (This example is also taken from [1])

1    import javax.swing.*;

2    import java.awt.*;

3 

4    public class WelcomeSwing {

5    public static void main(String[] ps) {

6    JFrame frame = frame {

7      title = "Welcome!"

8      content = panel of border layout {

9          center = label { text = "Hello World" }

10        south = panel of grid layout {

11           row = { button {

12                     text = "cancel" }

13                  button {

14                     text = "ok" }

15          }

16        }

17      }

18    };

19      frame.pack();

20      frame.setVisible(true);

21    }

22  }

  • Hybrid DSL Debugger for SWUL

[1]   Java-Swul available at http://www.program-transformation.org/Stratego/Java-Swul

Copyright © 2006 Hui Wu. All rights reserved.