Why on earth would you want the overhead and complication of Parse::RecDescent for a simple macro language?? Gods, NO!

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.