RubyWrite
RubyWrite was developed between 2008 and 2009 as an aid in writing source-level compilers. It was developed jointly by my students and I. It is a domain-specific language (DSL), embedded in Ruby, and useful for writing high-level compilers in Ruby (but could be used to compile any language). The software has been in use since then in several of my research projects, and for teaching in two compilers course, B629 and P523.
Technically, RubyWrite is tree-rewriting DSL, embedded in Ruby. It consists of three main components:
- A tree-building component that defines the [] operator for the Ruby Symbol class to enable easy construction of the Abstract Syntax Tree (AST). Nodes in the tree are of type Node.
- A mini-DSL within RubyWrite to write unparsers. It allows a succinct and intuitive description of pretty-printing rules to convert an AST into cleanly indented concrete syntax.
- A tree rewriting component that provides a declarative approach to rewrite ASTs, enabling source-level transformations to be described cleanly and compactly.
The RubyWrite manual provides several examples of tree rewriting and analysis, including expression flattening, data-flow analysis, and general tree traversal. There is also support for using concrete syntax of the language being compiled, which greatly simplifies writing complicated transformations.
Related publications:
-
Arun Chauhan, Andrew Keep, Chun-Yu Shei and Pushkar Ratnalikar. RubyWrite: A Ruby-embedded Domain-specific Language for High-level Transformations. Technical Report TR704, School of Informatics and Computing, Indiana University, Bloomington, Indiana, USA, January 2013. Reference Manual for RubyWrite.
[Full text]