summaryrefslogtreecommitdiff
path: root/src/ast/nodes/ExprNode.java
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-06-13 11:00:06 +0200
committerGitHub <noreply@github.com>2024-06-13 11:00:06 +0200
commit8e7089a5d6ba1f4f50a90133bb50bc5c6c554aff (patch)
treed4a627e56a199720f7d811af5756402e76628864 /src/ast/nodes/ExprNode.java
parent1c8761901b26c0be4d61f3aed5ec0495a558a0e7 (diff)
Set up visitor (#3)
Co-authored-by: geno <gabriele.genovese2@studio.unibo.it>
Diffstat (limited to 'src/ast/nodes/ExprNode.java')
-rw-r--r--src/ast/nodes/ExprNode.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/ast/nodes/ExprNode.java b/src/ast/nodes/ExprNode.java
new file mode 100644
index 0000000..3aa112f
--- /dev/null
+++ b/src/ast/nodes/ExprNode.java
@@ -0,0 +1,90 @@
+package com.clp.project.ast.nodes;
+
+import java.util.ArrayList;
+
+import com.clp.project.semanticanalysis.SemanticError;
+import com.clp.project.semanticanalysis.SymbolTable;
+import com.clp.project.ast.types.*;
+
+/**
+ * Node for the `expr` statement of the grammar.
+ */
+public class ExprNode implements Node {
+ private Node atom;
+ private Node compOp;
+ private String op;
+ private ArrayList<Node> exprs;
+ private ArrayList<Node> trailers;
+
+ public ExprNode(Node atom, Node compOp, ArrayList<Node> exprs, String op, ArrayList<Node> trailers) {
+ this.atom = atom;
+ this.compOp = compOp;
+ this.exprs = exprs;
+ this.op = op;
+ this.trailers = trailers;
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+
+ if (atom != null) {
+ errors.addAll(atom.checkSemantics(ST, _nesting));
+ }
+
+ if (compOp != null) {
+ errors.addAll(compOp.checkSemantics(ST, _nesting));
+ }
+
+ for (var expr : exprs) {
+ errors.addAll(expr.checkSemantics(ST, _nesting));
+ }
+
+ for (var trailer : trailers) {
+ errors.addAll(trailer.checkSemantics(ST, _nesting));
+ }
+
+ return errors;
+ }
+
+ // FIXME: type for the expr
+ @Override
+ public Type typeCheck() {
+ return new VoidType();
+ }
+
+ // TODO: add code generation for expr
+ @Override
+ public String codeGeneration() {
+ return "";
+ }
+
+ @Override
+ public String toPrint(String prefix) {
+ String str = prefix + "Expr\n";
+
+ prefix += " ";
+ if (atom != null) {
+ str += atom.toPrint(prefix);
+ }
+
+ if (compOp != null) {
+ str += compOp.toPrint(prefix);
+ }
+
+ for (var expr : exprs) {
+ str += expr.toPrint(prefix);
+ }
+
+ for (var trailer : trailers) {
+ str += trailer.toPrint(prefix);
+ }
+
+ if (op != null) {
+ str += prefix + "Op(" + op + ")\n";
+ }
+
+ return str;
+ }
+
+}