Ejemplo n.º 1
0
def rotate_new_fin(tuple_arg, qfin, pref, tiles):
    (symbol, lhs, rhs) = tuple_arg
    (aa, b, c, d) = tiles[symbol]
    a = list(aa)  # !!!! call by value/call by name !!!! @#$%^%^&**(
    a.append(a[0])
    del a[0]
    lhs.append(pref + rhs)  # the output state "rhs" is changed to "pref+rhs" input state
    rhs = qfin  # a new outpust state of the rule
    (a, lhs) = functions.paralel_sort(a, lhs)
    a = [[]] + a
    new_tile = functions.tile_normalize((a, b, c, d))
    if check_tile_forward_connectivity(new_tile):
        symbol = functions.tile_index(new_tile, tiles)
        return((symbol, lhs, rhs))
    else:
        # TILE NOT connected
        return(())
Ejemplo n.º 2
0
def rotate_intermediate(tuple_arg, lhs_num, pref, tiles):
    (symbol, lhs, rhs) = tuple_arg
    new_lhs = list(lhs)
    del new_lhs[lhs_num]
    new_lhs.append(pref + rhs)
    tile_new_pt1 = list(tiles[symbol][0])
    tmp = tile_new_pt1.pop(lhs_num + 1)
    tile_new_pt1.append(tile_new_pt1[0])
    del tile_new_pt1[0]
    (tile_new_pt1, new_lhs) = functions.paralel_sort(tile_new_pt1, new_lhs)
    tile_new_pt1 = [tmp] + tile_new_pt1
    new_tile = (tile_new_pt1, tiles[symbol][1], tiles[symbol][2], tiles[symbol][3])
    new_tile = functions.tile_normalize(new_tile)
    if check_tile_forward_connectivity(new_tile):
        symbol = functions.tile_index(new_tile, tiles)
        return((symbol, new_lhs, pref + lhs[lhs_num]))
    else:
        # TILE NOT connected
        return(())
Ejemplo n.º 3
0
def sl2ta(preds, sig, global_params, tiles, root_rule):
    # create the finite tree automaton and a set of tiles based on
    # the preprocessed system of predicates and its signatures
    #'fin': 'f',
    aut = {'rules': [], 'fin': root_rule}
    eq_edges = 0
    for p in preds.keys():
        (sig_fw, sig_bw, sig_eq) = sig[p]
        (params, rules) = preds[p]
        # check that root rule has no parameters
        if p == root_rule and not (params == [''] or params == []):
            raise InputError("Root predicate has parameters")
        for (al, pt, calls, equal) in rules:
            x_sets = []
            lhs = []
            null = []
            self = []
            par = []
            if al in global_params:
                par.append("al:%s" % al)
            for x in equal:
                if x in global_params:
                    par.append("al:%s" % x)
            # sort the parameters (it will be done in equal way for all the rules)
            par = sorted(par)
            for x in range(0, len(pt)):
                if (pt[x] in global_params) and not (pt[x] in [al] + equal):
                    par.append("%i:%s" % (x, pt[x]))
                if pt[x] == al:
                    self.append(x)
                if pt[x] == "nil":
                    null.append(x)
                tmp = 1
            x_m1 = []
            for x in sig_bw:
                x_m1.append(pt.index(params[x]))
            x_m1 = sorted(x_m1)
            for x in sig_eq:
                if params[x] in equal + [al]:
                    x_m1.append("al")
                elif params[x] in pt:
                    x_m1.append("s%i" % pt.index(params[x]))
                else:
                    x_m1.append("X" + params[x])
                eq_edges = 1
            # create the sets x_i^{fw} for i>=0 and place them into x_sets array
            for (call_name, call_pars) in calls:
                xi = []
                (c_fw, c_bw, c_eq) = sig[call_name]
                for s in c_fw:
                    xi.append(pt.index(call_pars[s]))
                xi = sorted(xi)  # sort variable indicies
                for s in c_eq:
                    if call_pars[s] in equal + [al]:
                        xi.append("al")
                    elif call_pars[s] in pt:
                        xi.append("s%i" % pt.index(call_pars[s]))
                    else:
                        xi.append("X" + call_pars[s])
                    eq_edges = 1
                x_sets.append(xi)
                lhs.append(call_name)
            # x_m1 contains input ports
            # x_sets now contains output ports
            # sort output ports according to selectors in paralel with lhs (the automata states)
            (x_sets, lhs) = functions.paralel_sort(x_sets, lhs)
            x_sets = [x_m1] + x_sets
            tile = (x_sets, null, self, par)
            tile = functions.tile_normalize(tile)
            # get an index to tiles list and use it as alphabet symbol
            symbol = functions.tile_index(tile, tiles)
            aut['rules'].append((symbol, lhs, p))
    return aut, eq_edges