+ @classmethod
+ def _fromast(cls, node):
+ from .polyhedra import Polyhedron
+ if isinstance(node, ast.Module) and len(node.body) == 1:
+ return cls._fromast(node.body[0])
+ elif isinstance(node, ast.Expr):
+ return cls._fromast(node.value)
+ elif isinstance(node, ast.UnaryOp):
+ domain = cls._fromast(node.operand)
+ if isinstance(node.operand, ast.invert):
+ return Not(domain)
+ elif isinstance(node, ast.BinOp):
+ domain1 = cls._fromast(node.left)
+ domain2 = cls._fromast(node.right)
+ if isinstance(node.op, ast.BitAnd):
+ return And(domain1, domain2)
+ elif isinstance(node.op, ast.BitOr):
+ return Or(domain1, domain2)
+ elif isinstance(node, ast.Compare):
+ equalities = []
+ inequalities = []
+ left = Expression._fromast(node.left)
+ for i in range(len(node.ops)):
+ op = node.ops[i]
+ right = Expression._fromast(node.comparators[i])
+ if isinstance(op, ast.Lt):
+ inequalities.append(right - left - 1)
+ elif isinstance(op, ast.LtE):
+ inequalities.append(right - left)
+ elif isinstance(op, ast.Eq):
+ equalities.append(left - right)
+ elif isinstance(op, ast.GtE):
+ inequalities.append(left - right)
+ elif isinstance(op, ast.Gt):
+ inequalities.append(left - right - 1)
+ else:
+ break
+ left = right
+ else:
+ return Polyhedron(equalities, inequalities)
+ raise SyntaxError('invalid syntax')
+