Grammar-Driven Generation of Domain
Download
Report
Transcript Grammar-Driven Generation of Domain
Grammar-Driven Generation of
Domain-Specific Language Testing Tools
Hui Wu
http://www.cis.uab.edu/wuh
February 08 2006
1
Motivation of Proposed Research
Editor
Domain Experts program
at DSL level
Compiler
Visualizer
subselect me
subselect me
begin
left
right
up
down
end
Translater
public class Robot{
public static void
main(String[] args) {
Robot robot =new Robot(0,0,0);
//move left
robot.move_left();
//move down
robot.move_down();robot.x = 5;
robot.y = 6;
DSL translated into General
Purpose Language (GPL)
Debugge
r
Domain Experts
deal with GPL
Profiler
Test Engine
Integrated Development
Environment (IDE)
Domain Experts
deal with DSL
2
A Horizontal Direction:
Debuggers for Different Types of DSLs
Imperative DSL: Centered around assignment
expressions or control flow statements
Robot Language
…
17
18
19
20
21
22
23
24
25
26
27
28
…
Down:
position(+0,-1)
Down: F_end
M_end
Init position(0,0)
Call left
Call down
Call knight
Set position(5,6)
Call up
Call right
Print position
3
A Horizontal Direction:
Debuggers for Different Types of DSLs
Declarative DSL: declares the relationship
between inputs and outputs.
1
2
3
4
5
6
Feature Definition Language (FDL)
Car : all (carbody, Transmission, Engine, Horsepower, opt(pullsTrailer))
Transmission : oneof (automatic, manual)
Engine : moreof (electric, gasoline)
Horsepower : oneof (lowPower, mediumPower, highPower)
include pullsTrailer
pullsTrailer requires highPower
4
A Horizontal Direction:
Hybrid DSL: embedded GPL code within the
DSL description
…
Random:
{
String answer;
int max;
JOptionPane myGUI = new JOptionPane();
Random rand = new Random();
answer = myGUI.showInputDialog("Generate a random number for X-axis between 1 and ");
max = Integer.parseInt(answer);
x = rand.nextInt(max);
answer = myGUI.showInputDialog("Generate a random number for Y-axis between 1 and ");
max = Integer.parseInt(answer);
y = rand.nextInt(max);
myGUI.showMessageDialog(null, "Generated Position(" + x + "," + y+ ")");
}
Random: F_end
M_end
Init position(0,0)
Call left
Call down
Call knight
Set position(5,6)
Call up
Call random
Call right
Print position
…
5
Mismatch Between Abstraction Levels
ANTLR Grammar
….
commands
: ( c:command cs:commands
|
)
;
command
: ( RIGHT
{
fileio.print("//move right");
fileio.print("x=x+1;");
fileio.print("time=time+1;");
fileio.print(" ");
}
|LEFT
{
fileio.print("//move left");
fileio.print("x=x-1;");
fileio.print("time=time+1;");
fileio.print(" ");
…
Generated Java Parser Code
….
public final void commands() throws RecognitionException, TokenStreamException {
try {
// for error handling
{
switch ( LA(1)) {
case CALL:
case INIT:
case SET:
case PRINT:
{
command();
commands();
break;
}
case END:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
…
public final void function_name() throws RecognitionException,
TokenStreamException {
try {
// for error handling
{
switch ( LA(1)) {
case RIGHT:
{
match(RIGHT);
fileio.print("
//move right");
fileio.print("
move_right();");
fileio.print(" ");
break;
}
case LEFT:
{
match(LEFT);
sllinenumber=dsllinenumber+1;
fileio.print("
//move left");
fileio.print("
move_left();");
fileio.print(" ");
break;
}
6
…
Difficulties with Building DSL Testing Tools
Debuggers and Profilers are difficult to build
because they depend heavily on the
underlying operating system’s capabilities and
lower-level native code functionality
Manual construction of the test tools for each
new DSL can be time-consuming, expensive,
and error-prone
7
Three Aspects of the Research
Programming Language Tool Generation
Environment
Aspect-Oriented Language for Grammar
DSL Debugger
8
Related Work
Programming Language Tool Generation
Environment
ASF+SDF:
Jakarta Tool Suite:
Complicated mechanism (e.g., Language extension)
Dose not provide rich transformation ability
LISA:
Does not generate test engines and profilers
Debugger, test engine, and profiler are not the target language
tools, LISA can be used as the front-end of our framework.
SmartTools:
Base on Java and XML technologies
Debugger, test engine, and profiler are not target language
tools
9
Research Directions
Imperative
DSLs
Debuggers
Unit Test
Engines
Profilers
Declarative
DSLs
Hybrid
DSLs
construction of the same
software tool (e.g., debugging)
to different categories of DSLs
vertical direction corresponds to
the vector representing the
various testing tools that will be
applied to DSLs
10
Research Goal
A Matrix of DSL Testing Tools
Imperative DSL
Debugger
Imperative DSL
Unit Test Engine
Imperative DSL
Profiler
Declarative DSL
Debugger
Declarative DSL
Unit Test Engine
Declarative DSL
Profiler
Hybrid DSL
Debugger
generalized approach
to produce a software
product line of testing
tools for DSLs
Hybrid DSL
Unit Test Engine
Hybrid DSL
Profiler
Future Work
By Product
Weaving Aspects into
DSL Grammars
11
Background
Eclipse Debugger
Platform
Eclipse Unit Test
Platform
Design Maintenance
System (DMS)
12
Processes of DSL Debugger Generation
DSL
DSL
is grammar
the input of
isthe
defined
Lexerusing
and
ANTLR
Parser generated
Notation
by
ANTLR
Robot DSL
1
2
3
4
5
6
begin
left
down
up
right
end
Robot DSL
corresponding
GPL code
generated in
Java
DSL
translation
process
Robot.java and Mapping.java
//move down
y=y-1;
time=time+1;
……
}
2
1
Additional
Mapping code
generated in
Java
public class Robot
{
public static void main(String[] args) {
……
//move left
x=x-1;
time=time+1;
3
Corresponding GPL
Lexer,
and Parser
Mapping Code
are inputs of Mapping
Eclipse Debugging
Generatedcomponent
Lexer, and Parser
by ANTLR
perspective
jdb
communicates with
communicates
mapping component
with mapping
component
4
Variables
}
import java.util.ArrayList;
Robot DSL Grammar In ANTLR Notation
Debugger
View
public class Mapping {
ArrayList mapping;
public Mapping(){
mapping=new ArrayList();
mapping.add(new Map(1, "Robot.java",2,8));
mapping.add(new Map(2, "Robot.java",10,14));
……
}
}
View
6
5
Mapping
Component
DSL
Editor
Java Command Line Debugger
Robot DSL Debugging Perspective in Eclipse
13
Debugging: A Crosscutting Grammar Concern
Base Grammar
…
command
:( RIGHT
{
fileio.print("
fileio.print("
//move right");
x=x+1;");
What
if thishere
line changes?
Change
Duplicate Debugging Aspect Code
fileio.print("
time=time+1;");
dsllinenumber=dsllinenumber+1;
gplbeginline=fileio.getLinenumber();
gplendline=fileio.getLinenumber();
fileio.print(" ");
}
|LEFT
{
filemap.print(" mapping.add(new Map("+dsllinenumber+",
\"Robot.java\","+gplbeginline+","+gplendline+"));");
fileio.print("
fileio.print("
//move left");
x=x-1;");
Change here
fileio.print("
fileio.print(" ");
}
|
…
time=time+1;");
Change ……
14
Related Work
Aspect Oriented Language for Grammars
AspectAsf:
weave all possible debugging aspects into all potential
program locations
AspectLISA:
aspect-oriented compiler generator based on attribute
grammars
incrementally extend a language design
advices before and after join point are not applicable
purpose of AspectLISA is not tool generation
15
AspectG Pointcut Model
16
Weaving into DSL Grammars Using AspectG
Debugging Aspect
Specification
(AspectG)
DSL
Grammar
PARLANSE Functions
DMS
DSL Grammar’
with Debugging
Aspect Weaved in
Antlr
GPL
In Java
DSL
Code
Lexer’ and Parser’
In Java
Debugging
Mapping Code
In Java
17
Related Work
DSL Debugger
Khepera:
JSR-045:
provides end-users debugging support on ANTLR grammar
Based on JSR-045
ToolBus Integrated Debugging Environment (TIDE)
Java Specification Requests for Debugging Support for Other
Languages
Java language domain with similar source code mapping mechanism
AntlrStudio:
Support optimization code debugger
Store transformation information in a database
Based on ASF+SDF
4 tedious steps to implement debugger for a new language
UFO
A framework for rapidly constructing dynamic analyzers
Target Unicon language (SNOBOL-style) high level, goal-directed,
object-oriented, GPL.
18
UFO Demo
19
Approaches Used in This Proposed Research
Syntax-Directed
Translation
Eclipse
Plug-In Based
Software
Development
ANTLR
Design Patterns
Automated
Software
Engineering
Software
Model-View-Controller
Adapter Pattern
Weaving Aspects
into
DSL Grammars
6 after(int commandname):
7
call(void antlr.Parser.match(int))
8 && args(commandname)
9
{ match(commandname); }
10 pointcut count_dsllinenumber():
11
call (void P.command());
12 after(): count_dsllinenumber(){
13
{ dsllinenumber=dsllinenumber+1;}
AspectG
20
DSL Debugger Perspective in Eclipse
21
Declarative DSL Debugger
22
Hybrid DSL Debugger
23
Hybrid DSL Debugger Demo
24
DSL Unit Test Framework (DUTF)
Similar to the DSL Debugging Framework
architecture and approaches
Complement to the DSL Debugging
Framework, identify the existence of program
errors
To monitor the performance of DSLs at run
time, similar architecture and approaches can
be applied to DSL Profiler Framework (DPF)
to generate DSL profilers
25
DSL Unit Test Perspective in Eclipse
26
DSL Unit Test Perspective in Eclipse
27
Experimental Validation of This Work
Various types of DSLs serve as test cases
Robot Language (imperative DSL)
FDL (declarative DSL)
Robot Language with extension (hybrid
DSL)
Qualitative Metrics-How well the generated
testing tools behave
To what degree of success can the DSL
unit test engine detect errors in DSL
program units?
To what degree can the DSL debugger help
end-users to locate and fix the detected
errors?
28
Summary
End-user developers (e.g., scientist, accountant, and
statistician) are in large number
Software failures caused by program errors pose a
great threat to economy
Testing and Debugging on GPLs have been
investigated for decades, but testing and debugging
DSLs has been neglected.
Several publication reviews, paper citations, and
source code requests indicate the proposed research
is in the right direction.
29
Summary
Preliminary feasibility study:
Debuggers for imperative, declarative, and hybrid
DSLs
Unit Test Engine for imperative DSLs
Published initial experiences [WGR+05]
An initial investigation into weaving aspects into
DSL grammars and working on implementation of
AspectG.
30
Thank you for coming!
Questions?
Summary of URLs referenced in talk
DSL Debugger Framework
ANTLR
http://www.antlr.org
AspectJ
http://www.cis.uab.edu/wuh/DDF
http://www.aspectj.org
DMS
http://www.semdesigns.com
31