Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行scala程序_Scala_Intellij Idea_Grammar - Fatal编程技术网

运行scala程序

运行scala程序,scala,intellij-idea,grammar,Scala,Intellij Idea,Grammar,我在scala中运行程序时遇到问题。我对该语言非常陌生,无法在intellij中设置它,因此我现在使用sublime并尝试在终端中运行它。当我尝试运行microproject类时,我总是得到arrayindexoutofbounds错误 如果有人能帮我弄清楚如何运行这个程序,那就太好了 import scala.util.parsing.combinator._ abstract class MatchTree case class S(e:MatchTree) extends MatchTr

我在scala中运行程序时遇到问题。我对该语言非常陌生,无法在intellij中设置它,因此我现在使用sublime并尝试在终端中运行它。当我尝试运行microproject类时,我总是得到arrayindexoutofbounds错误

如果有人能帮我弄清楚如何运行这个程序,那就太好了

import scala.util.parsing.combinator._

abstract class MatchTree
case class S(e:MatchTree) extends MatchTree
case class E(c:MatchTree, e:MatchTree) extends MatchTree
case class C(s:String) extends MatchTree
case class NIL() extends MatchTree

class MPParser extends JavaTokenParsers{
def s: Parser[MatchTree] = e ^^ {case se => S(se)}
def e: Parser[MatchTree] = c ~ e ^^ {case ch ~ ex => E(ch,ex)} | c ^^ {case 
ch => E(ch,NIL())}
def c[C] = ("a" | "b") ^^ {case ch => C(ch)}
}

object Microproject extends MPParser{
def main(args: Array[String]) {
println("input : "+ args(0))
println(parseAll(s, args(0)))
}
}

看起来程序需要您向其传递一个参数。您可以这样做(在命令行上):

这就是你应该知道的:

println("input : "+ args(0))
如您所见,此行将第一个参数输出到程序(
args(0)
)。下一次,您可以查看堆栈跟踪,查看错误发生在哪一行上,并查看是否可以找出那里发生了什么。此外,在未来,你可能更可能从你的教授那里得到运行教授程序的帮助,而不是从互联网上。你这次很幸运


另外,我不知道程序需要什么参数。你得问问你的教授。

听起来你已经成功地运行了这个程序。这个程序是否有效是另一个问题。我认为它有效是因为我的老师非常感谢!
println("input : "+ args(0))