package symbols; sub add_symbol { my $self = shift; my $symbol = shift; if(!defined($self->{'table'}{$symbol})) { $self->{'table'}{$symbol} = $self->{'count'}++; } } sub init_symbol_table { my $self = shift; my @keywords = ( 'break','false','for','foreach','function','if', 'new','newline','number','pop','print','push','read', 'repeat','return','shift','true','until','while' ); my @operators = ( '+=','&&','@','=',',','.','--','/','/=','==','"','^','&', '>=','>','++','{','[','(','<=','<','-','%','*','*=','!', '!=','||','\'','+','}',']',')','$',';','-=' ); $self->load_reserved(@keywords); $self->load_reserved(@operators); } sub load_reserved { my $self = shift; my @symbols = @_; foreach my $symbol (@symbols) { $self->add_symbol($symbol); } } sub new { my $this = shift; my $class = ref($this) || $this; my $self = { 'table' => undef, 'count' => 0 }; bless $self, $class; return $self; } 1;