Exemplo n.º 1
0
def make_jtlv_nodes():
    opmap = {
        'False': 'FALSE', 'True': 'TRUE',
        '!': '!',
        '|': '|', '&': '&', '->': '->', '<->': '<->',
        'G': '[]', 'F': '<>', 'X': 'next',
        'U': 'U',
        '<': '<', '<=': '<=', '=': '=', '>=': '>=', '>': '>', '!=': '!='}
    nodes = ast.make_fol_nodes(opmap)

    class Str(nodes.Str):
        def flatten(self, **kw):
            return '({c})'.format(c=self)

    class Var(nodes.Var):
        def flatten(self, env_vars=None, sys_vars=None, **kw):
            v = self.value
            if v in env_vars:
                player = 'e'
            elif v in sys_vars:
                player = 's'
            else:
                raise ValueError('{v} neither env nor sys var'.format(v))
            return '({player}.{value})'.format(player=player, value=v)

    nodes.Str = Str
    nodes.Var = Var
    return nodes
Exemplo n.º 2
0
def make_python_nodes():
    opmap = {
        "True": "True",
        "False": "False",
        "!": "not",
        "&": "and",
        "|": "or",
        "^": "^",
        "=": "==",
        "!=": "!=",
        "<": "<",
        "<": "<",
        ">=": ">=",
        ">": ">",
        "+": "+",
        "-": "-",
    }
    nodes = ast.make_fol_nodes(opmap)

    class Imp(nodes.Binary):
        def flatten(self, *arg, **kw):
            return "((not ({l})) or {r})".format(l=self.operands[0].flatten(), r=self.operands[1].flatten())

    class BiImp(nodes.Binary):
        def flatten(self, *arg, **kw):
            return "({l} == {r})".format(l=self.operands[0].flatten(), r=self.operands[1].flatten())

    nodes.Imp = Imp
    nodes.BiImp = BiImp
    return nodes
Exemplo n.º 3
0
def make_gr1c_nodes(opmap=None):
    if opmap is None:
        opmap = {
            'False': 'False', 'True': 'True',
            '!': '!',
            '|': '|', '&': '&', '->': '->', '<->': '<->',
            'G': '[]', 'F': '<>', 'X': '',
            '<': '<', '<=': '<=', '=': '=',
            '>=': '>=', '>': '>', '!=': '!='}
    nodes = ast.make_fol_nodes(opmap)

    class Var(nodes.Var):
        def flatten(self, prime=None, **kw):
            return '{v}{prime}'.format(
                v=self.value, prime="'" if prime else '')

    class Unary(nodes.Unary):
        def flatten(self, *arg, **kw):
            if self.operator == 'X':
                kw.update(prime=True)
                return self.operands[0].flatten(*arg, **kw)
            return super(Unary, self).flatten(*arg, **kw)

    nodes.Var = Var
    nodes.Unary = Unary
    return nodes
Exemplo n.º 4
0
def make_wring_nodes():
    opmap = {'False': '0', 'True': '1',
             '!': '!',
             '|': '+', '&': '*', '->': '->', '<->': '<->', 'xor': '^',
             'G': 'G', 'F': 'F', 'X': 'X',
             'U': 'U', 'R': 'R', 'V': 'V'}
    nodes = ast.make_fol_nodes(opmap)

    class Var(nodes.Var):
        def flatten(self, *arg, **kw):
            if ('env_vars' in kw) or ('sys_vars' in kw):
                env_vars = kw['env_vars']
                sys_vars = kw['sys_vars']
                if self.value in env_vars:
                    this_type = env_vars[self.value]
                elif self.value in sys_vars:
                    this_type = sys_vars[self.value]
                else:
                    raise TypeError(
                        '"{v}" is not defined as a variable in {t1} nor {t2}'.format(
                            v=self.value, t1=env_vars, t2=sys_vars))

                if this_type != 'boolean':
                    raise TypeError('"{v}" is not Boolean, but {type}'.format(
                        v=self.val, type=this_type))
            return '({var}=1)'.format(var=self.value)

    nodes.Var = Var
    return nodes
Exemplo n.º 5
0
def test_fol_nodes():
    nodes = ast.make_fol_nodes()
    # test Var
    v = nodes.Var('a')
    assert v.value == 'a'
    nt.assert_raises(TypeError, nodes.Var, 2)
    # test Bool
    b = nodes.Bool('TRue')
    print(b.value)
    assert b.value == 'True'
    assert b.flatten() == 'True'
    nt.assert_raises(TypeError, nodes.Bool, 2)
    nt.assert_raises(TypeError, nodes.Bool, 'bee')
Exemplo n.º 6
0
def make_wring_nodes():
    opmap = {
        "False": "0",
        "True": "1",
        "!": "!",
        "|": "+",
        "&": "*",
        "->": "->",
        "<->": "<->",
        "xor": "^",
        "G": "G",
        "F": "F",
        "X": "X",
        "U": "U",
        "R": "R",
        "V": "V",
    }
    nodes = ast.make_fol_nodes(opmap)

    class Var(nodes.Var):
        def flatten(self, *arg, **kw):
            if kw.has_key("env_vars") or kw.has_key("sys_vars"):
                env_vars = kw["env_vars"]
                sys_vars = kw["sys_vars"]
                if env_vars.has_key(self.value):
                    this_type = env_vars[self.value]
                elif sys_vars.has_key(self.value):
                    this_type = sys_vars[self.value]
                else:
                    raise TypeError(
                        '"{v}" is not defined as a variable in {t1} nor {t2}'.format(
                            v=self.value, t1=env_vars, t2=sys_vars
                        )
                    )

                if this_type != "boolean":
                    raise TypeError('"{v}" is not Boolean, but {type}'.format(v=self.val, type=this_type))
            return "({var}=1)".format(var=self.value)

    nodes.Var = Var
    return nodes
Exemplo n.º 7
0
def make_jtlv_nodes():
    opmap = {
        "False": "FALSE",
        "True": "TRUE",
        "!": "!",
        "|": "|",
        "&": "&",
        "->": "->",
        "<->": "<->",
        "G": "[]",
        "F": "<>",
        "X": "next",
        "U": "U",
        "<": "<",
        "<=": "<=",
        "=": "=",
        ">=": ">=",
        ">": ">",
        "!=": "!=",
    }
    nodes = ast.make_fol_nodes(opmap)

    class Str(nodes.Str):
        def flatten(self, **kw):
            return "({c})".format(c=self)

    class Var(nodes.Var):
        def flatten(self, env_vars=None, sys_vars=None, **kw):
            v = self.value
            if v in env_vars:
                player = "e"
            elif v in sys_vars:
                player = "s"
            else:
                raise ValueError("{v} neither env nor sys var".format(v))
            return "({player}.{value})".format(player=player, value=v)

    nodes.Str = Str
    nodes.Var = Var
    return nodes
Exemplo n.º 8
0
def make_python_nodes():
    opmap = {'True': 'True', 'False': 'False',
             '!': 'not', '&': 'and', '|': 'or',
             '^': '^', '=': '==', '!=': '!=',
             '<': '<', '<': '<', '>=': '>=', '>': '>',
             '+': '+', '-': '-'}
    nodes = ast.make_fol_nodes(opmap)

    class Imp(nodes.Binary):
        def flatten(self, *arg, **kw):
            return '((not ({l})) or {r})'.format(
                l=self.operands[0].flatten(),
                r=self.operands[1].flatten())

    class BiImp(nodes.Binary):
        def flatten(self, *arg, **kw):
            return '({l} == {r})'.format(
                l=self.operands[0].flatten(),
                r=self.operands[1].flatten())

    nodes.Imp = Imp
    nodes.BiImp = BiImp
    return nodes
Exemplo n.º 9
0
def make_gr1c_nodes(opmap=None):
    if opmap is None:
        opmap = {
            "False": "False",
            "True": "True",
            "!": "!",
            "|": "|",
            "&": "&",
            "->": "->",
            "<->": "<->",
            "G": "[]",
            "F": "<>",
            "X": "",
            "<": "<",
            "<=": "<=",
            "=": "=",
            ">=": ">=",
            ">": ">",
            "!=": "!=",
        }
    nodes = ast.make_fol_nodes(opmap)

    class Var(nodes.Var):
        def flatten(self, prime=None, **kw):
            return "{v}{prime}".format(v=self.value, prime="'" if prime else "")

    class Unary(nodes.Unary):
        def flatten(self, *arg, **kw):
            if self.operator == "X":
                kw.update(prime=True)
                return self.operands[0].flatten(*arg, **kw)
            return super(Unary, self).flatten(*arg, **kw)

    nodes.Var = Var
    nodes.Unary = Unary
    return nodes
Exemplo n.º 10
0
def make_smv_nodes():
    opmap = {"X": "X", "G": "G", "F": "F", "U": "U", "R": "V"}
    return ast.make_fol_nodes(opmap)
Exemplo n.º 11
0
def make_promela_nodes():
    opmap = dict(ast.OPMAP)
    opmap.update({"True": "true", "False": "false", "G": "[]", "F": "<>", "R": "V", "=": "=="})
    return ast.make_fol_nodes(opmap)
Exemplo n.º 12
0
def make_smv_nodes():
    opmap = {'X': 'X', 'G': 'G', 'F': 'F', 'U': 'U', 'R': 'V'}
    return ast.make_fol_nodes(opmap)
Exemplo n.º 13
0
def make_promela_nodes():
    opmap = dict(ast.OPMAP)
    opmap.update({'True': 'true', 'False': 'false',
                  'G': '[]', 'F': '<>', 'R': 'V', '=': '=='})
    return ast.make_fol_nodes(opmap)