diff --git a/sources/zweic/Analyzer.scala b/sources/zweic/Analyzer.scala index ae9aa05..5918917 100755 --- a/sources/zweic/Analyzer.scala +++ b/sources/zweic/Analyzer.scala @@ -49,7 +49,8 @@ case MethodDef(name, args, rtype, expr) => lookupMethod(name) match { case Some => - ownerClass.enterMethod + var paramtypes = for ( val Pair(x,y) <- args ) yield analyzeType(y); + ownerClass.enterMethod(MethodSymbol(tree.pos, name, paramtypes, analyzeType(rtype))) } } @@ -57,11 +58,32 @@ private def analyzeStat(varScope: VarScope, tree: Stat): VarScope = tree match { - case While(cond, stats) => - checkIntType(cond.pos, analyzeExpr(varScope, cond)); - stats.foldLeft(varScope)(analyzeStat); - varScope + case While(cond, stats) => + checkIntType(cond.pos, analyzeExpr(varScope, cond)); + stats.foldLeft(varScope)(analyzeStat); + varScope + case Var(name, typ, expr) => + varScope.get(name) match { + case Some(v) => + Report.error(tree.pos, "Variable already defined " + name.name); + case None => + val mv = VarSymbol(tree.pos, name, typ) + val et = analyzeExpr(varScope, expr) + varScope = varScope + name -> VarSymbol() + } + varScope + // ... � compl�ter ... + case Set(ident, expr) => + varScope.get(ident.name) match { + case Some(v) => + ident.sym = v; + if ( !analyzeExpr(varScope, expr).isSubtype(v.vartype) ) + Report.error(tree.pos, "Incompatible_types"); + case None => + Report.error(tree.pos, "Unknown variable " + ident.name); + } + varScope } // Analyze a type @@ -90,6 +112,27 @@ case IntLit(_) => IIntType // ... � compl�ter ... + case Ident(name) => + varScope.get(name.name) match { + case Some(v) => + name.sym = v; + v.vartype + case None => + Report.error(tree.pos, "Unknown variable " + name);K + IBadType + } + + case Binop(op, left, right) => + val t1 = analyzeExpr(varScope, left); + val t2 = analyzeExpr(varScope, right); + if ( op == EQ || op == NE ) { + if ( !(t1.isSubtype(t2) || t2.isSubtype(t1)) ) + Report.error(tree.pos, "Incompatible types: " + t1 + " <=> " + t2); + } else { + checkIntType(left.pos, t1); + checkIntType(right.pos, t2); + } + IIntType } /**