def right_associative_infix_rule(operator, grammar_rule):
    """Semantic action for rules like 'A = B (C B)*'."""
    def semantic_action(self, node, (result, remaining)):
        while remaining:
            op, rhs = remaining.pop(0)
            result = operator(Attr(result, Name(self.aliases[op])), [rhs], op)
        return result
    return g.rule(grammar_rule)(semantic_action)
Semantic action for rules like 'A = B (C B)*'.