Ejemplo n.º 1
0
 def create_structure(self, hash_table, match, list):
     hash_t = symboltable.SymbolTable()
     hash_t.add_upper_scope(hash_table)
     hash_t.concatenate_scopes(hash_table._upper_scopes)
     hash_table.insert((match[1]), (match[0], hash_t))
     data_type = ''
     to_return = None
     while list:
         match = list.pop(0)
         if match[1] == RETURN:
             return list.pop(0)
         if match[1] == BRACKET:
             break
         if self._is_data_type(match[1]):
             data_type = match[1]
         elif self._is_structure(match[1]):
             to_return = self.create_structure(hash_t, match, list)
             data_type = ''
         elif data_type:
             self._insert(match[0], match[1], data_type, hash_t)
             data_type = ''
         elif not self._is_do_not_care(match[1]):
             if not self._lookup(match[1], hash_t):
                 self._error_switch(symboltable.NOT_DEC, match[1], match[0])
     return to_return
Ejemplo n.º 2
0
 def evaluate_function(self, name, data_type, list):
     function_type = data_type
     hash_table = symboltable.SymbolTable()
     hash_table.add_upper_scope(self._main_scope)
     values = (data_type, hash_table)
     self._main_scope.insert(values, name)
     while list:
         valor = list.pop(0)
         variable = valor[1]
         if variable == RETURN:
             self._check_return_func(hash_table,
                                     list.pop(0)[1], valor[0],
                                     function_type, name)
         if variable is not BRACKET:
             if self._is_data_type(variable):
                 data_type = variable
             elif data_type and not self._is_data_type(
                     variable) and not self._is_do_not_care(
                         variable) and not self._is_structure(variable):
                 # A usar:
                 self._insert(valor[0], variable, data_type, hash_table)
                 data_type = ''
                 # Álvaro : hash_table.insert(datatype, variable)
             elif self._is_structure(variable):
                 return_ = self.create_structure(hash_table, valor, list)
                 if return_ is not None:
                     self._check_return_func(hash_table, return_[1],
                                             return_[0], function_type,
                                             name)
             elif not self._is_do_not_care(variable):
                 if not self._lookup(variable, hash_table):
                     self._error_switch(symboltable.NOT_DEC, variable,
                                        valor[0])
         else:
             break
Ejemplo n.º 3
0
 def __init__(self, tokens):
     """'tokens' should be a generator expression."""
     self.tokens = tokens
     next = self.tokens.next()
     self.next_token = next[1]
     self.next_type = next[0]
     self.symbols = symboltable.SymbolTable()
     self.code = []
Ejemplo n.º 4
0
 def __init__(self, tokenizer, out_file_path):
     self.tokenizer = tokenizer
     self.tokenizer.advance()
     #self.out_file = out_file
     self.symboltable = symboltable.SymbolTable()
     self.vmwriter = VmWriter(out_file_path)
     self.class_name = ''
     self.fn_info = {}
     self.label_count = 0
Ejemplo n.º 5
0
    Type, \
    Block, \
    AssignStmt, \
    IfStmt, \
    WhileStmt, \
    ReturnStmt, \
    LValue, \
    IntLiteral, \
    FloatLiteral, \
    Operator, \
    ArithExpr, \
    FuncCall, \
    CondExpr

from common import Variable, InputError
s = symboltable.SymbolTable()
lib = None


def setLibAST(libAST):
    global lib
    lib = libAST


def initLib(node):
    if isinstance(node, Function):
        var = Variable(node.name.name, node.type, node)
        try:
            s.insertVariable(var)
        except InputError as err:
            print(format(err) + ": " + node.name.name)
Ejemplo n.º 6
0
import time
beginning = time.time()
count = 0


""" FIRST PASS: Traverse parse, fill SYMBOL_TABLE with labels """
FILENAME = os.path.dirname(os.path.realpath(__file__))+"/"+str(sys.argv[1])

try:
    file = parser.Parser(FILENAME)

except:
    print "File \"" + sys.argv[1] + "\" does not exist."
    sys.exit()

SYMBOL_TABLE = symboltable.SymbolTable()

rom_counter = 0
RAM_ADDRESS = 15

""" if A or C command advance, if L add to table """
while file.has_more_commands():
    
    file.advance()
    command_type = file.command_type()
    
    if command_type is "L_COMMAND":
        SYMBOL_TABLE.add_entry(file.symbol(), rom_counter)
    
    else:
        rom_counter += 1
Ejemplo n.º 7
0
 def __init__(self, tokenizer, out_file):
     self.tokenizer = tokenizer
     self.tokenizer.advance()
     self.out_file = out_file
     self.symboltable = symboltable.SymbolTable()
Ejemplo n.º 8
0
 def __init__(self):
     self.scope = symboltable.SymbolTable(None, "Main")
     self.return_code = 0
Ejemplo n.º 9
0
 def setUp(self):
     self.symboltable = symboltable.SymbolTable()
Ejemplo n.º 10
0
 def __init__(self, file_path):
     self._error_string = ''
     self._main_scope = symboltable.SymbolTable()
     self._open_file(file_path)