summaryrefslogtreecommitdiffstats
path: root/src/front/scope.py
diff options
context:
space:
mode:
authorAndreas Nüßlein <nutz@unfoog.de>2009-06-30 20:57:09 +0200
committerAndreas Nüßlein <nutz@unfoog.de>2009-06-30 20:57:09 +0200
commit8c9fb246794f7cb94689c348f104b29433416f4e (patch)
treee32ae136f1baacafc0cc266382846ab3ae007e47 /src/front/scope.py
parent4aedc5d76250fae734af1cd89256ec70e165ab18 (diff)
downloadswppy-8c9fb246794f7cb94689c348f104b29433416f4e.tar.gz
swppy-8c9fb246794f7cb94689c348f104b29433416f4e.tar.xz
swppy-8c9fb246794f7cb94689c348f104b29433416f4e.zip
implemented scope and most of ast
Diffstat (limited to '')
-rw-r--r--src/front/scope.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/front/scope.py b/src/front/scope.py
index 0df8729..a15ed1d 100644
--- a/src/front/scope.py
+++ b/src/front/scope.py
@@ -1,6 +1,24 @@
class Scope(object):
__shared_state = {}
- functions = {}
+ __current_function = None
+ __functions = {}
def __init__(self):
self.__dict__ = self.__shared_state
+
+ def new(self, name, symbols = []):
+ if getattr(self.__functions, name, None):
+ raise ScopeError("multiple definitions of %s" % name)
+ self.__functions[name] = []
+ self.__current_function = name
+ self.add(symbols)
+
+ def add(self, symbols):
+ if type(symbols) != type([]):
+ symbols = [symbols]
+ for symbol in symbols:
+ if symbol not in self.__functions[self.__current_function]:
+ self.__functions[self.__current_function].append(symbol)
+
+ def __str__(self):
+ return "<Scope: %s>" % str(self.__functions)