diff options
author | Andreas Nüßlein <nutz@unfoog.de> | 2009-06-30 20:57:09 +0200 |
---|---|---|
committer | Andreas Nüßlein <nutz@unfoog.de> | 2009-06-30 20:57:09 +0200 |
commit | 8c9fb246794f7cb94689c348f104b29433416f4e (patch) | |
tree | e32ae136f1baacafc0cc266382846ab3ae007e47 /src/front/scope.py | |
parent | 4aedc5d76250fae734af1cd89256ec70e165ab18 (diff) | |
download | swppy-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.py | 20 |
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) |