def TO_INT(node: ast) -> (bool, int):
if isinstance(node, ast.Num):
return (True, node.n)
if isinstance(node, ast.UnaryOp) and isinstance(node.operand, ast.Num):
if isinstance(node.op, ast.UAdd):
return (True, +node.operand.n)
if isinstance(node.op, ast.USub):
return (True, -node.operand.n)
error(loc(node), "Expected +/- Num")
return (False, 0)
error(loc(node), "Expected signed integer")
return (False, 0)
评论列表
文章目录