From 06671f5aed68753435a762bc3be43e83094156d1 Mon Sep 17 00:00:00 2001 From: geno Date: Wed, 26 Jun 2024 14:53:05 +0200 Subject: exercise 1 completed 1.b now works 1.c implened error for "function takes N positional arguments but M were given" --- src/ast/nodes/IfNode.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/ast/nodes/IfNode.java') diff --git a/src/ast/nodes/IfNode.java b/src/ast/nodes/IfNode.java index 50dde4a..772041b 100644 --- a/src/ast/nodes/IfNode.java +++ b/src/ast/nodes/IfNode.java @@ -1,10 +1,9 @@ package ast.nodes; +import ast.types.*; import java.util.ArrayList; - import semanticanalysis.SemanticError; import semanticanalysis.SymbolTable; -import ast.types.*; /** * Node for the `if` statement of the grammar. -- cgit v1.2.3-18-g5258 From 3c4229fc9e0ec6da9a7f60b57b9e93c49d1b6b6c Mon Sep 17 00:00:00 2001 From: L0P0P Date: Thu, 27 Jun 2024 12:02:35 +0200 Subject: Fixed a lot of problems from all the progs we need to parse --- src/ast/nodes/IfNode.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ast/nodes/IfNode.java') diff --git a/src/ast/nodes/IfNode.java b/src/ast/nodes/IfNode.java index 772041b..f51d486 100644 --- a/src/ast/nodes/IfNode.java +++ b/src/ast/nodes/IfNode.java @@ -41,11 +41,11 @@ public class IfNode implements Node { if (thenexp.getClass().equals(elseexp.getClass())) return thenexp; else { - System.out.println("Type Error: incompatible types in then and else branches"); + System.out.println("Type Error: incompatible types in then and else branches."); return new ErrorType(); } } else { - System.out.println("Type Error: non boolean condition in if"); + System.out.println("Type Error: non boolean condition in if."); return new ErrorType(); } } -- cgit v1.2.3-18-g5258 From afff6a80cd58f7787efa1398f7c8cbdce8989323 Mon Sep 17 00:00:00 2001 From: geno Date: Sun, 30 Jun 2024 13:36:37 +0200 Subject: fixed warnings, better formatting, final added where possible --- src/ast/nodes/IfNode.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/ast/nodes/IfNode.java') diff --git a/src/ast/nodes/IfNode.java b/src/ast/nodes/IfNode.java index f51d486..b0e1ddb 100644 --- a/src/ast/nodes/IfNode.java +++ b/src/ast/nodes/IfNode.java @@ -9,9 +9,10 @@ import semanticanalysis.SymbolTable; * Node for the `if` statement of the grammar. */ public class IfNode implements Node { - private Node guard; - private Node thenbranch; - private Node elsebranch; + + private final Node guard; + private final Node thenbranch; + private final Node elsebranch; public IfNode(Node guard, Node thenbranch, Node elsebranch) { this.guard = guard; @@ -21,7 +22,7 @@ public class IfNode implements Node { @Override public ArrayList checkSemantics(SymbolTable ST, int _nesting) { - ArrayList errors = new ArrayList(); + ArrayList errors = new ArrayList(); errors.addAll(guard.checkSemantics(ST, _nesting)); errors.addAll(thenbranch.checkSemantics(ST, _nesting)); @@ -38,9 +39,9 @@ public class IfNode implements Node { if (guard.typeCheck() instanceof BoolType) { Type thenexp = thenbranch.typeCheck(); Type elseexp = elsebranch.typeCheck(); - if (thenexp.getClass().equals(elseexp.getClass())) - return thenexp; - else { + if (thenexp.getClass().equals(elseexp.getClass())) { + return thenexp; + }else { System.out.println("Type Error: incompatible types in then and else branches."); return new ErrorType(); } -- cgit v1.2.3-18-g5258