summaryrefslogtreecommitdiff
path: root/src/ast/nodes/ExprListNode.java
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-06-30 13:45:57 +0200
committerGitHub <noreply@github.com>2024-06-30 13:45:57 +0200
commit8aa8b5834953cab15c0687608f4fafea2e6c61be (patch)
tree1835ae7c789136b4a6c44c12efd4247a0b96d893 /src/ast/nodes/ExprListNode.java
parent7125bb27fedaafd5a56b5122e4251b182448ddac (diff)
parent06d7c8dee25c065b1a569337f34d3cd5e892a31d (diff)
Merge pull request #10 from boozec/check-semantics
Co-Authored-By: geno <gabriele.genovese2@studio.unibo.it> Co-Authored-By: L0P0P <grassoemanuele@live.com>
Diffstat (limited to 'src/ast/nodes/ExprListNode.java')
-rw-r--r--src/ast/nodes/ExprListNode.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/ast/nodes/ExprListNode.java b/src/ast/nodes/ExprListNode.java
new file mode 100644
index 0000000..4760db8
--- /dev/null
+++ b/src/ast/nodes/ExprListNode.java
@@ -0,0 +1,68 @@
+package ast.nodes;
+
+import ast.types.*;
+import java.util.ArrayList;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
+
+/**
+ * Node for the `expr_list` statement of the grammar.
+ */
+public class ExprListNode implements Node {
+
+ private final ArrayList<Node> exprs;
+
+ public ExprListNode(ArrayList<Node> exprs) {
+ this.exprs = exprs;
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ ArrayList<SemanticError> errors = new ArrayList<>();
+
+ for (var expr : exprs) {
+ errors.addAll(expr.checkSemantics(ST, _nesting));
+ }
+
+ return errors;
+ }
+
+ public int getSize() {
+ return exprs.size();
+ }
+
+ /**
+ * Returns the i-th expressions of `exprs` field. If the index is greater or
+ * equals than the size return `null`.
+ */
+ public Node getElem(int i) {
+ if (i >= this.exprs.size()) {
+ return null;
+ }
+ return exprs.get(i);
+ }
+
+ @Override
+ public Type typeCheck() {
+ return new VoidType();
+ }
+
+ // TODO: code generation for expr list
+ @Override
+ public String codeGeneration() {
+ return "";
+ }
+
+ @Override
+ public String toPrint(String prefix) {
+ String str = prefix + "ExprList\n";
+
+ prefix += " ";
+ for (var param : exprs) {
+ str += param.toPrint(prefix);
+ }
+
+ return str;
+ }
+
+}