Exemplo n.º 1
0
    def test_mat_nat(self, get_visitor):
        file = "test_cases/math/symbol_table_mat_nat.bs"
        st = self.get_symbols(get_visitor(file))

        input_1 = st.get_local('a', 'main')
        output = st.get_local('b', 'main')

        assert ChemTypeResolver.is_number_in_set(input_1.types) and ChemTypeResolver.is_number_in_set(input_1.types)
        assert ChemTypeResolver.is_only_numeric(output.types)
Exemplo n.º 2
0
    def test_nat(self, get_visitor):
        file = "test_cases/split/symbol_table_nat.bs"
        st = self.get_symbols(get_visitor(file))

        input_1 = st.get_local('a', 'main')
        output = st.get_local('b', 'main')

        assert ChemTypeResolver.is_number_in_set(input_1.types)
        assert ChemTypeResolver.is_number_in_set(output.types) and ChemTypeResolver.is_mat_in_set(output.types)
        assert input_1.scope == 'main'
        assert output.scope == 'main'
Exemplo n.º 3
0
    def test_nat(self, get_visitor):
        file = "test_cases/detect/symbol_table_nat.bs"
        st = self.get_symbols(get_visitor(file))

        input_1 = st.get_local('a', 'main')
        mod = st.get_global('mod')
        output = st.get_local('b', 'main')

        assert ChemTypeResolver.is_mat_in_set(input_1.types) and ChemTypeResolver.is_number_in_set(input_1.types)
        assert ChemTypes.MODULE in mod.types and len(mod.types) == 1
        assert ChemTypeResolver.is_number_in_set(output.types)
Exemplo n.º 4
0
    def visitMath(self, ctx: BSParser.MathContext):
        deff = self.visitVariableDefinition(ctx.variableDefinition())
        symbol = Symbol(deff['name'], self.scope_stack[-1],
                        ChemTypeResolver.numbers())

        for use in ctx.primary():
            var = self.visitPrimary(use)

            # This places any constants into the global symbol table.
            # By doing this, it makes it significantly easier to handle
            # arithmetic later in the compilation process.
            if 'value' in var.keys() and not self.symbol_table.get_global(
                    var['name']):
                globalz = Symbol(var['name'], 'global',
                                 ChemTypeResolver.numbers())
                globalz.value = Number(var['name'], 1, var['value'])
                self.symbol_table.add_global(globalz)

            if not ChemTypeResolver.is_number_in_set(var['types']):
                local = self.symbol_table.get_local(var['name'])
                if not local:
                    raise UndefinedVariable("{} is not defined.".format(
                        var['name']))
                local.types.update(ChemTypeResolver.numbers())
                if ChemTypes.UNKNOWN in local.types:
                    local.types.remove(ChemTypes.UNKNOWN)
                self.symbol_table.update_symbol(local)

        self.symbol_table.add_local(symbol)

        return None
Exemplo n.º 5
0
    def test_nat(self, get_visitor):
        file = "test_cases/store/symbol_table_nat.bs"
        st = self.get_symbols(get_visitor(file))

        output = st.get_local('a', 'main')

        assert ChemTypeResolver.is_number_in_set(output.types) and ChemTypeResolver.is_mat_in_set(output.types)