Kiama /

Filename Size Date modified Message
148 B
Add ENSIME-related files to .hgignore
2.7 KB
Added tag v2.1.0 for changeset cb1c855aa45a
71 B
Remove --XX:MaxPermSize option from SBT options since we have moved to Java 8 now
16.7 KB
Move to Mozilla Public License v 2.0
9.6 KB
Add newline at end of README
372 B
Fix typo in pipeline setup
7.3 KB
Move to sbt 1.0.0


Build Status

Kiama is a Scala library for language processing. In the Kiama project we are investigating embedding of language processing formalisms such as grammars, parsers, rewriters and analysers into general-purpose programming languages.

IMPORTANT NOTE: Kiama is a research project, so many details will change. Consult with us before you rely on it for serious work. We make no guarantees about the features or performance of the Kiama library if you do choose to use it.

Tony Sloane

Programming Languages and Verification Research Group Department of Computing, Macquarie University

Latest News

  • Jun 19, 2017: Version 2.1.0 released
  • Apr 6, 2016: Version 2.0.0 released
  • Jun 24, 2015: moved project to BitBucket
  • Nov 10, 2014: Version 1.8.0 released
  • Aug 11, 2014: Version 1.7.0 released
  • May 16, 2014: Version 1.6.0 released
  • Apr 21, 2014: Version 1.5.3 released


Documentation about how to build, install and use Kiama can be found on the Kiama wiki.

The main documentation for Kiama takes the form of wiki pages covering library features and examples, available at the Google Code site. The User Manual is a good place to start.

See the Research wiki page for links to papers and presentations about Kiama.

For summary information about Kiama releases, including dependencies on other software and links to API documentation, see the Releases wiki page.

See the Installation wiki page for instructions on how to install Kiama.


Kiama is distributed under the Mozilla Public License, v. 2.0. See the file LICENSE for details of the license. More information can be obtained from Mozilla.

Some Examples

A traditional approach to language processing is to represent the data to be processed as a hierarchical structure (a tree). Kiama provides different ways to operate on such trees to carry out typical language processing tasks.

Attribute equations define properties of tree nodes in terms of constants or the properties of other nodes. In this example, the local and global minima of a binary tree (locmin and globmin) are defined using simple local equations. Accessing an attribute (property) of a node is just a function call (also accessible via the arrow notation in Kiama 1.x). The attr function provides caching and circularity checking to the equations.

Kiama version 1.x:

val locmin : Tree ==> Int =
    attr {
        case Fork(l, r) => (l->locmin) min (r->locmin)
        case Leaf(v)    => v

val globmin : Tree ==> Int =
    attr {
        case t if t isRoot => t->locmin
        case t             => t.parent[Tree]->globmin

Kiama version 2.x:

val locmin : RepminTree => Int =
    attr {
        case Fork(l, r) => locmin(l).min(locmin(r))
        case Leaf(v)    => v

val globmin : RepminTree => Int =
    attr {
        case tree.parent(p) => globmin(p)
        case t              => locmin(t)

Sometimes it is useful to define attributes using a mutual dependency. With attr this approach would lead to an error since it would not be possible to calculate the values of such attributes. The circular function goes further by implementing mutually dependent attributes via an iteration to a fixed point. In this example, we are calculating variable liveness information for a imperative language statements using the standard data flow equations.

Kiama 1.x:

val in : Stm ==> Set[Var] =
    circular(Set[Var]()) {
        case s => uses(s) ++ (out(s) -- defines(s))

val out : Stm ==> Set[Var] =
    circular(Set[Var]()) {
        case s => (s->succ) flatMap (in)

Kiama 2.x:

val in : Stm => Set[Var] =
        s => uses(s) ++ (out(s) -- defines(s))

val out : Stm => Set[Var] =
        s => succ(s) flatMap (in)

While attributes provide a way to decorate a tree with information, rewriting is concerned with transforming trees, perhaps for translation or for optimisation. Kiama contains a strategy-based rewriting library heavily inspired by the [ Stratego] program transformation language. In this example, we are implementing an evaluation strategy for lambda calculus, using generic strategies such as innermost rewriting.

Kiama 1.x:

val beta =
    rule {
        case App(Lam(x, t, e1), e2) =>  Let(x, t, e2, e1)

Kiama 2.x:

val beta =
    rule[Exp] {
        case App(Lam(x, t, e1), e2) => substitute(x, e2, e1)

Kiama 1.x and 2.x:

val lambda =
    beta + arithop + subsNum + subsVar + subsApp + subsLam + subsOpn

def innermost (s : => Strategy) : Strategy =
    all(innermost(s) <* attempt(s <* innermost(s)))

val s : Strategy =

Kiama's pretty-printing library provides a flexible way to describe how you want your output to be produced within constraint of line length. For example, the following describes how to pretty-print the constructs of a simple imperative language, where group, nest and line cooperate to produce nicely indented code that breaks lines at sensible place when needed.

Kiama 1.x and 2.x:

def toDoc(t : ImperativeNode) : Doc =
    t match {
        case Num(d)      => value(d)
        case Var(s)      => s
        case Neg(e)      => parens("-" <> toDoc(e))
        case Add(l, r)   => binToDoc(l, "+", r)
        case Sub(l, r)   => binToDoc(l, "-", r)
        case Mul(l, r)   => binToDoc(l, "*", r)
        case Div(l, r)   => binToDoc(l, "/", r)
        case Null()      => semi
        case Seqn(ss)    => group(braces (nest (line <> ssep (ss map toDoc, line)) <> line))
        case Asgn(v, e)  => toDoc(v) <+> "=" <+> toDoc(e) <> semi
        case While(e, b) => "while" <+> parens(toDoc(e)) <> group(nest(line <> toDoc(b)))

def binToDoc(l : ImperativeNode, op : String, r : ImperativeNode) : Doc =
    parens(toDoc(l) <+> op <+> toDoc (r))

Mailing lists

There are also two Google Groups for Kiama:

  • kiama (General announcements and discussions)

  • kiama-commit (Commit messages and build problems)



The main Kiama Project team is:

  • Tony Sloane
  • Matthew Roberts
  • Dominic Verity

Other contributors have been:

  • Len Hamey
  • Lennart Kats and Eelco Visser (some aspects of attribution)
  • Ben Mockler (the first version of the Oberon-0 example)

Kiama is currently concentrating on incorporating existing language processing formalisms, so credit goes to the original developers of those formalisms. See the code for details of the sources of ideas that come from elsewhere.

Many of the library rewriting strategies are based on the Stratego library. See


Work on this project has been supported by the following Universities, funding agencies and companies.

  • University of Minnesota

  • Delft University of Technology, The Netherlands

  • Eindhoven University of Technology, The Netherlands

  • Netherlands Organization for Scientific Research

    • Combining Attribute Grammars and Term Rewriting for Programming Abstractions project (040.11.001)
    • MoDSE: Model-Driven Software Evolution project (638.001.610)
    • TFA: Transformations for Abstractions project (612.063.512)
  • YourKit


YourKit is kindly supporting open source projects with its full-featured Java Profiler. YourKit, LLC is the creator of innovative and intelligent tools for profiling Java and .NET applications. Take a look at YourKit's leading software products: YourKit Java Profiler and YourKit .NET Profiler.

  • CloudBees


CloudBees provides generous support to FOSS projects for continuous builds and other services, for which we are very grateful. nightly builds are built on a CloudBees Jenkins instance, part of their DEV@cloud service.