From ce49d20a5fe3726e1800bc495a25c7617212abf4 Mon Sep 17 00:00:00 2001 From: Emanuele Grasso <96300448+L0P0P@users.noreply.github.com> Date: Sun, 14 Jul 2024 18:48:09 +0200 Subject: Reaching definition analysis (#17) Co-authored-by: Santo Cariotti Co-authored-by: geno Co-authored-by: geno --- src/ast/nodes/AtomNode.java | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/ast/nodes/AtomNode.java') diff --git a/src/ast/nodes/AtomNode.java b/src/ast/nodes/AtomNode.java index ea99808..204c3b3 100644 --- a/src/ast/nodes/AtomNode.java +++ b/src/ast/nodes/AtomNode.java @@ -13,6 +13,8 @@ import semanticanalysis.SymbolTable; */ public class AtomNode implements Node { + private String prefix; + private String suffix; protected String val; protected TestlistCompNode exprlist; @@ -21,8 +23,14 @@ public class AtomNode implements Node { protected int offset; public AtomNode(String val, Node exprlist) { + this(val, exprlist, "", ""); + } + + public AtomNode(String val, Node exprlist, String prefix, String suffix) { this.val = val; this.exprlist = (TestlistCompNode) exprlist; + this.prefix = prefix; + this.suffix = suffix; } /** @@ -33,6 +41,10 @@ public class AtomNode implements Node { return val; } + public void setId(String id) { + this.val = id; + } + @Override public ArrayList checkSemantics(SymbolTable ST, int _nesting, FunctionType ft) { ArrayList errors = new ArrayList<>(); @@ -134,13 +146,25 @@ public class AtomNode implements Node { } @Override - public String toPrint(String prefix) { - // FIXME: can be a testlist_comp with two expr and two atoms + public String printAST(String prefix) { if (val != null) { - return prefix + "Atom(" + val + ")\n"; + return prefix + "AtomNode: " + val + "\n"; + } else { + return prefix + "AtomNode\n" + exprlist.printAST(prefix + " "); } + } - return prefix + "Atom(null)\n"; + @Override + public String toPrint(String prefix) { + String str = prefix + this.prefix; + + if (val != null) { + str += val; + } else { + str += this.exprlist.toPrint(""); + } + str += this.suffix; + return str; } } -- cgit v1.2.3-18-g5258