diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3cc4b0b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +**/.venv +**/*.interp +**/*.tokens +**/__pycache__ diff --git a/MiniC/MiniC.g4 b/MiniC/MiniC.g4 index 0fb24e9..dad84c1 100644 --- a/MiniC/MiniC.g4 +++ b/MiniC/MiniC.g4 @@ -24,6 +24,7 @@ stat: assignment SCOL | if_stat | while_stat | print_stat + | for_fortran_stat ; assignment: ID ASSIGN expr #assignStat; @@ -31,6 +32,9 @@ assignment: ID ASSIGN expr #assignStat; if_stat: IF OPAR expr CPAR then_block=stat_block (ELSE else_block=stat_block)? #ifStat; +for_fortran_stat: FOR ID ASSIGN expr TO expr + (BY expr)? stat_block #forStat; + stat_block: OBRACE block CBRACE | stat ; @@ -96,6 +100,9 @@ CBRACE : '}'; TRUE : 'true'; FALSE : 'false'; IF : 'if'; +FOR : 'for'; +TO : 'to'; +BY : 'by'; ELSE : 'else'; WHILE : 'while'; RETURN : 'return'; diff --git a/MiniC/README-interpreter.md b/MiniC/README-interpreter.md index 3d6f6c5..06fdd45 100644 --- a/MiniC/README-interpreter.md +++ b/MiniC/README-interpreter.md @@ -29,4 +29,6 @@ TODO: explain your choices - explain the limitations of your implementation. # Known bugs +- On a division by zero, the interpreter prints "Division by 0" message and returns 1. + This differs from certain versions of GCC. The test is therefore skipped. TODO: document any known bug and limitations. Did you do everything asked for? Did you implement an extension? diff --git a/MiniC/TP03/MiniCInterpretVisitor.py b/MiniC/TP03/MiniCInterpretVisitor.py index f1571d8..f3b5022 100644 --- a/MiniC/TP03/MiniCInterpretVisitor.py +++ b/MiniC/TP03/MiniCInterpretVisitor.py @@ -22,10 +22,20 @@ class MiniCInterpretVisitor(MiniCVisitor): def visitVarDecl(self, ctx) -> None: # Initialise all variables in self._memory type_str = ctx.typee().getText() - raise NotImplementedError(f"Initialization for type {type_str}") + default_value = { + "float": 0.0, + "int": 0, + "bool": False, + "string": "" + }[type_str] + + names_str = self.visit(ctx.id_l()) + for name in names_str: + self._memory[name] = default_value def visitIdList(self, ctx) -> List[str]: - raise NotImplementedError() + ids = self.visit(ctx.id_l()) + return ids + [ctx.ID().getText()] def visitIdListBase(self, ctx) -> List[str]: return [ctx.ID().getText()] @@ -45,7 +55,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 "" @@ -115,10 +125,20 @@ class MiniCInterpretVisitor(MiniCVisitor): return lval * rval elif ctx.myop.type == MiniCParser.DIV: # TODO : interpret division - raise NotImplementedError() + if rval == 0: + raise MiniCRuntimeError("Division by 0") + if type(lval) == type(1) and type(rval) == type(1): + # Integer division + if lval * rval < 0: + return -int(abs(lval)/abs(rval)) + return int(abs(lval)/abs(rval)) + raise MiniCInternalError("Attempting to divide elements of different type") elif ctx.myop.type == MiniCParser.MOD: - # TODO : interpret modulo - raise NotImplementedError() + if rval == 0: + raise MiniCRuntimeError("Division by 0") + if lval < 0: + return -(abs(lval) % abs(rval)) + return lval % abs(rval) else: raise MiniCInternalError( f"Unknown multiplicative operator '{ctx.myop}'") @@ -150,13 +170,42 @@ class MiniCInterpretVisitor(MiniCVisitor): print(val) def visitAssignStat(self, ctx) -> None: - raise NotImplementedError() + v = self.visit(ctx.expr()) + self._memory[ctx.ID().getText()] = v def visitIfStat(self, ctx) -> None: - raise NotImplementedError() + b = self.visit(ctx.expr()) + blocks = ctx.stat_block() + if b != 0: + self.visit(blocks[0]) + elif len(blocks) > 1: + self.visit(blocks[1]) def visitWhileStat(self, ctx) -> None: - raise NotImplementedError() + while self.visit(ctx.expr()) != 0: + self.visit(ctx.stat_block()) + + def visitForStat(self, ctx) -> None: + from_val = self.visit(ctx.expr(0)) + to_val = self.visit(ctx.expr(1)) + stride = 1 + if len(ctx.expr()) > 2: + stride = self.visit(ctx.expr(2)) + + def cond_fun(stride): + if stride > 0: + return lambda x,y: x < y + return lambda x,y: x > y + + condition = cond_fun(stride) + + counter = ctx.ID().getText() + self._memory[counter] = from_val + while condition(self._memory[counter], to_val): + old_counter = self._memory[counter] + self.visit(ctx.stat_block()) + self._memory[counter] = old_counter + stride # type: ignore + # TOPLEVEL def visitProgRule(self, ctx) -> None: diff --git a/MiniC/TP03/MiniCTypingVisitor.py b/MiniC/TP03/MiniCTypingVisitor.py index f9c5fcd..f68deae 100644 --- a/MiniC/TP03/MiniCTypingVisitor.py +++ b/MiniC/TP03/MiniCTypingVisitor.py @@ -43,7 +43,13 @@ class MiniCTypingVisitor(MiniCVisitor): # type declaration def visitVarDecl(self, ctx) -> None: - raise NotImplementedError() + names_str = self.visit(ctx.id_l()) + type_minic = self.visit(ctx.typee()) + + for name in names_str: + if name in self._memorytypes: + self._raiseNonType(ctx, f"Variable {name} already declared") + self._memorytypes[name] = type_minic def visitBasicType(self, ctx): assert ctx.mytype is not None @@ -51,14 +57,18 @@ class MiniCTypingVisitor(MiniCVisitor): return BaseType.Integer elif ctx.mytype.type == MiniCParser.FLOATTYPE: return BaseType.Float - else: # TODO: same for other types - raise NotImplementedError() + elif ctx.mytype.type == MiniCParser.STRINGTYPE: + return BaseType.String + elif ctx.mytype.type == MiniCParser.BOOLTYPE: + return BaseType.Boolean + def visitIdList(self, ctx) -> List[str]: - raise NotImplementedError() + ids = self.visit(ctx.id_l()) + return ids + [ctx.ID().getText()] def visitIdListBase(self, ctx) -> List[str]: - raise NotImplementedError() + return [ctx.ID().getText()] # typing visitors for expressions, statements ! @@ -73,14 +83,13 @@ class MiniCTypingVisitor(MiniCVisitor): return BaseType.Float def visitBooleanAtom(self, ctx): - raise NotImplementedError() + return BaseType.Boolean def visitIdAtom(self, ctx): try: return self._memorytypes[ctx.getText()] except KeyError: - self._raiseNonType(ctx, - "Undefined variable {}".format(ctx.getText())) + self._raiseNonType(ctx, "Undefined variable {}".format(ctx.getText())) def visitStringAtom(self, ctx): return BaseType.String @@ -91,30 +100,67 @@ class MiniCTypingVisitor(MiniCVisitor): return self.visit(ctx.atom()) def visitOrExpr(self, ctx): - raise NotImplementedError() + ltype = self.visit(ctx.expr(0)) + rtype = self.visit(ctx.expr(1)) + self._assertSameType(ctx, "|", ltype, rtype) + if ltype == BaseType.String: + self._raise(ctx, "string not allowed", ltype) + return ltype def visitAndExpr(self, ctx): - raise NotImplementedError() + ltype = self.visit(ctx.expr(0)) + rtype = self.visit(ctx.expr(1)) + self._assertSameType(ctx, "&", ltype, rtype) + if ltype == BaseType.String: + self._raise(ctx, "string not allowed", ltype) + return ltype def visitEqualityExpr(self, ctx): - raise NotImplementedError() + ltype = self.visit(ctx.expr(0)) + rtype = self.visit(ctx.expr(1)) + self._assertSameType(ctx, "==", ltype, rtype) + return BaseType.Boolean def visitRelationalExpr(self, ctx): - raise NotImplementedError() + ltype = self.visit(ctx.expr(0)) + rtype = self.visit(ctx.expr(1)) + self._assertSameType(ctx, "relational expr need same type", ltype, rtype) + if ltype not in [BaseType.Integer, BaseType.Float]: + self._raise(ctx, "non numeric type", ltype) + return BaseType.Boolean def visitAdditiveExpr(self, ctx): assert ctx.myop is not None - raise NotImplementedError() + ltype = self.visit(ctx.expr(0)) + rtype = self.visit(ctx.expr(1)) + self._assertSameType(ctx, "Additive", ltype, rtype) + if ltype not in [BaseType.String, BaseType.Integer, BaseType.Float]: + self._raise(ctx, "additive operands", ltype, rtype) + if ltype == BaseType.String and ctx.myop.type != MiniCParser.PLUS: + self._raise(ctx, "Minus not compatible with string", ltype) + return ltype def visitMultiplicativeExpr(self, ctx): assert ctx.myop is not None - raise NotImplementedError() + ltype = self.visit(ctx.expr(0)) + rtype = self.visit(ctx.expr(1)) + if ltype == BaseType.String or rtype == BaseType.String: + self._raise(ctx, "multiplicative operands", ltype, rtype) + self._assertSameType(ctx, "multiplicative operands", ltype, rtype) + return ltype def visitNotExpr(self, ctx): - raise NotImplementedError() + ltype = self.visit(ctx.expr()) + if ltype != BaseType.Boolean: + self._raise(ctx, "NOT: only boolean allowed", ltype) + return BaseType.Boolean def visitUnaryMinusExpr(self, ctx): - raise NotImplementedError() + ltype = self.visit(ctx.expr()) + if ltype not in [BaseType.Integer, BaseType.Float]: + self._raise(ctx, "non integer type", ltype) + return ltype + # visit statements @@ -139,10 +185,42 @@ class MiniCTypingVisitor(MiniCVisitor): self._raise(ctx, 'println_string statement', etype) def visitAssignStat(self, ctx): - raise NotImplementedError() + etype = self.visit(ctx.expr()) + if ctx.ID().getText() not in self._memorytypes: + self._raiseNonType(ctx, f"Undefined variable {ctx.ID().getText()}") + self._assertSameType(ctx, ctx.ID().getText(), self._memorytypes[ctx.ID().getText()], etype) def visitWhileStat(self, ctx): - raise NotImplementedError() + etype = self.visit(ctx.expr()) + if etype != BaseType.Boolean: + self._raise(ctx, "non boolean as condition", etype) + self.visit(ctx.stat_block()) def visitIfStat(self, ctx): - raise NotImplementedError() + etype = self.visit(ctx.expr()) + if etype != BaseType.Boolean: + self._raise(ctx, "non boolean as condition", etype) + for block in ctx.stat_block(): + self.visit(block) + + def visitForStat(self, ctx) -> None: + from_type = self.visit(ctx.expr(0)) + to_type = self.visit(ctx.expr(1)) + + if from_type != BaseType.Integer: + self._raise(ctx, "non-integer from value", from_type) + if to_type != BaseType.Integer: + self._raise(ctx, "non-integer to value", to_type) + + + if ctx.ID().getText() not in self._memorytypes: + self._raiseNonType(ctx, f"Undefined variable {ctx.ID().getText()}") + if self._memorytypes[ctx.ID().getText()] != BaseType.Integer: + self._raise(ctx, "non-integer for loop counter", self._memorytypes[ctx.ID().getText()]) + + if len(ctx.expr()) > 2: + stride_type = self.visit(ctx.expr(2)) + if stride_type != BaseType.Integer: + self._raise(ctx, "non-integer stride value", stride_type) + + self.visit(ctx.stat_block()) diff --git a/MiniC/TP03/tests/students/base/test_add_string.c b/MiniC/TP03/tests/students/base/test_add_string.c new file mode 100644 index 0000000..f694c86 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_add_string.c @@ -0,0 +1,10 @@ +#include "printlib.h" + +int main() { + println_string("hello"+" "+"there"); + return 0; +} + +// SKIP TEST EXPECTED +// EXPECTED +// hello there diff --git a/MiniC/TP03/tests/students/base/test_and_string.c b/MiniC/TP03/tests/students/base/test_and_string.c new file mode 100644 index 0000000..fa643d7 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_and_string.c @@ -0,0 +1,11 @@ +#include "printlib.h" + +int main() { + println_string("hello" && "hi"); + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 4 col 17: invalid type for string not allowed: string \ No newline at end of file diff --git a/MiniC/TP03/tests/students/base/test_comp_bool.c b/MiniC/TP03/tests/students/base/test_comp_bool.c new file mode 100644 index 0000000..e7f2214 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_comp_bool.c @@ -0,0 +1,16 @@ +#include "printlib.h" + +int main() { + bool x, y; + + if (x <= y) { + println_string("ok"); + } + + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 6 col 6: invalid type for non numeric type: boolean \ No newline at end of file diff --git a/MiniC/TP03/tests/students/base/test_div_0.c b/MiniC/TP03/tests/students/base/test_div_0.c new file mode 100644 index 0000000..fc1d200 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_div_0.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main() { + int x, y; + x = 5; + y = 0; + println_int(x/0); + return 0; +} + +// SKIP TEST EXPECTED +// EXECCODE 1 +// EXPECTED +// Division by 0 diff --git a/MiniC/TP03/tests/students/base/test_div_0_float.c b/MiniC/TP03/tests/students/base/test_div_0_float.c new file mode 100644 index 0000000..1fec8fc --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_div_0_float.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main() { + float x, y; + x = 5.0; + y = 0.0; + x = x/y; + return 0; +} + +// SKIP TEST EXPECTED +// EXECCODE 1 +// EXPECTED +// Division by 0 diff --git a/MiniC/TP03/tests/students/base/test_division.c b/MiniC/TP03/tests/students/base/test_division.c new file mode 100644 index 0000000..b07a011 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_division.c @@ -0,0 +1,16 @@ +#include "printlib.h" + +int main() { + int x, y; + float xf, yf; + + x = 5; + y = 2; + println_int((-x)/y); + println_int(x/y); + return 0; +} + +// EXPECTED +// -2 +// 2 diff --git a/MiniC/TP03/tests/students/base/test_else.c b/MiniC/TP03/tests/students/base/test_else.c new file mode 100644 index 0000000..eb23197 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_else.c @@ -0,0 +1,15 @@ +#include "printlib.h" + +int main() { + int x, y; + if (x != 0) { + y = 12; + } else { + y = -3; + } + println_int(y); + return 0; +} + +// EXPECTED +// -3 diff --git a/MiniC/TP03/tests/students/base/test_if_nonbool.c b/MiniC/TP03/tests/students/base/test_if_nonbool.c new file mode 100644 index 0000000..3f9bde0 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_if_nonbool.c @@ -0,0 +1,16 @@ +#include "printlib.h" + +int main() { + int x, y; + + if (x) { + y = 5; + } + println_int(y); + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 6 col 2: invalid type for non boolean as condition: integer diff --git a/MiniC/TP03/tests/students/base/test_mod.c b/MiniC/TP03/tests/students/base/test_mod.c new file mode 100644 index 0000000..a4b760f --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_mod.c @@ -0,0 +1,19 @@ +#include "printlib.h" + +int main() { + int x, y; + x = 5; + y = 3; + println_int(x%y); + println_int((-x)%y); + y = 0; + println_int(x%y); + return 0; +} + +// SKIP TEST EXPECTED +// EXECCODE 1 +// EXPECTED +// 2 +// -2 +// Division by 0 diff --git a/MiniC/TP03/tests/students/base/test_not_int.c b/MiniC/TP03/tests/students/base/test_not_int.c new file mode 100644 index 0000000..277d6cf --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_not_int.c @@ -0,0 +1,11 @@ +#include "printlib.h" + +int main() { + println_int(!(12+2)); + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 4 col 14: invalid type for NOT: only boolean allowed: integer diff --git a/MiniC/TP03/tests/students/base/test_or_string.c b/MiniC/TP03/tests/students/base/test_or_string.c new file mode 100644 index 0000000..fc7ad7a --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_or_string.c @@ -0,0 +1,11 @@ +#include "printlib.h" + +int main() { + println_string("hello" || "hi"); + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 4 col 17: invalid type for string not allowed: string diff --git a/MiniC/TP03/tests/students/base/test_println_bool.c b/MiniC/TP03/tests/students/base/test_println_bool.c new file mode 100644 index 0000000..1960ef7 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_println_bool.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main() { + int x, y; + + println_bool(true); + println_bool(y+2); + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 7 col 2: invalid type for println_bool statement: integer diff --git a/MiniC/TP03/tests/students/base/test_println_float.c b/MiniC/TP03/tests/students/base/test_println_float.c new file mode 100644 index 0000000..946f84a --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_println_float.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main() { + int x, y; + + println_float(15.0); + println_float(y+2); + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 7 col 2: invalid type for println_float statement: integer diff --git a/MiniC/TP03/tests/students/base/test_println_string.c b/MiniC/TP03/tests/students/base/test_println_string.c new file mode 100644 index 0000000..a4fe9c3 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_println_string.c @@ -0,0 +1,14 @@ +#include "printlib.h" + +int main() { + int x, y; + + println_string("hello !"); + println_string(y-2); + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 7 col 2: invalid type for println_string statement: integer diff --git a/MiniC/TP03/tests/students/base/test_substr_string.c b/MiniC/TP03/tests/students/base/test_substr_string.c new file mode 100644 index 0000000..5016224 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_substr_string.c @@ -0,0 +1,11 @@ +#include "printlib.h" + +int main() { + println_string("hello" - "llo"); + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 4 col 17: invalid type for Minus not compatible with string: string diff --git a/MiniC/TP03/tests/students/base/test_unary_string.c b/MiniC/TP03/tests/students/base/test_unary_string.c new file mode 100644 index 0000000..75b3825 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_unary_string.c @@ -0,0 +1,11 @@ +#include "printlib.h" + +int main() { + println_string(-"hello"); + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 4 col 17: invalid type for non integer type: string diff --git a/MiniC/TP03/tests/students/base/test_while.c b/MiniC/TP03/tests/students/base/test_while.c new file mode 100644 index 0000000..f8e80a2 --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_while.c @@ -0,0 +1,13 @@ +#include "printlib.h" + +int main() { + int x; + while (x < 12) { + x = x+2; + } + println_int(x); + return 0; +} + +// EXPECTED +// 12 diff --git a/MiniC/TP03/tests/students/base/test_while_nonbool.c b/MiniC/TP03/tests/students/base/test_while_nonbool.c new file mode 100644 index 0000000..b65726a --- /dev/null +++ b/MiniC/TP03/tests/students/base/test_while_nonbool.c @@ -0,0 +1,17 @@ +#include "printlib.h" + +int main() { + int x, y; + + while (x) { + y = 5; + x = x+1; + } + println_int(y); + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 6 col 2: invalid type for non boolean as condition: integer diff --git a/MiniC/TP03/tests/students/ext-for-c/README.md b/MiniC/TP03/tests/students/ext-for-c/README.md deleted file mode 100644 index f2a3430..0000000 --- a/MiniC/TP03/tests/students/ext-for-c/README.md +++ /dev/null @@ -1 +0,0 @@ -Add your own tests for the C-like 'for' loop in this directory (tests for the interpreter). diff --git a/MiniC/TP03/tests/students/ext-for-fortran/test_for.c b/MiniC/TP03/tests/students/ext-for-fortran/test_for.c new file mode 100644 index 0000000..2aa7fa2 --- /dev/null +++ b/MiniC/TP03/tests/students/ext-for-fortran/test_for.c @@ -0,0 +1,32 @@ +#include "printlib.h" + +int main() { + int x, y; + int zero, trois; + trois = 3; + + // simple loop + for x=zero to trois { + y = y+3; + } + println_int(y); + println_int(x); + + // inversed loop + for x=5 to 1 by -2 { + println_int(x); + } + + // empty loop + for x=5 to 0 { + println_int(-1); + } + return 0; +} + +// SKIP TEST EXPECTED +// EXPECTED +// 9 +// 3 +// 5 +// 3 diff --git a/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_from.c b/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_from.c new file mode 100644 index 0000000..7f34bfb --- /dev/null +++ b/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_from.c @@ -0,0 +1,17 @@ +#include "printlib.h" + +int main() { + int x, y; + float fl; + fl = 12.0; + + for x=fl to 3 { + y = y+3; + } + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 2: invalid type for non-integer from value: float diff --git a/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_id.c b/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_id.c new file mode 100644 index 0000000..dfc5f42 --- /dev/null +++ b/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_id.c @@ -0,0 +1,17 @@ +#include "printlib.h" + +int main() { + int x, y; + float fl; + fl = 12.0; + + for fl=0 to 3 { + y = y+3; + } + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 2: invalid type for non-integer for loop counter: float diff --git a/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_stride.c b/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_stride.c new file mode 100644 index 0000000..880c506 --- /dev/null +++ b/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_stride.c @@ -0,0 +1,15 @@ +#include "printlib.h" + +int main() { + int x, y; + + for x=0 to 3 by 1.0 { + y = y+3; + } + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 6 col 2: invalid type for non-integer stride value: float diff --git a/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_to.c b/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_to.c new file mode 100644 index 0000000..05c910c --- /dev/null +++ b/MiniC/TP03/tests/students/ext-for-fortran/test_invalid_to.c @@ -0,0 +1,17 @@ +#include "printlib.h" + +int main() { + int x, y; + float fl; + fl = 12.0; + + for x=0 to fl { + y = y+3; + } + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 8 col 2: invalid type for non-integer to value: float diff --git a/MiniC/TP03/tests/students/ext-for-fortran/test_undefined_id.c b/MiniC/TP03/tests/students/ext-for-fortran/test_undefined_id.c new file mode 100644 index 0000000..722193d --- /dev/null +++ b/MiniC/TP03/tests/students/ext-for-fortran/test_undefined_id.c @@ -0,0 +1,15 @@ +#include "printlib.h" + +int main() { + int x, y; + + for undef=0 to 3 { + y = y+3; + } + return 0; +} + +// SKIP TEST EXPECTED +// EXITCODE 2 +// EXPECTED +// In function main: Line 6 col 2: Undefined variable undef