package OperatorTerminalExpression; use strict; use base qw(AbstractExpression); sub new { my $class = shift; my $self = {}; my $op = shift; $self->{op} = $op; bless $self, $class; } sub interpret { my $self = shift; my $context = shift; my $i = $context->pop(); my $j = $context->pop(); if ($self->{op} == '+') { $context->push($i+$j); } else { $context->push($i*$j); } } 1;