We introduce a declarative Domain Specific Language (DSL), called RubyWrite, embedded within Ruby, with the goal of providing an extensible, effective, portable, and easy to use framework for writing source-to-source compilers. Through its combination of declarative specification of program transformations and traversals, RubyWrite enables clear and concise writing of analysis and transformation steps. At the same time, having this declarative DSL embedded in a multi-paradigm language allows compiler writers to employ standard algorithms and data structures that often use global state. This eliminates the need to adapt the standard compiler algorithms to work within a purely declarative environment, which can cause loss of algorithmic efficiency.
RubyWrite aids us in our compiler research where it provides the core of three compiler infrastruc- ture development projects, and is used as a teaching aid in a graduate-level compilers course. We expect RubyWrite to be widely applicable and a proof of concept of the utility of combining declarative expressiveness with imperative capabilities in a high-level modern language aimed at developing a variety of compiler infrastructure.