def p_conditional(self, t): """conditional : if_else_parts | if_else_parts else_block""" parts = t[1] if len(t) > 2: parts.append(t[2]) t[0] = conditional.ConditionalList(parts)
def parse_ternary_op(assignment): assert isinstance(assignment.value, expression.TernaryOp) actions = parse_actionD(ParameterAssignment(assignment.param, assignment.value.expr2)) cond_block = conditional.Conditional( assignment.value.guard, [ParameterAssignment(assignment.param, assignment.value.expr1)], None ) actions.extend(conditional.ConditionalList([cond_block]).get_action_list()) return actions
def parse_boolean(assignment): assert isinstance(assignment.value, expression.Boolean) actions = parse_actionD(ParameterAssignment(assignment.param, expression.ConstantNumeric(0))) expr = nmlop.CMP_NEQ(assignment.value.expr, 0) cond_block = conditional.Conditional( expr, [ParameterAssignment(assignment.param, expression.ConstantNumeric(1))], None ) actions.extend(conditional.ConditionalList([cond_block]).get_action_list()) return actions
def parse_hasbit(assignment): assert isinstance(assignment.value, expression.BinOp) and ( assignment.value.op == nmlop.HASBIT or assignment.value.op == nmlop.NOTHASBIT ) actions = parse_actionD(ParameterAssignment(assignment.param, expression.ConstantNumeric(0))) cond_block = conditional.Conditional( assignment.value, [ParameterAssignment(assignment.param, expression.ConstantNumeric(1))], None ) actions.extend(conditional.ConditionalList([cond_block]).get_action_list()) return actions
def parse_abs_op(assignment): assert isinstance(assignment.value, expression.AbsOp) actions = parse_actionD(ParameterAssignment(assignment.param, assignment.value.expr)) cond_block = conditional.Conditional( nmlop.CMP_LT(assignment.value.expr, 0), [ParameterAssignment(assignment.param, nmlop.SUB(0, assignment.value.expr))], None, ) actions.extend(conditional.ConditionalList([cond_block]).get_action_list()) return actions