Created
July 5, 2009 09:42
-
-
Save kentaro/140914 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import scala.collection.mutable.ArrayStack | |
object Kemuri extends Application { | |
private var stack: ArrayStack[Int] = new ArrayStack[Int]; | |
private def eval (c: Char) = { | |
if (c == '|') { | |
stack.foreach((i:Int) => print(i.toChar)) | |
stack.clear | |
} | |
else if (c == '^') { | |
val a = stack.pop | |
val b = stack.pop | |
stack.push(a ^ b) | |
} | |
else if (c == '~') { | |
stack.push(~stack.pop) | |
} | |
else if (c == '"') { | |
val a = stack.pop | |
stack.push(a) | |
stack.push(a) | |
} | |
else if (c == '\'') { | |
val a = stack.pop | |
val b = stack.pop | |
val c = stack.pop | |
stack.push(a) | |
stack.push(c) | |
stack.push(b) | |
} | |
else if (c == '`') { | |
"Hello, world!".reverse.foreach((c:Char) => stack.push(c.toByte)) | |
} | |
else { error("illegal char") } | |
} | |
def run (args: Array[String]): Unit = { | |
args.foreach((s:String) => s.foreach(eval)) | |
} | |
def run (args: String): Unit = { | |
args foreach eval | |
} | |
} | |
Kemuri.run(args) | |
// Kemuri.run("`|"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment