2010-04-10 2 views
5

위해 나는 다음과 같은 코드를 사용하여 스칼라 AST를 생성하고 :생성의 스칼라 AST는 재귀 적 방법

val setting = new Settings(error) 
    val reporter = new ConsoleReporter(setting, in, out) { 
     override def displayPrompt =() 
    } 

    val compiler = new Global(setting, reporter) with ASTExtractor{ 
     override def onlyPresentation = true 
    } 
    //setting.PhasesSetting("parser", "parserPhase") 
    val run = new compiler.Run 
    val sourceFiles:List[String] = List("Test.scala") 
    run.compile(sourceFiles.toList) 

나는이 코드에서 컴파일러를 실행하고 작업 할 AST를 생성하는 데 사용되는 표준 코드입니다 같아요. 위의 코드는 지금까지 Test.scala에서 유효한 모든 스칼라 코드에 대해 잘 작동했습니다. (: 지능 X) = Int 인 경우 (여기서 x는 == 0) -1 다른 xMethod (X-1)

제가

DEF xMethod 같은 Test.scala에서 재귀 함수를 사용하면 그것은 나에게 java.lang.NullPointerException을 준다. 스택 추적의 상위 몇 줄의 코드는

def aMethod(c:Int):Int = { bMethod(c) } 
def bMethod(x:Int):Int = aMethod(x) 

재귀 함수는 다른 설정이 필요하면 알려 주시기 바랍니다 같은 방법에 대해 잘 작동이

at scala.tools.nsc.typechecker.Typers$Typer.checkNoDoubleDefsAndAddSynthetics$1(Typers.scala:2170) 
at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2196) 
at scala.tools.nsc.typechecker.Typers$Typer.typedBlock(Typers.scala:1951) 
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3815) 
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4124) 
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4177) 
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:199) 

처럼 보인다.

답변