What's wrong with something like this:
sub parse_commands { my ($filename) = @_; my $fh = IO::File->new($filename) || die ...; while (<$fh>) { # All commands being with a letter and must be the first chara +cter next if /^[^A-Za-z]/; # A command is space-delimited and must be on one line. # We want to deal with the entire command in uppercase. my ($command, @line) = split /\s+/, uc; unless (exists $DispatchTable{$command}) { warn "'$command' isn't a valid command.\n"; next; } push @commands, [$command, \@line]; } return \@commands; }
All of a sudden, you have a parsed list of commands. Obviously, you'd do something a little more in-depth when dealing with WHILE/ENDWHILE, IF/ELSE/ENDIF, SUB/ENDSUB, and FOR/ENDFOR, but it's not that much more complicated. It can even be a one-pass compiler if you
If interested, I'll write one. Remember - the handler for each command is the one that cares about parameters and the like. This isn't a fully-featured language (though it is Turing-complete).
------
We are the carpenters and bricklayers of the Information Age.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
In reply to Re: Re: Keyword parser function mapping module
by dragonchild
in thread Keyword parser function mapping module
by apprentice
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |