Skip to content

Instantly share code, notes, and snippets.

@Rogach
Rogach / gist:1646123
Created January 20, 2012 08:24
Simple math interpreter
object Interpreter {
def main(args:Array[String]) = {
(new SimpleParser).parseString("2*3.2 + 3*(36.07/4 - 10)").println
}
import scala.util.parsing.combinator._
class SimpleParser extends JavaTokenParsers {
def expr: Parser[Double] = (
term~"+"~expr ^^ { case a~"+"~b => a + b }
| term~"-"~expr ^^ { case a~"-"~b => a - b }
@Rogach
Rogach / gist:1577445
Created January 8, 2012 06:17
Trying to get simple syntax tree out of scala compiler
import scala.tools.nsc.interactive.{Global, RefinedBuildManager}
import scala.tools.nsc.Settings
import scala.tools.nsc.reporters.StoreReporter
import scala.tools.nsc.io._
import scala.tools.nsc.util._
import scala.tools.nsc.interactive.Response
import scala.tools.nsc.util.{Position, OffsetPosition}
import scala.reflect.generic.Trees
val settings = new Settings