From 6bdf1fc6c1b7afe18ffcae05f8fb11eca0f51258 Mon Sep 17 00:00:00 2001
From: Santo Cariotti <santo@dcariotti.me>
Date: Tue, 25 Jun 2024 11:33:41 +0200
Subject: wip

---
 src/ast/nodes/AtomNode.java | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

(limited to 'src/ast/nodes/AtomNode.java')

diff --git a/src/ast/nodes/AtomNode.java b/src/ast/nodes/AtomNode.java
index 4dcb926..7dc38fb 100644
--- a/src/ast/nodes/AtomNode.java
+++ b/src/ast/nodes/AtomNode.java
@@ -16,15 +16,33 @@ public class AtomNode implements Node {
         this.val = val;
     }
 
+    public String getId() {
+        return this.val;
+    }
+
     @Override
     public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
-        return new ArrayList<SemanticError>();
+        var errors = new ArrayList<SemanticError>();
+        System.out.println(getId() + " " + _nesting + " " + ST.nslookup(getId()));
+        if (!(this.typeCheck() instanceof IntType) && !ST.top_lookup(this.getId())) {
+            System.out.println(!(this.typeCheck() instanceof IntType) + " " + !ST.top_lookup(this.getId()));
+            errors.add(new SemanticError("Undefined name `" + this.getId() + "`"));
+        }
+
+        return errors;
     }
 
     // FIXME: this type for atom
     @Override
     public Type typeCheck() {
-        return new AtomType();
+        try {
+            Integer.parseInt(this.val);
+            System.out.println(this.val + " is int");
+            return new IntType();
+        } catch (NumberFormatException e) {
+            System.out.println(this.val + " is atom");
+            return new AtomType();
+        }
     }
 
     // TODO: add code generation for atom node
-- 
cgit v1.2.3-18-g5258