diff --git a/src/main/java/Compiler.java b/src/main/java/Compiler.java index e391269..a771ca9 100644 --- a/src/main/java/Compiler.java +++ b/src/main/java/Compiler.java @@ -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(); diff --git a/src/main/java/Input.java b/src/main/java/Input.java index 36b02eb..44ddefc 100644 --- a/src/main/java/Input.java +++ b/src/main/java/Input.java @@ -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; } } \ No newline at end of file diff --git a/src/main/java/abstractSyntaxTree/Statement/IfElseStatement.java b/src/main/java/abstractSyntaxTree/Statement/IfElseStatement.java index a26c62d..41fb152 100644 --- a/src/main/java/abstractSyntaxTree/Statement/IfElseStatement.java +++ b/src/main/java/abstractSyntaxTree/Statement/IfElseStatement.java @@ -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"); } diff --git a/src/main/java/abstractSyntaxTree/Statement/IfStatement.java b/src/main/java/abstractSyntaxTree/Statement/IfStatement.java index 8ad8499..7938a9b 100644 --- a/src/main/java/abstractSyntaxTree/Statement/IfStatement.java +++ b/src/main/java/abstractSyntaxTree/Statement/IfStatement.java @@ -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;