Weaving a Debugging Aspect into Domain-Specific Language Grammars SAC ’05 PSC Track Santa Fe, New...
-
Upload
willa-ellis -
Category
Documents
-
view
217 -
download
1
Transcript of Weaving a Debugging Aspect into Domain-Specific Language Grammars SAC ’05 PSC Track Santa Fe, New...
Weaving a Debugging Aspect into Domain-Specific Language Grammars
SAC ’05 PSC TrackSanta Fe, New Mexico USA
March 17, 2005
Hui Wu, Jeff Gray, Marjan Mernik, and Suman Roychoudhury
http://www.cis.uab.edu/wuh/DDF
This Research is Supported by
Eclipse Innovation Grant by IBM
Challenges with DSL Debugging
Domain Experts program at DSL level
DSL translated into General Purpose Language (GPL)
Domain Experts deal with DSL
Integrated Development Environment
subsel ect mebegin l eft ri ght up downend
Transl ater
subsel ect mepubl i c cl ass Robot{ publ i c stati c voidmain(Stri ng[] args) { Robot robot =new Robot(0,0,0); / /move l eft robot.move_l eft(); / /move down robot.move_down();robot.x = 5; robot.y = 6;
EditorEditor
CompilerCompiler
Visualizer
Visualizer
Debugger
Debugger
Domain Experts deal with GPL
Difficulties with Constructing a DSL Debugger Difficulties with Constructing a DSL Debugger
A debugger is difficult to build because it depends heavily on the underlying operating system’s capabilities and lower-level native code functionality
Manual construction of the debugger for each new DSL can be time-consuming, expensive, and error-prone
Motivation of building a DSL Debugger Domain experts lack knowledge about the underlying GPL Although techniques for constructing a debugger for a GPL
have been developed over the years, debug support for DSLs has not been investigated deeply
The underlying GPL can be messy and human unreadable One line of DSL can be translated into tens of lines of GPL
code
Architecture of DSL Debugging Framework
12
6
1 begin2 left3 down4 up5 right6 end
4
Lexer,Parser
public class Robot{ public static void main(String[] args) { …… //move left x=x-1; time=time+1;
//move down y=y-1; time=time+1; …… } }
3
import java.util.ArrayList;
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)); …… } }
Mapping Component
5
Robot DSL Grammar In ANTLR Notation
Robot DSL
Generated Lexer, and Parser by ANTLR
Robot.java and Mapping.java
Java Command Line Debugger
Robot DSL Debugging Perspective in Eclipse
DebuggerView
DSLEditor
Variables View
DSL grammar is defined using
ANTLR Notation
DSL is the input of the Lexer and
Parser generated by ANTLR
DSL translation
process
Robot DSL corresponding
GPL code generated in
JavaAdditional
Mapping code generated in
Java
Corresponding GPL and Mapping Code
are inputs of Mapping component
jdb communicates with mapping component
Eclipse Debugging perspective
communicates with mapping component
Mapping Technique to Generate Debugger
Source Code Mapping
Source Code Mapping
The source code mapping process uses the generated mapping information to determine which line of the DSL code is mapped to the corresponding segment of GPL code. It indicates the location of the GPL code segment.
The source code mapping process uses the generated mapping information to determine which line of the DSL code is mapped to the corresponding segment of GPL code. It indicates the location of the GPL code segment.
DSL Debugger Framework (DDF)
Debug Methods Mapping
The debug methods mapping process takes the user’s debugging commands from the debugger perspective at the DSL level to determine what type of debugging commands need to be issued to a command line debugger at the GPL level.
Debugging: A Crosscutting Grammar Concern
dsllinenumber=dsllinenumber+1;
gplbeginline=fileio.getLinenumber();gplendline=fileio.getLinenumber();
filemap.print(" mapping.add(new Map("+dsllinenumber+",\"Robot.java\","+gplbeginline+","+gplendline+"));");
…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(" ");
}|…
dsllinenumber=dsllinenumber+1;
gplbeginline=fileio.getLinenumber();gplendline=fileio.getLinenumber();
filemap.print(" mapping.add(new Map("+dsllinenumber+",\"Robot.java\","+gplbeginline+","+gplendline+"));");
Base Grammar
Duplicate Debugging Aspect Code
What if this line changes?Change here
Change here
Change ……
First Approach: Weaving at GPL Level
DSL Grammar
ANTLRParser
Lexer
In Java
Debugging Aspect Specification
In AspectJ
AspectJCompiler
Parser’
Lexer’
With Debugging Aspects Weaved in
DSL Code
DebuggingMapping
Code
GPL
In Java
First Approach: Weaving at GPL Level
…
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;}
…
…try { // for error handling {
switch ( LA(1)) {case RIGHT:case LEFT:case UP:case DOWN:case INIT:case SET:case PRINT:{
command();commands();break;
}case END:{
System.out.println(" ");break;
}default:{throw new NoViableAltException(LT(1), getFilename());
…
Generated Parser code by ANTLR
Debugging Aspect in AspectJ
First Approach: Weaving at GPL LevelDisadvantages: The lack of mature aspect weavers for many languages
(e.g., Object Pascal, C, or Ada)
Requires the developer of the DSL to have detailed knowledge of the code generator within ANTLR in order to construct the appropriate pointcuts.
In some case, the generated code is unreadable by a human
Second Approach: Weaving into DSL Grammars
DSL Grammar
ANTLR
Debugging Aspect Specification
In Parlanse Function
Parser’
Lexer’
With Debugging Aspects Weaved in
DSL Code
DebuggingMapping
Code
GPL
In Java
DMSDMS
DSL Grammar’ With Debugging
Aspect Weaved In
Second Approach: Weaving into DSL Grammars
Transform actual DSL Grammar Unique contribution of this paper
Language independence.
12 Steps to Weave Debugging Aspects into DSL Grammar Level Using a Program Transformation Engine (DMS)
1. Specify ANTLR grammar specification2. Specify Java semantic actions using DMS regular expression3. Generate ANTLR Parser4. Generate abstract syntax tree with ANTLR_ACTION nodes5. Search ANTLR_ACTION nodes from the generated AST6. Retrieve ANTLR_ACTION nodes and store them in a hash map7. Retrieve associated string expression from each ANTLR_ACTION node8. Modify the regular Java parser by changing the starting production9. Parse the associated string expressions as regular Java statement lists10.Transform the statement lists using the ASTInterface API11.Regenerate the ANTLR_ACTION nodes with debugging aspects weaved in12.Output the complete ANTLR AST (with modified action nodes)
…command :( RIGHT {
dsllinenumber=dsllinenumber+1;fileio.print(" //move right");fileio.print(" x=x+1;");fileio.print(" time=time+1;");gplbeginline=fileio.getLinenumber();gplendline=fileio.getLinenumber();fileio.print(" ");filemap.print(" mapping.add(new Map("+dsllinenumber+",\"Robot.java\","+gplbeginline+","+gplendline+"));");
} |LEFT { dsllinenumber=dsllinenumber+1;
fileio.print(" //move left");fileio.print(" x=x-1;");fileio.print(" time=time+1;");gplbeginline=fileio.getLinenumber();gplendline=fileio.getLinenumber()fileio.print(" ");filemap.print(" mapping.add(new Map("+dsllinenumber+",\"Robot.java\","+gplbeginline+","+gplendline+"));");
}…
Future Work
More complex DSLs and different types of DSLs need to be investigated Imperative, declarative, and hybrid DSLs
Domain-Specific Language Unit Test Framework (DUTF) to complement the DDF
Domain-Specific Language Profiler Framework (DPF) to monitor the runtime environment and performance of the DSL
Related Work
SmartTools is a software factory which generate language development environment based on Java and XML technologies. But the tools like debugger, is not in the generation list.
The Language Implementation System on Attribute Grammars (LISA) tool is a grammar-based system to generate a compiler, interpreter, and other language-based tools
JastAdd is a Java based compiler construction system for AST transformation using JavaCC and tree-building using JJTree.
Conclusion
This paper describes two different approaches to modularize the DSL debugger generation process.
The second approach, which weaves debugging aspects directly into a DSL grammar, offers the most flexibility.
Drawback of current effort Initial learning curve for DMS is huge
AspectANTLR to be developed to remove accidental complexities of using DMS
IDE platform is based solely on IBM Eclipse support for other IDEs will be needed
Experimentation performed only on a simple imperative DSL additional experimental validation needed for other types of DSLs