summaryrefslogtreecommitdiff
path: root/src/ast/nodes/CompForNode.java
diff options
context:
space:
mode:
authorgeno <gabriele.genovese2@studio.unibo.it>2024-06-27 20:49:56 +0200
committergeno <gabriele.genovese2@studio.unibo.it>2024-06-27 20:49:56 +0200
commitfd85e9980c0305c6dfb91aaeb199430a89163c3e (patch)
tree724d7184c11ad3acb8a8b0d2e15f1922f5b36059 /src/ast/nodes/CompForNode.java
parent4898724edf343650ffb80792caf9e242e5843059 (diff)
fixed comp_for and added reseved word type
Diffstat (limited to 'src/ast/nodes/CompForNode.java')
-rw-r--r--src/ast/nodes/CompForNode.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/ast/nodes/CompForNode.java b/src/ast/nodes/CompForNode.java
new file mode 100644
index 0000000..d5c50d6
--- /dev/null
+++ b/src/ast/nodes/CompForNode.java
@@ -0,0 +1,59 @@
+package ast.nodes;
+
+import ast.types.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
+
+/**
+ * Node for the `comp_for` statement of the grammar. 'for' exprlist 'in' expr
+ * comp_iter?
+ */
+public class CompForNode implements Node {
+
+ protected ExprListNode exprlist;
+ protected ExprNode single_expr;
+ protected CompIterNode comp_iter;
+
+ public CompForNode(Node exprlist, Node single_expr, Node comp_iter) {
+ this.exprlist = (ExprListNode) exprlist;
+ this.single_expr = (ExprNode) single_expr;
+ this.comp_iter = (CompIterNode) comp_iter;
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+
+ errors.addAll(exprlist.checkSemantics(ST, _nesting));
+ errors.addAll(single_expr.checkSemantics(ST, _nesting));
+ if (comp_iter != null) {
+ errors.addAll(comp_iter.checkSemantics(ST, _nesting));
+ }
+ return errors;
+ }
+
+ @Override
+ public Type typeCheck() {
+ return new VoidType();
+ }
+
+ // TODO: add code generation for arglist node
+ @Override
+ public String codeGeneration() {
+ return "";
+ }
+
+ @Override
+ public String toPrint(String prefix) {
+ String str = prefix + "CompForNode\n";
+
+ prefix += " ";
+ str += exprlist.toPrint(prefix);
+ str += single_expr.toPrint(prefix);
+ str += comp_iter.toPrint(prefix);
+ return str;
+ }
+
+}