I am trying to write a parser in Scala for SML with tokens. It almost works the way I want it to work, except for the fact that it is currently analyzing
let fun fx = r and fun gy at the end of r;
instead
let fun fx = r and gy at the end of r;
How can I change the code so that it finds out that the second function does not need a FunToken?
def parseDef:Def = { currentToken match { case ValToken => { eat(ValToken); val nme:String = currentToken match { case IdToken(x) => {advance; x} case _ => error("Expected a name after VAL.") } eat(EqualToken); VAL(nme,parseExp) } case FunToken => { eat(FunToken); val fnme:String = currentToken match { case IdToken(x) => {advance; x} case _ => error("Expected a name after VAL.") } val xnme:String = currentToken match { case IdToken(x) => {advance; x} case _ => error("Expected a name after VAL.") } def parseAnd:Def = currentToken match { case AndToken => {eat(AndToken); FUN(fnme,xnme,parseExp,parseAnd)} case _ => NOFUN } FUN(fnme,xnme,parseExp,parseAnd) } case _ => error("Expected VAL or FUN."); } }
source share