public void insertEntry(EntryType entry) { if (lookup(entry.getId(), entry.getParams()) == null) { entries.add(entry); } else { throw new SemanticException( entry.getId() + " is already registered in this symbolTable. " + "You may want to update instead. 3" + lookup(entry.getId(), entry.getParams()) + ":" + entry); } }
/** * This is basically the method to look for function definitions. * * @param name function name * @param params function parameter * @return The Entry for this method */ public EntryType lookup(String name, List<EntryType> params) { EntryType ret = null; for (EntryType entry : entries) { if (entry.getId().equals(name)) { boolean found = true; if (entry.getParams().size() == params.size()) { for (int i = 0; i < params.size(); i++) { if (!entry.getParams().get(i).equals(params.get(i))) { found = false; } } } else { found = false; } if (found) ret = entry; } } return ret; }