alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (treePrint.scala)

This example Scala source code file (treePrint.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

bufferedreader, imain, int, nulloutputstream, nulloutputstream, outputstream, outputstream, power, printwriter, printwriter, settings, stringreader, test, writer

The Scala treePrint.scala source code

/** Testing compact tree printers.
 */
object Test {
  import scala.tools.nsc._
  import interpreter._
  import java.io.{ OutputStream, BufferedReader, StringReader, PrintWriter, Writer, OutputStreamWriter}
  
  val code = """
    def foo = {
      var q: Boolean = false
      val x = if (true) {
        if (true) {
          if (true) {
            5
          }
          else if (true) {
            5
          } else {
            10
          }
        }
        else 20
      }
      else 30
    
      (x == 5) || !q || true
    }
  """  
  
  class NullOutputStream extends OutputStream { def write(b: Int) { } }

  def main(args: Array[String]) {
    val settings = new Settings
    settings.classpath.value = System.getProperty("java.class.path")
    settings.Ycompacttrees.value = true

    val intp = new IMain(settings, new PrintWriter(new NullOutputStream))
    val power = Power(intp)
    intp.interpret("""def initialize = "Have to interpret something or we get errors." """)
    power trees code foreach println
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala treePrint.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.