Current progress on compiler. Created classes for management of variables.
[trinary.git] / extended / Record.py
blob71b36f1037226cf9816784a1b1fbe4692d5a6085
2 import sys
4 class Records(object):
5 def __init__(self):
6 self.global_table = {}
7 self.local_table = {}
8 self.counter = 0
10 def increment(self):
11 self.counter = self.counter + 1
13 def reset_counter(self):
14 self.counter = 0
16 def add_to_global(self, key, value):
17 if key in self.global_table:
18 return False
19 self.global_table[key] = value
20 return True
22 def add_to_local(self, key, value):
23 if key in self.local_table:
24 return False
25 self.local_table[key] = value
26 return True
28 # clear local table
29 def reset_local(self):
30 self.local_table.clear()
32 # return the value of 'key' (if present) from the tables
33 def return_value(self, key, structure = False):
35 # find in global table
36 if key in self.global_table:
37 return self.global_table[key]
39 # find in local table
40 elif key in self.local_table:
41 return self.local_table[key]
43 # find in structure
44 elif structure != False and key in structure.in_members(key):
45 return structure.get_member(key)
47 else:
48 print "id '" + key + "' not defined"
49 raise SystemExit