From d3b74248d53f19bc8f10510d3d44b68aa4883ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20B=C3=B6hm?= Date: Tue, 9 Jun 2009 08:44:42 +0200 Subject: simplify scope, symbol and types --- src/front/scope.py | 24 +++++------------------- src/front/symbol.py | 32 +++----------------------------- src/front/type.py | 12 ++++++++++++ 3 files changed, 20 insertions(+), 48 deletions(-) create mode 100644 src/front/type.py (limited to 'src') diff --git a/src/front/scope.py b/src/front/scope.py index 2cc3018..0df8729 100644 --- a/src/front/scope.py +++ b/src/front/scope.py @@ -1,20 +1,6 @@ -class Scope(object, DictMixin): - def __init__(self, parent): - self.parent = parent - self.__symbols = {} +class Scope(object): + __shared_state = {} + functions = {} - 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 + def __init__(self): + self.__dict__ = self.__shared_state diff --git a/src/front/symbol.py b/src/front/symbol.py index 879403f..b93b778 100644 --- a/src/front/symbol.py +++ b/src/front/symbol.py @@ -1,34 +1,8 @@ -class SymbolClass(object): - def __init__(self, name): - self.name = name - - def __str__(self): - return self.name - - def __repr__(self): - return "" % self - -SymbolClass.CONST = SymbolClass("CONST") -SymbolClass.VAR = SymbolClass("VAR") -SymbolClass.FUNC = SymbolClass("FUNC") - -class SymbolType(object): - def __init__(self, name): - self.name = name - - def __str__(self): - return self.name - - def __repr__(self): - return "" % self - -SymbolType.INT = SymbolType("INT") -SymbolType.BOOL = SymbolType("BOOL") +from type import DataType class Symbol(object): - __slots__ = ['cls', 'type', 'value'] + __slots__ = ['type', 'value'] - def __init__(self, value, type = SymbolType.INT, cls = SymbolClass.VAR): + def __init__(self, value, type = DataType.INT): self.value = value self.type = type - self.cls = cls diff --git a/src/front/type.py b/src/front/type.py new file mode 100644 index 0000000..a8bd8c7 --- /dev/null +++ b/src/front/type.py @@ -0,0 +1,12 @@ +class DataType(object): + def __init__(self, name): + self.name = name + + def __str__(self): + return self.name + + def __repr__(self): + return "" % self + +DataType.INT = DataType("INT") +DataType.BOOL = DataType("BOOL") -- cgit v1.2.3