testing in meeting

This commit is contained in:
Krauß, Josefine 2024-06-20 08:30:12 +02:00
parent 6585e67273
commit 5220a65a92
4 changed files with 16 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import abstractSyntaxTree.Expression.LocalVarIdentifier;
import abstractSyntaxTree.Expression.UnaryExpression;
import abstractSyntaxTree.Program;
import abstractSyntaxTree.Statement.IStatement;
import abstractSyntaxTree.Statement.IfElseStatement;
import abstractSyntaxTree.Statement.LocalVarDecl;
import abstractSyntaxTree.Statement.ReturnStatement;
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
@ -104,8 +105,12 @@ public class Compiler {
// }
//abstractSyntaxTree.classes.get(0).methodDecls.get(0).codeBlock.returnType = "char";
AssignStatementExpression a = (AssignStatementExpression) abstractSyntaxTree.classes.get(0).methodDecls.get(0).codeBlock.statements.get(2);
IfElseStatement c = (IfElseStatement) abstractSyntaxTree.classes.get(0).methodDecls.get(0).codeBlock.statements.get(2);
InstVarExpression d = (InstVarExpression) c.condition;
d.classRef = abstractSyntaxTree.classes.get(0);
AssignStatementExpression a = (AssignStatementExpression) abstractSyntaxTree.classes.get(0).methodDecls.get(0).codeBlock.statements.get(1);
InstVarExpression b = (InstVarExpression) a.left;
b.classRef = abstractSyntaxTree.classes.get(0);
abstractSyntaxTree.typeCheck();

View File

@ -4,8 +4,12 @@ class Example {
char c;
int m(int n){
int localA;
localA = 5;
this.i = 3;
this.b = true;
if(this.b){
localA = 7;
}else{
localA = 5;
}
return localA;
}
}

View File

@ -12,7 +12,7 @@ import java.util.List;
import java.util.Objects;
public class IfElseStatement extends AbstractType implements IStatement{
IExpression condition;
public IExpression condition;
IStatement ifStatement;
IStatement elseStatement;
@ -29,7 +29,7 @@ public class IfElseStatement extends AbstractType implements IStatement{
TypeCheckResult conditionType = condition.typeCheck(methodContext, typeContext, localVars);
if (!conditionType.type.equals("bool")) {
if (!conditionType.type.equals("boolean")) {
throw new IllegalArgumentException("should be boolean");
}

View File

@ -12,7 +12,7 @@ import java.util.List;
import java.util.Objects;
public class IfStatement extends AbstractType implements IStatement{
IExpression condition;
public IExpression condition;
//Do we need a block statement here?
IStatement ifStatement;