Reputation: 165
I am working on scala and I am trying to make this parser:
<expr> ::= <num>
| (cond (<expr> <expr>) ...) # multi-armed conditional
| (cond (<expr> <expr>) ... (else <expr>)) # multi-armed conditional w/ else
this is my code for this part:
case SList(List(SSym(cond),SList(List(a,b)))) => CondExt(parse(SList(List.apply(a,b))))
when I run this code I get this error:
Status: CompilationFailure
solution.scala:53: error: type mismatch;
found : ExprExt
required: List[(ExprExt, ExprExt)]
case SList(List(SSym(cond),SList(List(a,b)))) => CondExt(parse(SList(List.apply(a,b))))
How is this error fixed I tried several other different ways:
case SList(List(SSym(cond),SList(List((a,b)),SList(List((c,d)))))) => CondExt(SList(List(parse(a),parse(b))))
and for this I get this error:
Status: CompilationFailure
solution.scala:54: error: wrong number of arguments for <none>: (list: List[Library.SExpr])Library.SList
case SList(List(SSym(cond),SList(List((a,b)),SList(List((c,d)))))) => CondExt(SList(List(parse(a),parse(b))))
^
solution.scala:54: error: not found: value a
case SList(List(SSym(cond),SList(List((a,b)),SList(List((c,d)))))) => CondExt(SList(List(parse(a),parse(b))))
How can someone point me to my mistake that I am doing.
Extra Info:
case class CondExt(cs: List[(ExprExt, ExprExt)]) extends ExprExt
case class CondEExt(cs: List[(ExprExt, ExprExt)], e: ExprExt) extends ExprExt
sealed abstract class SExpr
case class SNum(n : Int) extends SExpr
case class SSym(s : String) extends SExpr
case class SList(l : List[SExpr]) extends SExpr
object Parser {
def parse(str: String): ExprExt = parse(Reader.read(str))
def parse(sexpr: SExpr): ExprExt = {
}
}
Upvotes: 1
Views: 542
Reputation: 10623
The problem is here:
CondExt(parse(SList(List.apply(a,b))))
The parse(SList(...))
calls parse(arg:SExpr):ExprExt
. This tries to call CondExt(arg:ExprExt)
, But CondExt
only has an apply
method defined for an argument of type List[(ExprExt, ExprExt)]
.
You either need to make CondExt
take ExprExt
s, make parse
return a List[(ExprExt, ExprExt)]
, or do something else to make the types match.
Upvotes: 1