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
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
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
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
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
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
def make_promela_nodes(): opmap = dict(ast.OPMAP) opmap.update({ 'True': 'true', 'False': 'false', 'G': '[]', 'F': '<>', 'R': 'V', '=': '==' }) return ast.make_fol_nodes(opmap)
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')
def test_fol_nodes(): nodes = ast.make_fol_nodes() # test Var v = nodes.Var('a') assert v.value == 'a' with pytest.raises(TypeError): nodes.Var(2) # test Bool b = nodes.Bool('TRue') print(b.value) assert b.value == 'True' assert b.flatten() == 'True' with pytest.raises(TypeError): nodes.Bool(2) with pytest.raises(TypeError): nodes.Bool('bee')
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
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
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
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
def make_promela_nodes(): opmap = dict(ast.OPMAP) opmap.update({"True": "true", "False": "false", "G": "[]", "F": "<>", "R": "V", "=": "=="}) return ast.make_fol_nodes(opmap)
def make_smv_nodes(): opmap = {'X': 'X', 'G': 'G', 'F': 'F', 'U': 'U', 'R': 'V'} return ast.make_fol_nodes(opmap)
def make_promela_nodes(): opmap = dict(ast.OPMAP) opmap.update({'True': 'true', 'False': 'false', 'G': '[]', 'F': '<>', 'R': 'V', '=': '=='}) return ast.make_fol_nodes(opmap)
def make_smv_nodes(): opmap = {"X": "X", "G": "G", "F": "F", "U": "U", "R": "V"} return ast.make_fol_nodes(opmap)