Created
September 7, 2012 15:35
-
-
Save jonifreeman/3667222 to your computer and use it in GitHub Desktop.
Kiama rewrite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import org.kiama.rewriting.Rewriter._ | |
import org.kiama.rewriting.Rewriter._ | |
scala> trait Expr | |
defined trait Expr | |
scala> case class Constant(x: Int) extends Expr | |
defined class Constant | |
scala> case class Add(e1: Expr, e2: Expr) extends Expr | |
defined class Add | |
scala> val e = Add(Constant(1), Constant(2)) | |
e: Add = Add(Constant(1),Constant(2)) | |
scala> val rewritePlus5 = everywheretd (rule { case Constant(x) => Constant(x+5) }) | |
rewritePlus5: org.kiama.rewriting.Rewriter.Strategy = <function1> | |
scala> rewrite (rewritePlus5) (e) | |
res0: Add = Add(Constant(6),Constant(7)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment