From f720e2d49c6292ccb3de8c9668c99a5b799038b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20B=C3=B6hm?= Date: Mon, 25 May 2009 18:45:16 +0200 Subject: add scope, and symbol class, obsoletes SymbolTable --- src/front/scope.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/front/scope.py (limited to 'src/front/scope.py') diff --git a/src/front/scope.py b/src/front/scope.py new file mode 100644 index 0000000..2cc3018 --- /dev/null +++ b/src/front/scope.py @@ -0,0 +1,20 @@ +class Scope(object, DictMixin): + def __init__(self, parent): + self.parent = parent + self.__symbols = {} + + def __getitem__(self, key): + try: + return self.__symbols[key] + except KeyError: + return self.parent[key] + + def __setitem__(self, key, item): + self.__symbols[key] = item + + def keys(self): + keys = self.__symbols.keys() + for key in self.parent.keys(): + if key not in keys: + keys.append(key) + return keys -- cgit v1.2.3