Title: Weaving a Debugging Aspect into DomainSpecific Language Grammars
1Weaving a Debugging Aspect into Domain-Specific
Language Grammars
Hui Wu, Jeff Gray, Marjan Mernik, and Suman
Roychoudhury
http//www.cis.uab.edu/wuh/DDF
SAC 05 PSC Track Santa Fe, New Mexico USA March
17, 2005
This Research is Supported by Eclipse Innovation
Grant by IBM
2Challenges with DSL Debugging
Editor
Domain Experts program at DSL level
Compiler
Domain Experts deal with GPL
Visualizer
Debugger
Integrated Development Environment
DSL translated into General Purpose Language
(GPL)
Domain Experts deal with DSL
3Difficulties 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
systems 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
4Architecture of DSL Debugging Framework
Robot DSL corresponding GPL code generated in
Java
DSL grammar is defined using ANTLR Notation
DSL is the input of the Lexer and Parser
generated by ANTLR
Additional Mapping code generated in Java
DSL translation process
Corresponding GPL and Mapping Code are inputs of
Mapping component
Eclipse Debugging perspective communicates with
mapping component
jdb communicates with mapping component
5Architecture of DSL Debugging Framework
- Reuse existing GPL standalone command line
debugger - Generative Programming techniques are used to
synthesize debugger mapping code from DSL grammar
specification - Utilize the debugging methods mapping knowledge
and source code mapping information to generate
the DSL debugger in Eclipse - Map the GPL debugger output messages back to the
DSL level through the wrapper interface
6Mapping Technique to Generate Debugger
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.
Source Code Mapping
The debug methods mapping process takes the
users 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.
Debug Methods Mapping
DSL Debugger Framework (DDF)
7Debugging A Crosscutting Grammar Concern
Base Grammar
command ( RIGHT fileio.print(" //
move right") fileio.print(" xx1") file
io.print(" timetime1") fileio.print("
") LEFT fileio.print(" //
move left") fileio.print(" xx-1") filei
o.print(" timetime1") fileio.print("
")
What if this line changes?
Change here
Duplicate Debugging Aspect Code
dsllinenumberdsllinenumber1 gplbeginlinefil
eio.getLinenumber() gplendlinefileio.getLinenumb
er() filemap.print(" mapping.add(new
Map("dsllinenumber", \"Robot.java\","gplbeginli
ne","gplendline"))")
dsllinenumberdsllinenumber1 gplbeginlinefil
eio.getLinenumber() gplendlinefileio.getLinenumb
er() filemap.print(" mapping.add(new
Map("dsllinenumber", \"Robot.java\","gplbeginli
ne","gplendline"))")
Change here
Change
8First Approach Weaving at GPL Level
Lexer
DSL Grammar
ANTLR
Debugging Aspect Specification In AspectJ
Parser
In Java
AspectJ Compiler
Lexer
GPL
DSL Code
Parser
Debugging Mapping Code
With Debugging Aspects Weaved in
In Java
9First Approach Weaving at GPL Level
Generated Parser code by ANTLR
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())
Debugging Aspect in AspectJ
-
- 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 dsllinenumberdsllinenumber1
-
10First Approach Weaving at GPL Level
- Disadvantages
- 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
11Second Approach Weaving into DSL Grammars
Debugging Aspect Specification In Parlanse
Function
DSL Grammar
DSL Code
DMS
Lexer
GPL
DSL Grammar With Debugging Aspect Weaved In
ANTLR
Parser
Debugging Mapping Code
With Debugging Aspects Weaved in
In Java
12Second Approach Weaving into DSL Grammars
command ( RIGHT dsllinenumberdsllin
enumber1 fileio.print(" //move
right") fileio.print(" xx1") fileio.print(
" timetime1") gplbeginlinefileio.getLinenum
ber() gplendlinefileio.getLinenumber() fileio
.print(" ") filemap.print(" mapping.add(new
Map("dsllinenumber", \"Robot.java\","gplbeginl
ine","gplendline"))") LEFT
dsllinenumberdsllinenumber1 fileio.print("
//move left") fileio.print(" xx-1") fileio.
print(" timetime1") gplbeginlinefileio.getL
inenumber() gplendlinefileio.getLinenumber() f
ileio.print(" ") filemap.print("
mapping.add(new Map("dsllinenumber", \"Robot.ja
va\","gplbeginline","gplendline"))")
- 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 specification 2.
Specify Java semantic actions using DMS regular
expression 3. Generate ANTLR Parser 4. Generate
abstract syntax tree with ANTLR_ACTION nodes 5.
Search ANTLR_ACTION nodes from the generated
AST 6. Retrieve ANTLR_ACTION nodes and store
them in a hash map 7. Retrieve associated string
expression from each ANTLR_ACTION node 8. Modify
the regular Java parser by changing the starting
production 9. Parse the associated string
expressions as regular Java statement
lists 10.Transform the statement lists using the
ASTInterface API 11.Regenerate the ANTLR_ACTION
nodes with debugging aspects weaved in 12.Output
the complete ANTLR AST (with modified action
nodes)
13DSL Debugger Perspective in Eclipse
14Future 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
15Related 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.
16Conclusion
- 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
17Questions?
- Summary of URLs referenced in talk
- DSL Debugger Framework
- http//www.cis.uab.edu/wuh/DDF
- ANTLR
- http//www.antlr.org
- AspectJ
- http//www.aspectj.org
- DMS
- http//www.semdesigns.com
DDF