| 1 | #!/usr/local/bin/perl -w | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use Language::Basic; | ||
| 5 | use Term::ReadLine; | ||
| 6 | |||
| 7 | my $program = Language::Basic::Program->new(); | ||
| 8 | |||
| 9 | my $prompt = '> '; | ||
| 10 | |||
| 11 | my $term = Term::ReadLine->new('BASIC interpreter'); | ||
| 12 | |||
| 13 | my $OUT = $term->OUT || *STDOUT; | ||
| 14 | |||
| 15 | select $OUT; # Really, there should be a way to do this without assuming | ||
| 16 | # that Basic only prints to the selected handle | ||
| 17 | |||
| 18 | print $OUT "Language::Basic interpreter with ", $term->ReadLine(), " support\n"; | ||
| 19 | |||
| 20 | while ( defined (my $line = $term->readline($prompt)) ) { | ||
| 21 | $term->addhistory($line) if $line =~ /\S/; | ||
| 22 | |||
| 23 | if ($line =~ /^\s*\d+\s+/) { | ||
| 24 | $program->line($line); | ||
| 25 | } elsif ($line =~ /^\s*RUN\s*$/i) { | ||
| 26 | $program->implement; | ||
| 27 | } elsif ($line =~ /^\s*QUIT\s*$/i) { | ||
| 28 | print $OUT "Bye!\n"; | ||
| 29 | exit; | ||
| 30 | } else { | ||
| 31 | print $OUT "Invalid command; try RUN, QUIT, or defining a statement with a number.\n"; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 |