diff options
author | geno <gabriele.genovese2@studio.unibo.it> | 2024-06-27 18:19:27 +0200 |
---|---|---|
committer | geno <gabriele.genovese2@studio.unibo.it> | 2024-06-27 18:19:27 +0200 |
commit | 095a2cb4e9abb88805aac3271874bc512108ff96 (patch) | |
tree | 2f4a14954b6efac11f108c6eb862b1c12bee40d7 | |
parent | 673117132daa9c4fdd103189b5cd9a32a3731f5a (diff) |
minor changes
-rw-r--r-- | src/ast/nodes/ArglistNode.java | 5 | ||||
-rw-r--r-- | src/ast/nodes/AtomNode.java | 6 | ||||
-rw-r--r-- | src/ast/nodes/ExprNode.java | 12 |
3 files changed, 11 insertions, 12 deletions
diff --git a/src/ast/nodes/ArglistNode.java b/src/ast/nodes/ArglistNode.java index 78b4ca7..983d150 100644 --- a/src/ast/nodes/ArglistNode.java +++ b/src/ast/nodes/ArglistNode.java @@ -3,7 +3,6 @@ package ast.nodes; import ast.types.*; import java.util.ArrayList; import java.util.Arrays; - import semanticanalysis.SemanticError; import semanticanalysis.SymbolTable; @@ -37,8 +36,8 @@ public class ArglistNode implements Node { continue; } - if (!ST.top_lookup(argName) && argExpr.typeCheck() instanceof AtomType) { - errors.add(new SemanticError("'" + argName + "' is not defined.")); + if (ST.nslookup(argName) < 0 && argExpr.typeCheck() instanceof AtomType) { + errors.add(new SemanticError("name '" + argName + "' is not defined.")); } } else { errors.addAll(arg.checkSemantics(ST, _nesting)); diff --git a/src/ast/nodes/AtomNode.java b/src/ast/nodes/AtomNode.java index 58cd7f9..3c2b1eb 100644 --- a/src/ast/nodes/AtomNode.java +++ b/src/ast/nodes/AtomNode.java @@ -28,6 +28,8 @@ public class AtomNode implements Node { if ((this.typeCheck() instanceof AtomType) && ST.nslookup(this.getId()) < 0) { errors.add(new SemanticError("name '" + this.getId() + "' is not defined.")); + } else { + // System.out.println("exist " + this.getId()); } return errors; @@ -40,11 +42,11 @@ public class AtomNode implements Node { Pattern continueBreakVariable = Pattern.compile("^(continue|break)$"); // this regex should match every possible atom name written in this format: CHAR (CHAR | DIGIT)* Pattern simpleVariable = Pattern.compile("^[a-zA-Z][a-zA-Z0-9]*$", Pattern.CASE_INSENSITIVE); - + Matcher booleanVariableMatcher = booleanVariable.matcher(this.val); Matcher continueBreakVariableMatcher = continueBreakVariable.matcher(this.val); Matcher simpleVariableMatcher = simpleVariable.matcher(this.val); - + boolean matchFoundBoolean = booleanVariableMatcher.find(); boolean matchFoundContinueBreak = continueBreakVariableMatcher.find(); boolean matchFoundSimpleVariable = simpleVariableMatcher.find(); diff --git a/src/ast/nodes/ExprNode.java b/src/ast/nodes/ExprNode.java index 1b20e2e..62b3a94 100644 --- a/src/ast/nodes/ExprNode.java +++ b/src/ast/nodes/ExprNode.java @@ -3,7 +3,6 @@ package ast.nodes; import ast.types.*; import java.util.ArrayList; import java.util.Arrays; - import semanticanalysis.STentry; import semanticanalysis.SemanticError; import semanticanalysis.SymbolTable; @@ -39,21 +38,20 @@ public class ExprNode implements Node { public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) { ArrayList<SemanticError> errors = new ArrayList<SemanticError>(); - // check if the atom is a built-in function + // check if the atom is a function if (atom != null && !trailers.isEmpty()) { + // check if the atom is not a built-in function if (!Arrays.asList(bif).contains(atom.getId())) { - + errors.addAll(atom.checkSemantics(ST, _nesting)); - + TrailerNode trailer = (TrailerNode) trailers.get(0); String funName = atom.getId(); // TODO: it isnt a function, it could be a variable STentry fun = ST.lookup(funName); - - if (fun != null && !(fun.getType() instanceof ImportType)) { if (!(fun.getType() instanceof FunctionType)) { if (trailer.isParenthesis()) { @@ -96,7 +94,7 @@ public class ExprNode implements Node { // FIXME: type for the expr @Override public Type typeCheck() { - if (this.atom != null ) { + if (this.atom != null) { return this.atom.typeCheck(); } |