#!/bin/perl
use strict;
use Stack;
use NonTerminalExpression;
use IntegerTerminalExpression;
use OperatorTerminalExpression;
use Time::HR;

my $t1 = gethrtime();
my $context = Stack->new();
my $i;
my $j;
for ($i=0; $i<1000; $i++) {
  my $nte = NonTerminalExpression->new();
  for ($j=0; $j<500; $j++) {
    $nte->add(IntegerTerminalExpression->new($j));  
  }
  for ($j=0; $j<500-1; $j++) {
    $nte->add(OperatorTerminalExpression->new('+'));  
  }
  $nte->interpret($context);
  my $result = $context->pop();
  # print "result: ".$result."\n";
}
my $t2 = gethrtime();
print (int(($t2-$t1)/1000000))." ";
