Est. 2009 Advanced

Rascal

A domain-specific metaprogramming language from CWI for analyzing, transforming, and generating source code, designed as the modern successor to ASF+SDF

Created by Paul Klint, Tijs van der Storm, and Jurgen J. Vinju (CWI Software Analysis & Transformation group)

Paradigm Multi-paradigm: Functional, Imperative, Metaprogramming (with relational calculus and term rewriting)
Typing Static, Strong (with local type inference)
First Appeared 2009
Latest Version Version 0.42.2 (April 2026)

Rascal is a domain-specific language for metaprogramming — programming whose subject matter is other programs. Developed at the Dutch national research institute CWI (Centrum Wiskunde & Informatica), it is built for the tasks of analyzing, transforming, generating, and visualizing source code, and for defining new languages of one’s own. Where a general-purpose language treats numbers and strings as its primary data, Rascal treats source code itself as data: grammars, parse trees, abstract syntax, relations, and program facts are all first-class values that the language is specially equipped to manipulate.

History & Origins

Rascal did not appear from nowhere. It is the direct successor to a long line of CWI research on algebraic specification and term rewriting, most visibly the ASF+SDF Meta-Environment — an interactive system in which the Syntax Definition Formalism (SDF) described grammars and the Algebraic Specification Formalism (ASF) described rewrite rules over them. Over years of building and using such formalisms, the CWI team accumulated hard-won experience about what worked and what did not when writing tools that operate on programs.

Rascal was the deliberate distillation of that experience into a single, more conventional-looking programming language. It was introduced publicly in 2009 by Paul Klint, Tijs van der Storm, and Jurgen J. Vinju of CWI’s Software Analysis & Transformation (SWAT) group, in the paper “RASCAL: A Domain Specific Language for Source Code Analysis and Manipulation,” presented at the IEEE International Working Conference on Source Code Analysis and Manipulation (SCAM). A 2011 follow-up, “Rascal: From Algebraic Specification to Meta-Programming,” spelled out the lineage explicitly: Rascal kept the best ideas of ASF+SDF — concrete syntax, pattern matching, rewriting — while folding them into a language with ordinary control flow, mutable variables, and a rich standard library.

The influence of the original work has been recognized formally: in 2019 the 2009 SCAM paper received the conference’s Most Influential Paper award, a decade-later acknowledgment of how widely the approach had spread in the source-code-analysis community.

Design Philosophy

Rascal’s guiding principle is captured by its own slogan: “the one-stop shop for metaprogramming.” Rather than gluing together a parser generator, a tree-walking library, a query language, and a templating engine — each with its own data model and conventions — Rascal aims to provide all of these inside one coherent language with one set of data types.

Three commitments follow from this:

  • Source code is data. Programs in any language — Java, C, PHP, Python, and beyond — can be parsed into trees and relations and then queried and rewritten with the same built-in operations.
  • No bias toward any one target language. Rascal is a general meta language; it does not assume the program it analyzes is written in any particular language, which is why the same toolkit serves Java metrics one day and a bespoke DSL the next.
  • Bring research-grade analysis to working tools. The language is explicitly aimed at letting researchers and engineers build new kinds of software tools quickly, then apply them to real, large code portfolios.

Key Features

Concrete and abstract syntax

Rascal lets you write context-free grammars directly in the language and then parse text into trees. You can pattern-match over concrete syntax (fragments that look like the real source code, quotes and all) or over abstract syntax (algebraic data types), choosing whichever is clearer for the task.

// An algebraic data type describing a tiny expression language
data Exp
  = intLit(int n)
  | add(Exp lhs, Exp rhs)
  | mul(Exp lhs, Exp rhs);

// Constant folding via pattern matching
Exp simplify(add(intLit(0), Exp e)) = e;
Exp simplify(mul(intLit(1), Exp e)) = e;
default Exp simplify(Exp e) = e;

Pattern matching and generic traversal

Pattern matching is pervasive and goes well beyond simple cases — it includes deep, list, set, and descendant patterns. The visit statement provides type-safe generic traversal, letting a transformation reach deep into a tree and rewrite just the nodes it cares about without manually recursing through every constructor.

// Double every integer literal anywhere in a tree
Exp doubleAll(Exp e) = visit(e) {
  case intLit(int n) => intLit(n * 2)
};

Relations and relational calculus

Rascal builds relations and sets into the language with operators drawn from relational calculus — composition, transitive closure, image, and comprehensions — which makes whole-program questions (“which methods transitively call this one?”) concise to express.

Source locations

A distinctive built-in type is the source location (loc), an extension of URIs that can pin down an exact region of a local or remote file. Because locations are first-class values, analysis results can be tied precisely back to the code they describe, which is what makes editor integration and clickable diagnostics possible.

The M3 model

Rascal’s standard library ships M3, a general and extensible model for capturing facts about source code — declarations, uses, containment, inheritance, and more — in a uniform, language-independent shape. M3 underpins much of the metric and analysis work done in Rascal, including measurements of Java and PHP systems in the EU OSSMETER project.

Evolution

The implementation has matured steadily rather than dramatically. Today Rascal is developed in the open under the usethesource organization and includes an interpreter, a static type checker, a parser generator, a compiler, and a JVM-based runtime, reflecting its practical orientation toward running real analyses at scale.

Tooling has tracked the wider IDE landscape. Rascal historically generated Eclipse plugins for languages defined in it, and it now also targets Visual Studio Code through the Language Server Protocol, so a language author can define a grammar and get editor features — highlighting, jump-to-definition, diagnostics — generated for them. The released version numbers remain in the pre-1.0 range — reportedly around 0.42.2 in April 2026 — but the project has a long, continuous history of use well predating those tags, with the line stretching back through ASF+SDF.

Current Relevance

Rascal occupies a clear and durable niche. It is not a mainstream application-development language; it is a specialized instrument for people who build tools about software:

  • Software-engineering research — as the working language of CWI’s SWAT group and collaborators studying program analysis, transformation, and language design.
  • Language and DSL engineering — as a language workbench in which new domain-specific languages, with their own syntax and generated IDE support, can be built end to end.
  • Empirical analysis of code portfolios — through frameworks like PHP AiR and the M3 model, which turn large real-world codebases into queryable data.
  • Specialized DSLs — such as Derric, a digital-forensics language for describing file formats and generating recovery tools.

Why It Matters

Rascal’s importance lies less in raw adoption numbers and more in the idea it makes practical: that the messy, multi-step craft of working with code — parsing it, analyzing it, rewriting it, measuring it, and visualizing the results — deserves one integrated language rather than a pile of disconnected tools. By carrying the rigor of algebraic specification and term rewriting into a language with familiar control flow and a batteries-included library, it lowered the barrier to building serious source-code tools. For students of programming languages and for engineers facing a large, unfamiliar codebase, Rascal remains one of the most complete and instructive metaprogramming environments available.

Timeline

1990s
CWI develops the ASF+SDF Meta-Environment, an interactive system for algebraic specification and term rewriting that becomes the direct ancestor of Rascal
2009
Rascal is introduced by Paul Klint, Tijs van der Storm, and Jurgen Vinju at the IEEE International Working Conference on Source Code Analysis and Manipulation (SCAM), in the paper 'RASCAL: A Domain Specific Language for Source Code Analysis and Manipulation'
2011
The team publishes 'Rascal: From Algebraic Specification to Meta-Programming', documenting the move from ASF+SDF toward a general-purpose metaprogramming language; Rascal is developed as open-source software
2014
PHP AiR (PHP Analysis in Rascal), a framework for analyzing large PHP systems, is presented at CSMR-WCRE (the IEEE Software Evolution Week), demonstrating Rascal on real-world software portfolios
2015
The M3 model — a general, extensible representation of source-code facts — is described as part of Rascal's standard library and used in projects such as the EU OSSMETER effort
2019
The original 2009 SCAM paper receives the SCAM Most Influential Paper award, recognizing its lasting impact a decade after publication
2023
Rascal reaches approximately the 0.30.x release line, with the project hosted under the usethesource organization and tooling delivered through both Eclipse and VS Code (via the Language Server Protocol)
2026
Version 0.42.2 is released (April), continuing steady development of the interpreter, type checker, parser generator, and JVM-based runtime

Notable Uses & Legacy

CWI Software Analysis & Transformation group

Rascal is the primary research vehicle of the SWAT group at CWI in Amsterdam, used to prototype program analyses, language tooling, and domain-specific languages.

PHP AiR

A framework for analyzing large PHP systems built entirely in Rascal, used to study how PHP language features are used in practice, how systems evolve, and to support refactoring and security analysis.

OSSMETER and the M3 model

Rascal's M3 source-code model was applied in the EU OSSMETER project to compute object-oriented and procedural metrics for Java and PHP code, supporting open-source quality measurement.

Derric

A domain-specific language for digital forensics and file carving, implemented in Rascal, that lets investigators describe file formats and generate validating recovery tools.

Language workbench and IDE generation

Rascal is used to define new languages with concrete syntax and then automatically generate editor support, including Eclipse plugins and VS Code extensions via the Language Server Protocol.

Language Influence

Influenced By

ASF+SDF SDF ML

Running Today

Run examples using the official Docker image:

docker pull
Last updated: