diff --git a/MiniC/Makefile b/MiniC/Makefile index ee9b977..938d23e 100644 --- a/MiniC/Makefile +++ b/MiniC/Makefile @@ -1,4 +1,4 @@ -MYNAME = JohnDoe +MYNAME = SamyAvrillon PACKAGE = MiniC # Example: stop at the first failed test: # make PYTEST_OPTS=-x test diff --git a/MiniC/MiniC.g4 b/MiniC/MiniC.g4 index a1dad31..6592018 100644 --- a/MiniC/MiniC.g4 +++ b/MiniC/MiniC.g4 @@ -24,7 +24,8 @@ stat : assignment SCOL | if_stat | while_stat - | print_stat + | print_stat + | for_stat ; assignment: ID ASSIGN expr #assignStat; @@ -39,6 +40,7 @@ stat_block while_stat: WHILE OPAR expr CPAR body=stat_block #whileStat; +for_stat: FOR OPAR (init_stat=assignment)? SCOL (cond=expr)? SCOL (loop_stat=assignment)? CPAR stat_block #forStat; print_stat : PRINTLN_INT OPAR expr CPAR SCOL #printlnintStat @@ -101,6 +103,7 @@ FALSE : 'false'; IF : 'if'; ELSE : 'else'; WHILE : 'while'; +FOR : 'for'; RETURN : 'return'; PRINTLN_INT : 'println_int'; PRINTLN_BOOL : 'println_bool'; diff --git a/MiniC/README-interpreter.md b/MiniC/README-interpreter.md index cf39f47..21e036c 100644 --- a/MiniC/README-interpreter.md +++ b/MiniC/README-interpreter.md @@ -4,11 +4,14 @@ LAB3, MIF08 / CAP 2022-23 # Authors -TODO: YOUR NAME HERE +Samy Avrillon +Mostly you for the # Contents -TODO for STUDENTS : Say a bit about the code infrastructure ... +Well ... You did the code infrastructure, so i have no interest in telling that it is bad. So ... Great infrastructure ! + +I think this part is for future work on MiniC, so i will not answer it (seriously). # Howto @@ -21,12 +24,25 @@ You can select the files you want to test by using `make test TEST_FILES='TP03/* # Test design -TODO: explain your tests. Do not repeat what test files already contain, just give the main objectives of the tests. +- «corrected» folder corresponds to the tests that i have changed from the base set (see Desing Choices below) +- «typeErrors» folder corresponds to tests of the error messages when using an operator/structure. Each *part* of the operator/structure is checked independently so we know for sure where the error comes from. +- ifClauseSyntax and whileClauseSyntax test the syntax of if and while clauses. +- floatDiv0, floatMod0, intDiv0 et intMod0 tests «Division by 0» errors. +- multidecl.c test multi-variables declarations. +- testOps.c test float and int arithmetics. +- forTests.c tests the execution of the for (C-like) loops. # Design choices -TODO: explain your choices - explain the limitations of your implementation. +We will consider that when using an operator on two types with one of them illegal (for example, trying to multiply an int and a string), an error of type «type mismatch» will be raised instead of an «invalid type» one. This allows to check type equality before type validity. + +The protocol to choosing an error message is as follows: +- If the operator requires its arguments to be of the same type, the first check is equality of the types of the operands. In case of error, an error of type «type mismatch» is raised with the types of the operands. +- If this check passed, the first argument type is checked, and if it is invalid, an error of type «invalid type» is raised **with only one type** +- If the operator can take arguments of different types, each type is checked, and in case of error, an error of type «invalid type» is raised with **type for each argument**. + +In order to follow this protocol, two tests have been rewritten (and moved to the «student» directory): bad_type01.c and bad_type_bool_bool.c # Known bugs -TODO: document any known bug and limitations. Did you do everything asked for? Did you implement an extension? +I think i did everything i was asked, and did not notice any bug. diff --git a/MiniC/TP03/MiniCInterpretVisitor.py b/MiniC/TP03/MiniCInterpretVisitor.py index 49d10c3..ca76455 100644 --- a/MiniC/TP03/MiniCInterpretVisitor.py +++ b/MiniC/TP03/MiniCInterpretVisitor.py @@ -19,11 +19,24 @@ class MiniCInterpretVisitor(MiniCVisitor): def visitVarDecl(self, ctx) -> None: # Initialise all variables in self._memory - type_str = ctx.typee().getText() - raise NotImplementedError() + typee = ctx.typee().getText() + names = self.visit(ctx.id_l()) + val = 42 + if(typee == "int"): + val = 0 + elif(typee == "string"): + val = "" + elif(typee == "bool"): + val = False + elif(typee == "float"): + val = 0.0 + for name in names: + self._memory[name] = val def visitIdList(self, ctx) -> List[str]: - raise NotImplementedError() + l = self.visit(ctx.id_l()) + l.append(ctx.ID().getText()) + return l def visitIdListBase(self, ctx) -> List[str]: return [ctx.ID().getText()] @@ -43,7 +56,7 @@ class MiniCInterpretVisitor(MiniCVisitor): return ctx.getText() == "true" def visitIdAtom(self, ctx) -> MINIC_VALUE: - raise NotImplementedError() + return self._memory[ctx.getText()] def visitStringAtom(self, ctx) -> str: return ctx.getText()[1:-1] # Remove the "" @@ -119,8 +132,9 @@ class MiniCInterpretVisitor(MiniCVisitor): else: return lval / rval elif ctx.myop.type == MiniCParser.MOD: - # TODO : interpret modulo - raise NotImplementedError() + if rval == 0: + raise MiniCRuntimeError("Division by 0") + return lval % rval else: raise MiniCInternalError( "Unknown multiplicative operator '%s'" % ctx.myop) @@ -152,13 +166,36 @@ class MiniCInterpretVisitor(MiniCVisitor): print(val) def visitAssignStat(self, ctx) -> None: - raise NotImplementedError() + name = ctx.ID().getText() + val = self.visit(ctx.expr()) + self._memory[name] = val def visitIfStat(self, ctx) -> None: - raise NotImplementedError() + condval = self.visit(ctx.expr()) + if(condval==True): + self.visit(ctx.then_block) + else: + if(ctx.else_block != None): + self.visit(ctx.else_block) def visitWhileStat(self, ctx) -> None: - raise NotImplementedError() + condexpr = ctx.expr() + inexpr = ctx.body + while(self.visit(condexpr)==True): + self.visit(inexpr) + + def visitForStat(self, ctx): + init_stat = ctx.init_stat + cond = ctx.cond + loop_stat = ctx.loop_stat + body = ctx.stat_block() + + if(init_stat != None): + self.visit(init_stat) + while(True if cond==None else self.visit(cond)): + self.visit(body) + if(loop_stat != None): + self.visit(loop_stat) # TOPLEVEL def visitProgRule(self, ctx) -> None: diff --git a/MiniC/TP03/MiniCTypingVisitor.py b/MiniC/TP03/MiniCTypingVisitor.py index f9b29f5..a750cc2 100644 --- a/MiniC/TP03/MiniCTypingVisitor.py +++ b/MiniC/TP03/MiniCTypingVisitor.py @@ -43,7 +43,12 @@ class MiniCTypingVisitor(MiniCVisitor): # type declaration def visitVarDecl(self, ctx) -> None: - raise NotImplementedError() + ttype = self.visit(ctx.typee()) + ids = self.visit(ctx.id_l()) + for i in ids: + if i in self._memorytypes: + self._raiseNonType(ctx,"Variable {} already declared".format(i)) + self._memorytypes[i] = ttype def visitBasicType(self, ctx): assert ctx.mytype is not None @@ -51,14 +56,20 @@ class MiniCTypingVisitor(MiniCVisitor): return BaseType.Integer elif ctx.mytype.type == MiniCParser.FLOATTYPE: return BaseType.Float - else: # TODO: same for other types - raise NotImplementedError() + if ctx.mytype.type == MiniCParser.STRINGTYPE: + return BaseType.String + elif ctx.mytype.type == MiniCParser.BOOLTYPE: + return BaseType.Boolean + else: + raise MiniCInternalError("Unknown type '%s'" % ctx.mytype) def visitIdList(self, ctx) -> List[str]: - raise NotImplementedError() + l = self.visit(ctx.id_l()) + l.append(ctx.ID().getText()) + return l def visitIdListBase(self, ctx) -> List[str]: - raise NotImplementedError() + return [ctx.ID().getText()] # typing visitors for expressions, statements ! @@ -73,7 +84,7 @@ class MiniCTypingVisitor(MiniCVisitor): return BaseType.Float def visitBooleanAtom(self, ctx): - raise NotImplementedError() + return BaseType.Boolean def visitIdAtom(self, ctx): try: @@ -91,29 +102,84 @@ class MiniCTypingVisitor(MiniCVisitor): return self.visit(ctx.atom()) def visitOrExpr(self, ctx): - raise NotImplementedError() + fstT = self.visit(ctx.expr(0)) + sndT = self.visit(ctx.expr(1)) + if(fstT == sndT): + if(fstT == BaseType.Boolean): + return BaseType.Boolean + else: + self._raise(ctx,"boolean operator", fstT) + else: + self._assertSameType(ctx,"boolean operator", fstT,sndT) def visitAndExpr(self, ctx): - raise NotImplementedError() + fstT = self.visit(ctx.expr(0)) + sndT = self.visit(ctx.expr(1)) + if(fstT == sndT): + if(fstT == BaseType.Boolean): + return BaseType.Boolean + else: + self._raise(ctx,"boolean operator", fstT) + else: + self._assertSameType(ctx,"boolean operator", fstT,sndT) def visitEqualityExpr(self, ctx): - raise NotImplementedError() + fstT = self.visit(ctx.expr(0)) + sndT = self.visit(ctx.expr(1)) + if(fstT == sndT): + return BaseType.Boolean + else: + self._assertSameType(ctx,"equality operator", fstT,sndT) def visitRelationalExpr(self, ctx): - raise NotImplementedError() + fstT = self.visit(ctx.expr(0)) + sndT = self.visit(ctx.expr(1)) + if(fstT == sndT): + if(fstT in [BaseType.Float, BaseType.Integer]): + return BaseType.Boolean + else: + self._raise(ctx, "comparaison operator", fstT) + else: + self._assertSameType(ctx,"comparaison operator", fstT,sndT) def visitAdditiveExpr(self, ctx): assert ctx.myop is not None - raise NotImplementedError() + fstT = self.visit(ctx.expr(0)) + sndT = self.visit(ctx.expr(1)) + if(fstT == sndT): + if(fstT in [BaseType.Float, BaseType.Integer]): + return fstT + elif (fstT == BaseType.String and ctx.myop.type == MiniCParser.PLUS): + return BaseType.String + else: + self._raise(ctx, "additive operands", fstT) + else: + self._assertSameType(ctx,"additive operator", fstT,sndT) def visitMultiplicativeExpr(self, ctx): - raise NotImplementedError() + fstT = self.visit(ctx.expr(0)) + sndT = self.visit(ctx.expr(1)) + if(fstT == sndT): + if(not fstT in [BaseType.Float, BaseType.Integer]): + self._raise(ctx, "multiplicative operands", fstT) + else: + return fstT + else: + self._assertSameType(ctx,"multiplicative operator", fstT,sndT) def visitNotExpr(self, ctx): - raise NotImplementedError() + fstT = self.visit(ctx.expr()) + if(fstT == BaseType.Boolean): + return BaseType.Boolean + else: + self._raise(ctx,"not operator", fstT) def visitUnaryMinusExpr(self, ctx): - raise NotImplementedError() + fstT = self.visit(ctx.expr()) + if(fstT in [BaseType.Integer,BaseType.Float]): + return fstT + else: + self._raise(ctx,"minus operator", fstT) # visit statements @@ -130,7 +196,7 @@ class MiniCTypingVisitor(MiniCVisitor): def visitPrintlnboolStat(self, ctx): etype = self.visit(ctx.expr()) if etype != BaseType.Boolean: - self._raise(ctx, 'println_int statement', etype) + self._raise(ctx, 'println_bool statement', etype) def visitPrintlnstringStat(self, ctx): etype = self.visit(ctx.expr()) @@ -138,10 +204,35 @@ class MiniCTypingVisitor(MiniCVisitor): self._raise(ctx, 'println_string statement', etype) def visitAssignStat(self, ctx): - raise NotImplementedError() + theid = ctx.ID().getText() + ttyp = self.visit(ctx.expr()) + if(not theid in self._memorytypes): + self._raiseNonType(ctx,"Undefined variable {}".format(theid)) + if(self._memorytypes[theid] != ttyp): + self._assertSameType(ctx,theid, self._memorytypes[theid],ttyp) def visitWhileStat(self, ctx): - raise NotImplementedError() + cond = self.visit(ctx.expr()) + if(cond != BaseType.Boolean): + self._raise(ctx, "while condition", cond) + self.visit(ctx.body) def visitIfStat(self, ctx): - raise NotImplementedError() + cond = self.visit(ctx.expr()) + if(cond != BaseType.Boolean): + self._raise(ctx, "if condition", cond) + self.visit(ctx.then_block) + if(ctx.else_block != None): + self.visit(ctx.else_block) + + def visitForStat(self, ctx): + if(ctx.init_stat != None): + self.visit(ctx.init_stat) + if(ctx.cond != None): + cond = self.visit(ctx.cond) + if(cond != BaseType.Boolean): + self._raise(ctx, "for condition", cond) + if(ctx.loop_stat != None): + self.visit(ctx.loop_stat) + + self.visit(ctx.stat_block()) diff --git a/MiniC/TP03/tests/provided/examples-types/bad_type01.c b/MiniC/TP03/tests/students/corrected/bad_type01.c similarity index 57% rename from MiniC/TP03/tests/provided/examples-types/bad_type01.c rename to MiniC/TP03/tests/students/corrected/bad_type01.c index 1a84239..39f8e7c 100644 --- a/MiniC/TP03/tests/provided/examples-types/bad_type01.c +++ b/MiniC/TP03/tests/students/corrected/bad_type01.c @@ -11,4 +11,4 @@ int main(){ // EXITCODE 2 // EXPECTED -// In function main: Line 8 col 6: invalid type for multiplicative operands: integer and string +// In function main: Line 8 col 6: type mismatch for multiplicative operator: integer and string diff --git a/MiniC/TP03/tests/provided/examples-types/bad_type_bool_bool.c b/MiniC/TP03/tests/students/corrected/bad_type_bool_bool.c similarity index 85% rename from MiniC/TP03/tests/provided/examples-types/bad_type_bool_bool.c rename to MiniC/TP03/tests/students/corrected/bad_type_bool_bool.c index be2d14e..e5f3981 100644 --- a/MiniC/TP03/tests/provided/examples-types/bad_type_bool_bool.c +++ b/MiniC/TP03/tests/students/corrected/bad_type_bool_bool.c @@ -6,4 +6,4 @@ int main(){ } // EXITCODE 2 // EXPECTED -// In function main: Line 4 col 14: invalid type for additive operands: boolean and boolean +// In function main: Line 4 col 14: invalid type for additive operands: boolean diff --git a/MiniC/TP03/tests/students/floatDiv0.c b/MiniC/TP03/tests/students/floatDiv0.c new file mode 100644 index 0000000..b1b4f2f --- /dev/null +++ b/MiniC/TP03/tests/students/floatDiv0.c @@ -0,0 +1,16 @@ +#include "printlib.h" + +int main(){ + float x,y,z; + + x = 42.0; + y = 0.0; + z = x/y; + println_float(z); + + return 0; +} + +// EXPECTED +// EXITCODE 1 +// Division by 0 diff --git a/MiniC/TP03/tests/students/floatMod0.c b/MiniC/TP03/tests/students/floatMod0.c new file mode 100644 index 0000000..b14e96c --- /dev/null +++ b/MiniC/TP03/tests/students/floatMod0.c @@ -0,0 +1,16 @@ +#include "printlib.h" + +int main(){ + float x,y,z; + + x = 42.0; + y = 0.0; + z = x%y; + println_float(z); + + return 0; +} + +// EXPECTED +// EXITCODE 1 +// Division by 0 diff --git a/MiniC/TP03/tests/students/forTests.c b/MiniC/TP03/tests/students/forTests.c new file mode 100644 index 0000000..e05c472 --- /dev/null +++ b/MiniC/TP03/tests/students/forTests.c @@ -0,0 +1,32 @@ +#include "printlib.h" + +int main(){ + int x; + + x = 0; + for(;x<4;){ + println_int(x); + x = x+1; + } + x = 69; + for(x=42;false;){ + } + println_int(x); + for(x = 100;x>=4;x = x/2){ + println_int(x+4); + } + return 0; +} + +// EXITCODE 0 +// EXPECTED +// 0 +// 1 +// 2 +// 3 +// 42 +// 104 +// 54 +// 29 +// 16 +// 10 diff --git a/MiniC/TP03/tests/students/ifClauseSyntax.c b/MiniC/TP03/tests/students/ifClauseSyntax.c new file mode 100644 index 0000000..4160d22 --- /dev/null +++ b/MiniC/TP03/tests/students/ifClauseSyntax.c @@ -0,0 +1,34 @@ +#include "printlib.h" + +int main(){ + int x,y,z; + + x = 0; + y = 0; + + if(x==1) + println_string("pif"); + else{ + println_string("paf"); + } + if(y==0){ + println_string("paf"); + }else + println_string("pif"); + if(x!=y){ + println_string("pif"); + }else{ + println_string("paf"); + } + if(0==0) + println_string("paf"); + else + println_string("pif"); + return 0; +} + +// EXPECTED +// paf +// paf +// paf +// paf diff --git a/MiniC/TP03/tests/students/intDiv0.c b/MiniC/TP03/tests/students/intDiv0.c new file mode 100644 index 0000000..714fbcb --- /dev/null +++ b/MiniC/TP03/tests/students/intDiv0.c @@ -0,0 +1,16 @@ +#include "printlib.h" + +int main(){ + int x,y,z; + + x = 42; + y = 0; + z = x/y; + println_int(z); + + return 0; +} + +// EXITCODE 1 +// EXPECTED +// Division by 0 diff --git a/MiniC/TP03/tests/students/intMod0.c b/MiniC/TP03/tests/students/intMod0.c new file mode 100644 index 0000000..9522ea5 --- /dev/null +++ b/MiniC/TP03/tests/students/intMod0.c @@ -0,0 +1,16 @@ +#include "printlib.h" + +int main(){ + int x,y,z; + + x = 42; + y = 0; + z = x%y; + println_int(z); + + return 0; +} + +// EXITCODE 1 +// EXPECTED +// Division by 0 diff --git a/MiniC/TP03/tests/students/multidecl.c b/MiniC/TP03/tests/students/multidecl.c new file mode 100644 index 0000000..2a6616e --- /dev/null +++ b/MiniC/TP03/tests/students/multidecl.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x,y,z,a,b,c; + string s,d; + float v,u,k,n; + bool t,w,p; + + println_int(x); + return 0; +} + +// EXPECTED +// 0 diff --git a/MiniC/TP03/tests/students/testOps.c b/MiniC/TP03/tests/students/testOps.c new file mode 100644 index 0000000..6d03b71 --- /dev/null +++ b/MiniC/TP03/tests/students/testOps.c @@ -0,0 +1,40 @@ +#include "printlib.h" + +int main(){ + int x,y,z; + float a,b,c; + + x = 42; + y = 69; + a = 42.0; + b = 69.0; + z = y-x; + println_int(z); + c = b-a; + println_float(c); + y = 690; + z = y/x; + println_int(z); + c = a/12.0; + println_float(c); + z = y % x; + println_int(z); + c = b % a; + println_float(c); + z = -x; + println_int(z); + c = -b; + println_float(c); + + return 0; +} + +// EXPECTED +// 27 +// 27.00 +// 16 +// 3.50 +// 18 +// 27.00 +// -42 +// -69.00 diff --git a/MiniC/TP03/tests/students/typeErrors/elseContentCheck.c b/MiniC/TP03/tests/students/typeErrors/elseContentCheck.c new file mode 100644 index 0000000..bd08abc --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/elseContentCheck.c @@ -0,0 +1,17 @@ +#include "printlib.h" + +int main(){ + int x; + + if (true) { + x = 42; + } else { + x = true; + } + + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 9 col 8: type mismatch for x: integer and boolean diff --git a/MiniC/TP03/tests/students/typeErrors/forBodyTyping.c b/MiniC/TP03/tests/students/typeErrors/forBodyTyping.c new file mode 100644 index 0000000..1e91760 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/forBodyTyping.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x; + + for(x = 0;x<10;x = x+1){ + println_int(false); + } + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 7 col 8: invalid type for println_int statement: boolean diff --git a/MiniC/TP03/tests/students/typeErrors/forCondTyping.c b/MiniC/TP03/tests/students/typeErrors/forCondTyping.c new file mode 100644 index 0000000..c017eb1 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/forCondTyping.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x; + + for(x = 0;x+10;x = x+1){ + println_int(x); + } + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 6 col 4: invalid type for for condition: integer diff --git a/MiniC/TP03/tests/students/typeErrors/forInitTyping.c b/MiniC/TP03/tests/students/typeErrors/forInitTyping.c new file mode 100644 index 0000000..6ce6769 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/forInitTyping.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x; + + for(x = 0 + false;x<10;x = x+1){ + println_int(x); + } + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 6 col 12: type mismatch for additive operator: integer and boolean diff --git a/MiniC/TP03/tests/students/typeErrors/forLoopTyping.c b/MiniC/TP03/tests/students/typeErrors/forLoopTyping.c new file mode 100644 index 0000000..2bbb152 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/forLoopTyping.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x; + + for(x = 0;x<10;x = false){ + println_int(x); + } + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 6 col 19: type mismatch for x: integer and boolean diff --git a/MiniC/TP03/tests/students/typeErrors/ifContentCheck.c b/MiniC/TP03/tests/students/typeErrors/ifContentCheck.c new file mode 100644 index 0000000..f07fddd --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/ifContentCheck.c @@ -0,0 +1,17 @@ +#include "printlib.h" + +int main(){ + int x; + + if (true) { + x = true; + }else { + x = 42; + } + + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 7 col 8: type mismatch for x: integer and boolean diff --git a/MiniC/TP03/tests/students/typeErrors/ifType.c b/MiniC/TP03/tests/students/typeErrors/ifType.c new file mode 100644 index 0000000..0fa6508 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/ifType.c @@ -0,0 +1,21 @@ +#include "printlib.h" + +int main(){ + int x; + bool a; + + if (a) { + + } + if (true) { + + } + if (x) { + + } + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 13 col 4: invalid type for if condition: integer diff --git a/MiniC/TP03/tests/students/typeErrors/invalidAdd.c b/MiniC/TP03/tests/students/typeErrors/invalidAdd.c new file mode 100644 index 0000000..13f78f6 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidAdd.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x,y; + bool a,b; + + x = x + y; + x = a - b; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 8: invalid type for additive operands: boolean diff --git a/MiniC/TP03/tests/students/typeErrors/invalidAnd.c b/MiniC/TP03/tests/students/typeErrors/invalidAnd.c new file mode 100644 index 0000000..e98ff94 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidAnd.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x,y; + bool a,b; + + a = a && b; + a = x && y; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 8: invalid type for boolean operator: integer diff --git a/MiniC/TP03/tests/students/typeErrors/invalidComp.c b/MiniC/TP03/tests/students/typeErrors/invalidComp.c new file mode 100644 index 0000000..dc1ad30 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidComp.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x,y; + bool a,b; + + a = x < y; + x = a > b; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 8: invalid type for comparaison operator: boolean diff --git a/MiniC/TP03/tests/students/typeErrors/invalidMinus.c b/MiniC/TP03/tests/students/typeErrors/invalidMinus.c new file mode 100644 index 0000000..e0c6bc1 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidMinus.c @@ -0,0 +1,16 @@ +#include "printlib.h" + +int main(){ + int x,y; + float z,t; + bool a,b; + + x = -y; + z = -t; + a = -b; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 10 col 8: invalid type for minus operator: boolean diff --git a/MiniC/TP03/tests/students/typeErrors/invalidMult.c b/MiniC/TP03/tests/students/typeErrors/invalidMult.c new file mode 100644 index 0000000..ef8e7b4 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidMult.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x,y; + bool a,b; + + x = x * y; + x = a * b; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 8: invalid type for multiplicative operands: boolean diff --git a/MiniC/TP03/tests/students/typeErrors/invalidNot.c b/MiniC/TP03/tests/students/typeErrors/invalidNot.c new file mode 100644 index 0000000..8652300 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidNot.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int y; + bool a,b; + + a = !b; + a = !y; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 8: invalid type for not operator: integer diff --git a/MiniC/TP03/tests/students/typeErrors/invalidOr.c b/MiniC/TP03/tests/students/typeErrors/invalidOr.c new file mode 100644 index 0000000..906d9c5 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidOr.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x,y; + bool a,b; + + a = a || b; + a = x || y; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 8: invalid type for boolean operator: integer diff --git a/MiniC/TP03/tests/students/typeErrors/invalidPrintBool.c b/MiniC/TP03/tests/students/typeErrors/invalidPrintBool.c new file mode 100644 index 0000000..8c01e37 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidPrintBool.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + bool x; + string a; + + println_bool(x); + println_bool(a); + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 4: invalid type for println_bool statement: string diff --git a/MiniC/TP03/tests/students/typeErrors/invalidPrintFloat.c b/MiniC/TP03/tests/students/typeErrors/invalidPrintFloat.c new file mode 100644 index 0000000..f5a2aea --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidPrintFloat.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + float x; + string a; + + println_float(x); + println_float(a); + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 4: invalid type for println_float statement: string diff --git a/MiniC/TP03/tests/students/typeErrors/invalidPrintInt.c b/MiniC/TP03/tests/students/typeErrors/invalidPrintInt.c new file mode 100644 index 0000000..d97ff96 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidPrintInt.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x; + string a; + + println_int(x); + println_int(a); + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 4: invalid type for println_int statement: string diff --git a/MiniC/TP03/tests/students/typeErrors/invalidPrintString.c b/MiniC/TP03/tests/students/typeErrors/invalidPrintString.c new file mode 100644 index 0000000..05dc511 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/invalidPrintString.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + string x; + bool a; + + println_string(x); + println_string(a); + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 4: invalid type for println_string statement: boolean diff --git a/MiniC/TP03/tests/students/typeErrors/mismatchAdd.c b/MiniC/TP03/tests/students/typeErrors/mismatchAdd.c new file mode 100644 index 0000000..ea7fd8b --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/mismatchAdd.c @@ -0,0 +1,16 @@ +#include "printlib.h" + +int main(){ + int x,y; + float z,t; + bool a,b; + + x = x + y; + z = z - t; + a = x + t; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 10 col 8: type mismatch for additive operator: integer and float diff --git a/MiniC/TP03/tests/students/typeErrors/mismatchAnd.c b/MiniC/TP03/tests/students/typeErrors/mismatchAnd.c new file mode 100644 index 0000000..972e09e --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/mismatchAnd.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x; + bool a,b; + + a = a && b; + a = x && b; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 8: type mismatch for boolean operator: integer and boolean diff --git a/MiniC/TP03/tests/students/typeErrors/mismatchComp.c b/MiniC/TP03/tests/students/typeErrors/mismatchComp.c new file mode 100644 index 0000000..a4f962a --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/mismatchComp.c @@ -0,0 +1,22 @@ +#include "printlib.h" + +int main(){ + int x,y; + float z,t; + bool a,b; + + a = x < y; + a = x <= y; + b = x > y; + a = x >= y; + a = z > t; + b = z >= t; + a = z < t; + a = z <= t; + b = x <= t; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 16 col 8: type mismatch for comparaison operator: integer and float diff --git a/MiniC/TP03/tests/students/typeErrors/mismatchEq.c b/MiniC/TP03/tests/students/typeErrors/mismatchEq.c new file mode 100644 index 0000000..d4663cb --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/mismatchEq.c @@ -0,0 +1,20 @@ +#include "printlib.h" + +int main(){ + int x,y; + float z,t; + string s,v; + bool a,b; + bool c; + + c = (x==y); + c = (z!=t); + c = (s==v); + c = (a!=b); + c = (t==y); + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 14 col 9: type mismatch for equality operator: float and integer diff --git a/MiniC/TP03/tests/students/typeErrors/mismatchMult.c b/MiniC/TP03/tests/students/typeErrors/mismatchMult.c new file mode 100644 index 0000000..c04780e --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/mismatchMult.c @@ -0,0 +1,16 @@ +#include "printlib.h" + +int main(){ + int x,y; + float z,t; + bool a,b; + + x = x * y; + z = z * t; + a = x * t; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 10 col 8: type mismatch for multiplicative operator: integer and float diff --git a/MiniC/TP03/tests/students/typeErrors/mismatchOr.c b/MiniC/TP03/tests/students/typeErrors/mismatchOr.c new file mode 100644 index 0000000..37a3891 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/mismatchOr.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main(){ + int x; + bool a,b; + + a = a || b; + a = x || b; + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 8: type mismatch for boolean operator: integer and boolean diff --git a/MiniC/TP03/tests/students/typeErrors/whileType.c b/MiniC/TP03/tests/students/typeErrors/whileType.c new file mode 100644 index 0000000..0444d22 --- /dev/null +++ b/MiniC/TP03/tests/students/typeErrors/whileType.c @@ -0,0 +1,21 @@ +#include "printlib.h" + +int main(){ + int x; + bool a; + + while (a) { + + } + while (false) { + + } + while (x) { + + } + return 0; +} + +// EXITCODE 2 +// EXPECTED +// In function main: Line 13 col 4: invalid type for while condition: integer diff --git a/MiniC/TP03/tests/students/whileClauseSyntax.c b/MiniC/TP03/tests/students/whileClauseSyntax.c new file mode 100644 index 0000000..e4a5a15 --- /dev/null +++ b/MiniC/TP03/tests/students/whileClauseSyntax.c @@ -0,0 +1,22 @@ +#include "printlib.h" + +int main(){ + int x,y,z; + + x = 42; + y = 0; + while(y skip ; // skip spaces, tabs, newlines +OPENP : '('; +ENDP : ')';