110 likes | 265 Views
Designing an XML-based Exchange Format for Harmonia. Marat Boshernitsan Susan L. Graham University of California, Berkeley, USA Exchange Formats Workshop WCRE 2000, Brisbane, Australia. Application Domain. Harmonia: a framework for constructing interactive language-based programming tools
E N D
Designing an XML-basedExchange Format for Harmonia Marat Boshernitsan Susan L. Graham University of California, Berkeley, USA Exchange Formats Workshop WCRE 2000, Brisbane, Australia
Application Domain • Harmonia: a framework for constructing interactive language-based programming tools • Primary focus: front-end, user-visible tools (language-sensitive editors, source browsers, design assistants) • Simultaneously support many languages: C++, Java, as well as smaller domain-specific languages (make, bison, …) • Fine-grain version history: enables incremental analyses and other user services • Rapid prototyping: bindings for C++, C, Tcl, Java, Lisp • External tool integration: existing analyzers, source transformers, etc.
use XML model internal program representation Exchange Format Requirements • General requirements • Support for industry standards • Convenient APIs • Easy to generate, store, and parse • Domain requirements • Small tools (individual source files) and large tools (entire software projects) • Harmonia-enabled tools as well as external language-sensitive tools • Legacy text-based tools (editors, compilers, etc.) • Support many languages – can not standardize on one encoding, e.g. JavaML
actually, ASG! to variable declaration to method declaration Example • Text: “if (cond) f();” • AST… IfThenStmt if ( VarRef ) ExprStmt Name MethodCall ; cond Name ( Args ) f
IfThenStmt if ( VarRef ) ExprStmt Name MethodCall1 ; cond Name2 (4 Args5 )6 f3 to method declaration: 42 Encoding Graphs <node id=1 name=MethodCall> <edge target=2 type=child/> <edge target=4 type=child/> <edge target=5 type=child/> <edge target=6 type=child/> </node> <node id=2 name=Name> <edge target=3 type=child/> <edge target=42 type=decl/> </node> <node id=3 name=IDENT text="f"/> <node id=4 name=LPAREN text="("/> <node id=5 name=Args></node> <node id=6 name=RPAREN text=")"/>
Encoding Trees <node id=1 name=MethodCall> <edge target=2 type=child/> <edge target=4 type=child/> <edge target=5 type=child/> <edge target=6 type=child/> </node> <node id=2 name=Name> <edge target=3 type=child/> <edge target=42 type=decl/> </node> <node id=3 name=IDENT text="f"/> <node id=4 name=LPAREN text="("/> <node id=5 name=Args></node> <node id=6 name=RPAREN text=")"/> IfThenStmt if ( VarRef ) ExprStmt Name MethodCall1 ; cond Name2 (4 Args5 )6 f3 to method declaration:42 <node id=1 name=MethodCall> <node id=2 name=Name decl=42> <node id=3 name=IDENT text="f"/> </node> <node id=4 name=LPAREN text="("/> <node id=5 name=Args></node> <node id=6 name=RPAREN text=")"/> </node>
Schemas • XML documents should have a DTD <node id=1 name=MethodCall> <node id=2 name=Name decl=42> <node id=3 name=IDENT text="f"/> </node> <node id=4 name=LPAREN text="("/> <node id=5 name=Args></node> <node id=6 name=RPAREN text=")"/> </node> <!ELEMENT node (node)*> <!ATTLIST node ...all node attributes...> • No type restrictions – cannot validate with respect to programming language • Need additional data schema
Schemas (cont.) • Idea: use the same typing mechanism as the AST • AST nodes typed according to the abstract grammar • Generate DTD from abstract grammar (used by the parser) • Interpret the DTD as a data schema <MethodCall id=1> <Name id=2 decl=42> <IDENT id=3 text="f"/> </Name> <LPAREN id=4 text="("/> <Args id=5></Args> <RPAREN id=6 text=")"/> </MethodCall> <!ELEMENT MethodCall (Name, LPAREN, Expr*, RPAREN)> <!ELEMENT Name (IDENT)> <!ATTLIST MethodCall id ID #REQUIRED> <!ATTLIST Name id ID #REQUIRED decl IDREF #REQUIRED>
Encoding Program Text • Legacy tools may not want to understand XML: but it is not so easy to get to program text • One last refinements: simply mark up the source… <MethodCall id=1> <Name id=2 decl=42> <IDENT id=3>f</IDENT> </Name> <LPAREN id=4>(</LPAREN> <Args id=5></Args> <RPAREN id=6/>)</LPAREN> </MethodCall> • Don’t want structure? Strip off XML tags (with XSL!): <xsl:template match="/"> <xsl:apply-templates/> </xsl:template>
Future Directions • Schema and grammar evolution • Schema will change with the grammar • Not really a problem: the grammar is abstract and rarely changes • Still, can use XSL to transform existing data to a new schema • Harmonia-enabled editor can generate transformations automatically • Incorporating version information • Need easy access to current version • Should be able to get to older versions • Data granularity for high level modeling tools • Need incremental refinement of detail
Conclusions • An encoding satisfying all design requirements • XML-based (standard, convenient APIs, easy import/export) • Works for variety of tools • Can utilize many off-the-shelf XML tools/libraries • Programming language independent (DTD generated from language grammar) • More information • Harmonia web page: • http://www.cs.berkeley.edu/Research/Projects/harmonia • Email: • Marat Boshernitsan <maratb@cs.berkeley.edu>