diff --git a/script.sh b/script.sh index 37c4d8d..e3fd1df 100755 --- a/script.sh +++ b/script.sh @@ -8,7 +8,7 @@ This wicked cool script will test your Zwei compiler for conformity to expected behavior. " -file="tests/four/Factorial.zwei" +file="tests/4/Factorial.zwei" $SEPARATOR echo " @@ -25,7 +25,7 @@ echo "Class typing" $SEPARATOR -file="tests/four/01.zwei" +file="tests/4/01.zwei" echo "Testing file $file : Error in file : undeclared superclass \"b\" (line 1) @@ -35,7 +35,7 @@ $SEPARATOR -file="tests/four/02.zwei" +file="tests/4/02.zwei" echo "Testing file $file : Error in file : class \"a\" already declared (line 3) @@ -51,7 +51,7 @@ echo "Supertypes" $SEPARATOR -file="tests/four/03.zwei" +file="tests/4/03.zwei" echo "Testing file $file : Error in file : illegal call of method \"equal\" : arguments have no common supertype (line 13) @@ -61,7 +61,7 @@ $SEPARATOR -file="tests/four/04.zwei" +file="tests/4/04.zwei" echo "Testing file $file : No error in file : arguments have common supertype @@ -77,7 +77,7 @@ echo "Class typing, courtesy M. Ganguin & J. Ruffin" $SEPARATOR -file="tests/four/class00-1.zwei" +file="tests/4/class00-1.zwei" echo "Testing file $file : Error in file : undeclared superclass \"unknown\" (line 1) @@ -87,7 +87,7 @@ $SEPARATOR -file="tests/four/class00-2.zwei" +file="tests/4/class00-2.zwei" echo "Testing file $file : Error in file : class \"ClassSymbolTest\" already declared (line 3) @@ -97,7 +97,7 @@ $SEPARATOR -file="tests/four/class00-3.zwei" +file="tests/4/class00-3.zwei" echo "Testing file $file : Error in file : type \"RANDOM\" is unknown (class hasn't been declared) (line 3) @@ -107,7 +107,7 @@ $SEPARATOR -file="tests/four/class00-4.zwei" +file="tests/4/class00-4.zwei" echo "Testing file $file : Error in file : undeclared identifier \"NONE\" (line 3) @@ -123,7 +123,7 @@ echo "Field typing, courtesy M. Ganguin & J. Ruffin" $SEPARATOR -file="tests/four/field00-1.zwei" +file="tests/4/field00-1.zwei" echo "Testing file $file : Error in file : type \"UNKNOWN\" is unknown (line 1) @@ -133,7 +133,7 @@ $SEPARATOR -file="tests/four/field00-2.zwei" +file="tests/4/field00-2.zwei" echo "Testing file $file : Recursive typing in classes (no error should be returned) @@ -143,7 +143,7 @@ $SEPARATOR -file="tests/four/field00-3.zwei" +file="tests/4/field00-3.zwei" echo "Testing file $file : Error in file : field \"a\" already declared (line 3) @@ -160,7 +160,7 @@ echo "Method typing, courtesy M. Ganguin & J. Ruffin" $SEPARATOR -file="tests/four/method00-1.zwei" +file="tests/4/method00-1.zwei" echo "Testing file $file : Error in file : return type \"UNKNOWN\" is unknown (line 4) @@ -170,7 +170,7 @@ $SEPARATOR -file="tests/four/method00-2.zwei" +file="tests/4/method00-2.zwei" echo "Testing file $file : Error in file : argument type \"UNKNOWN\" is unknown (line 2) @@ -180,7 +180,7 @@ $SEPARATOR -file="tests/four/method00-3.zwei" +file="tests/4/method00-3.zwei" echo "Testing file $file : Error in file : Overriding method \"overrideTest\" in class \"MethodTest\" has bad return type. (line 14) @@ -190,7 +190,7 @@ $SEPARATOR -file="tests/four/method00-4.zwei" +file="tests/4/method00-4.zwei" echo "Testing file $file : Error in file : Overriding method \"overrideTest\" in class \"MethodTest\" has bad argument type. (line 11) @@ -200,7 +200,7 @@ $SEPARATOR -file="tests/four/method00-5.zwei" +file="tests/4/method00-5.zwei" echo "Testing file $file : Error in file : Method \"returnExpressionTypeTest\" does not return correct type. (line 8) @@ -210,7 +210,7 @@ $SEPARATOR -file="tests/four/method00-6.zwei" +file="tests/4/method00-6.zwei" echo "Testing file $file : Should return no errors : returning container class @@ -220,7 +220,7 @@ $SEPARATOR -file="tests/four/method00-7.zwei" +file="tests/4/method00-7.zwei" echo "Testing file $file : Should return no errors : overriding and polymorphism @@ -230,7 +230,7 @@ $SEPARATOR -file="tests/four/method00-8.zwei" +file="tests/4/method00-8.zwei" echo "Testing file $file : Should return no errors : testing variable scope @@ -240,7 +240,7 @@ $SEPARATOR -file="tests/four/method00-9.zwei" +file="tests/4/method00-9.zwei" echo "Testing file $file : Should return no errors : checking method return types @@ -256,7 +256,7 @@ echo "Program typing, courtesy M. Ganguin & J. Ruffin" $SEPARATOR -file="tests/four/program00-1.zwei" +file="tests/4/program00-1.zwei" echo "Testing file $file : Error in file : type \"RANDOM\" is unknown (line 1) @@ -266,7 +266,7 @@ $SEPARATOR -file="tests/four/program00-2.zwei" +file="tests/4/program00-2.zwei" echo "Testing file $file : Error in file : undeclared identifier \"k\" (line 3) @@ -282,7 +282,7 @@ echo "Statement typing, courtesy M. Ganguin & J. Ruffin" $SEPARATOR -file="tests/four/statement-while.zwei" +file="tests/4/statement-while.zwei" echo "Testing file $file : Errors in file : * type mismatch (expected : Int, found : null) in condition (line 6) @@ -293,7 +293,7 @@ $SEPARATOR -file="tests/four/statement-var.zwei" +file="tests/4/statement-var.zwei" echo "Testing file $file : Errors in file : * type \"nonexistent\" is unknown (line 8) @@ -306,7 +306,7 @@ $SEPARATOR -file="tests/four/statement-set.zwei" +file="tests/4/statement-set.zwei" echo "Testing file $file : Errors in file : * undeclared identifier \"s\" (line 10) @@ -318,7 +318,7 @@ $SEPARATOR -file="tests/four/statement-do.zwei" +file="tests/4/statement-do.zwei" echo "Testing file $file : Errors in file : * type mismatch (expected : Int, found : null) (line 5) @@ -328,7 +328,7 @@ $SEPARATOR -file="tests/four/statement-printInt.zwei" +file="tests/4/statement-printInt.zwei" echo "Testing file $file : Errors in file : * type mismatch (expected : Int, found : foo) (line 7) @@ -338,7 +338,7 @@ $SEPARATOR -file="tests/four/statement-printChar.zwei" +file="tests/4/statement-printChar.zwei" echo "Testing file $file : Errors in file : * type mismatch (expected : Int, found : foo) (line 7) @@ -354,7 +354,7 @@ echo "Term typing, courtesy M. Ganguin & J. Ruffin" $SEPARATOR -file="tests/four/term-ident.zwei" +file="tests/4/term-ident.zwei" echo "Testing file $file : Error in file : undeclared identifier \"y\" (line 6) @@ -364,7 +364,7 @@ $SEPARATOR -file="tests/four/term-select.zwei" +file="tests/4/term-select.zwei" echo "Testing file $file : Errors in file : * undeclared identifier \"k\" (line 16) @@ -375,7 +375,7 @@ $SEPARATOR -file="tests/four/term-call.zwei" +file="tests/4/term-call.zwei" echo "Testing file $file : Errors in file : * undeclared identifier \"k\" (line 20) @@ -388,7 +388,7 @@ $SEPARATOR -file="tests/four/term-new.zwei" +file="tests/4/term-new.zwei" echo "Testing file $file : Errors in file : * undeclared class \"unknown\" (line 17) @@ -400,7 +400,7 @@ $SEPARATOR -file="tests/four/term-unop.zwei" +file="tests/4/term-unop.zwei" echo "Testing file $file : Errors in file : * undeclared identifier \"y\" (line 6) @@ -411,7 +411,7 @@ $SEPARATOR -file="tests/four/term-binop.zwei" +file="tests/4/term-binop.zwei" echo "Testing file $file : Errors in file : * undeclared identifier \"k\" (line 7) @@ -424,7 +424,7 @@ $SEPARATOR -file="tests/four/term-objComp.zwei" +file="tests/4/term-objComp.zwei" echo "Testing file $file : Errors in file : * two type mismatches (neither opr�rand is an Int) (line 18) @@ -438,7 +438,7 @@ $SEPARATOR -file="tests/four/term-if.zwei" +file="tests/4/term-if.zwei" echo "Testing file $file : Errors in file : * undeclared identifier \"k\" (line 21) @@ -453,7 +453,7 @@ $SEPARATOR -file="tests/four/term-block.zwei" +file="tests/4/term-block.zwei" echo "Testing file $file : Errors in file : * type mismatch (expected return type : Int, found : null) (line 24) @@ -470,7 +470,7 @@ echo "Various test files, courtesy R. Tagliani" $SEPARATOR -file="tests/four/bionInt.zwei" +file="tests/4/bionInt.zwei" echo "Testing file $file : No errors in file @@ -480,91 +480,91 @@ $SEPARATOR -file="tests/four/blockvar.zwei" +file="tests/4/blockvar.zwei" echo "Testing file $file : No errors in file " -file="tests/four/classes.zwei" +file="tests/4/classes.zwei" echo "Testing file $file : No errors in file " -file="tests/four/classes0.zwei" +file="tests/4/classes0.zwei" echo "Testing file $file : No errors in file " -file="tests/four/expr_if.zwei" +file="tests/4/expr_if.zwei" echo "Testing file $file : No errors in file " -file="tests/four/expr_readChar.zwei" +file="tests/4/expr_readChar.zwei" echo "Testing file $file : No errors in file " -file="tests/four/expr_readInt.zwei" +file="tests/4/expr_readInt.zwei" echo "Testing file $file : No errors in file " -file="tests/four/functions.zwei" +file="tests/4/functions.zwei" echo "Testing file $file : No errors in file " -file="tests/four/new.zwei" +file="tests/4/new.zwei" echo "Testing file $file : No errors in file " -file="tests/four/null.zwei" +file="tests/4/null.zwei" echo "Testing file $file : No errors in file " -file="tests/four/printChar.zwei" +file="tests/4/printChar.zwei" echo "Testing file $file : No errors in file " -file="tests/four/printInt.zwei" +file="tests/4/printInt.zwei" echo "Testing file $file : No errors in file " -file="tests/four/select.zwei" +file="tests/4/select.zwei" echo "Testing file $file : No errors in file " -file="tests/four/unop.zwei" +file="tests/4/unop.zwei" echo "Testing file $file : No errors in file " -file="tests/four/unopa.zwei" +file="tests/4/unopa.zwei" echo "Testing file $file : No errors in file " -file="tests/four/blockvar_2xerror0.zwei" +file="tests/4/blockvar_2xerror0.zwei" echo "Testing file $file : Errors in file : * undeclared identifier \"y\" (line 3) @@ -575,7 +575,7 @@ $SEPARATOR -file="tests/four/blockvar_error0.zwei" +file="tests/4/blockvar_error0.zwei" echo "Testing file $file : Errors in file : * undeclared identifier \"z\" (line 3) @@ -585,7 +585,7 @@ $SEPARATOR -file="tests/four/blockvar_error1.zwei" +file="tests/4/blockvar_error1.zwei" echo "Testing file $file : Errors in file : * variable \"x\" already declared (line 3) @@ -595,7 +595,7 @@ $SEPARATOR -file="tests/four/classes_error0.zwei" +file="tests/4/classes_error0.zwei" echo "Testing file $file : Errors in file : * class \"C1\" already declared (line 2) @@ -605,7 +605,7 @@ $SEPARATOR -file="tests/four/classes_error1.zwei" +file="tests/4/classes_error1.zwei" echo "Testing file $file : Errors in file : * undeclared superclass \"C1\" (line 2) @@ -615,7 +615,7 @@ $SEPARATOR -file="tests/four/classes_error2.zwei" +file="tests/4/classes_error2.zwei" echo "Testing file $file : Errors in file : * field \"a\" already declared (line 3) @@ -625,7 +625,7 @@ $SEPARATOR -file="tests/four/functions_error0.zwei" +file="tests/4/functions_error0.zwei" echo "Testing file $file : Errors in file : * method \"f1\" does not return correct type (line 2) @@ -635,7 +635,7 @@ $SEPARATOR -file="tests/four/functions_error1.zwei" +file="tests/4/functions_error1.zwei" echo "Testing file $file : Errors in file : * method \"f2\" does not return correct type (line 3) @@ -645,7 +645,7 @@ $SEPARATOR -file="tests/four/new_error0.zwei" +file="tests/4/new_error0.zwei" echo "Testing file $file : Errors in file : * illegal use of class constructor : argument types do not match (line 6) @@ -655,7 +655,7 @@ $SEPARATOR -file="tests/four/new_error0.zwei" +file="tests/4/new_error0.zwei" echo "Testing file $file : Errors in file : * illegal use of class constructor : wrong number of parameters (line 6) @@ -665,7 +665,7 @@ $SEPARATOR -file="tests/four/printChar_error0.zwei" +file="tests/4/printChar_error0.zwei" echo "Testing file $file : Errors in file : * program starts with block (line 0) @@ -675,7 +675,7 @@ $SEPARATOR -file="tests/four/unopa_error1.zwei" +file="tests/4/unopa_error1.zwei" echo "Testing file $file : Errors in file : * undeclared identifier \"b\" (line 3) diff --git a/sources/zweic/Parser.scala b/sources/zweic/Parser.scala index 6ac090e..815a29d 100755 --- a/sources/zweic/Parser.scala +++ b/sources/zweic/Parser.scala @@ -142,7 +142,7 @@ val pos = start; val f:Formal = formal(); if (check(SEMICOLON)) { - return FieldDecl(f); + return FieldDecl(f).setPos(pos); } else { accept(LPAREN); var par:List[Formal] = Nil; @@ -163,8 +163,8 @@ * Formal = Type ident */ private def formal(): Formal = { - val pos = start; val typ = type1(); + val pos = start; val name = Name(chars); accept(IDENT); return Formal(name, typ).setPos(pos); diff --git a/sources/zweic/Report.scala b/sources/zweic/Report.scala index 895769d..ce4f05b 100755 --- a/sources/zweic/Report.scala +++ b/sources/zweic/Report.scala @@ -45,7 +45,7 @@ } /** Imprime la position et le message passés en argument. */ - private def print(pos: Int, message: String): Unit = + def print(pos: Int, message: String): Unit = System.err.println(Position.toString(pos) + ": " + message); } diff --git a/sources/zweic/Scanner.scala b/sources/zweic/Scanner.scala index 287f50a..298ac39 100755 --- a/sources/zweic/Scanner.scala +++ b/sources/zweic/Scanner.scala @@ -111,7 +111,7 @@ } } else { // division - start = Position.encode(line, column); + start = Position.encode(line, column-1); token = DIV; return } @@ -121,7 +121,7 @@ } } - start = Position.encode(line, column); + start = Position.encode(line, column-1); // read the current token token = readToken; }